Indent AI Pair Programmer
Indent is an AI Pair Programmer offering conversational code generation, modification, and explanation. It provides a Python SDK to interact with its services, leveraging an OpenAI-compatible API structure. Currently in early development, its latest version is 0.1.61, with a rapid release cadence due to ongoing development.
Common errors
-
ValueError: INDENT_API_KEY environment variable not set.
cause The IndentClient was initialized without an API key, and the quickstart code explicitly checks for this and raises an error.fixSet the `INDENT_API_KEY` environment variable (e.g., `export INDENT_API_KEY='your_key'`) or pass your API key directly: `client = IndentClient(api_key='your_key')`. -
AttributeError: 'IndentClient' object has no attribute 'completions'
cause Attempting to call `.completions` directly on the `IndentClient` object instead of using the chat sub-object, a common pattern from older OpenAI SDKs.fixUse `client.chat.completions.create(...)` as per the OpenAI SDK v1 and Indent's compatible API structure.
Warnings
- breaking The Indent Python SDK is explicitly stated to be 'still in early development.' This implies that breaking changes, API alterations, and functional instability should be expected across minor versions.
- gotcha Indent's API client (IndentClient) uses an interface highly similar to the OpenAI Python SDK v1. Users familiar with older OpenAI SDK versions (pre-1.0) or other LLM libraries might encounter unexpected method signatures or behaviors.
- gotcha Authentication requires an `INDENT_API_KEY` which must be provided to the `IndentClient`. If this key is missing or invalid, API calls will fail, often with unhandled exceptions if not properly caught.
Install
-
pip install indent
Imports
- IndentClient
import indent
from indent import IndentClient
Quickstart
import os
from indent import IndentClient
# Ensure your INDENT_API_KEY is set as an environment variable
# Example: export INDENT_API_KEY='your_api_key_here'
api_key = os.environ.get("INDENT_API_KEY", "")
if not api_key:
raise ValueError("INDENT_API_KEY environment variable not set.")
client = IndentClient(api_key=api_key)
# Example: Generate code using the chat completions API
try:
response = client.chat.completions.create(
messages=[
{"role": "user", "content": "Write a Python function to reverse a string."}
]
)
print("Generated code:\n", response.choices[0].message.content)
except Exception as e:
print(f"An error occurred: {e}")