Autourgos LLM wrapper for the OpenAI Chat Completions API
Project description
autourgos-openaichat
LLM wrapper for the OpenAI Chat Completions API, part of the Autourgos framework.
Fully self-contained — no autourgos-core dependency required.
Install
pip install autourgos-openaichat
Quick start
from autourgos_openaichat import OpenAIChatModel
llm = OpenAIChatModel(model="gpt-4o", api_key="sk-...")
# Sync
reply = llm.invoke("What is the capital of France?")
print(reply) # "Paris"
# Async
reply = await llm.ainvoke("Translate 'hello' to Spanish.")
# Streaming
for chunk in llm.stream("Tell me a joke."):
print(chunk, end="", flush=True)
# Async streaming
async for chunk in llm.astream("Explain AI."):
print(chunk, end="", flush=True)
# Batch
replies = llm.batch_invoke(["Q1", "Q2", "Q3"])
# Async batch (concurrent)
replies = await llm.abatch_invoke(["Q1", "Q2", "Q3"])
Multi-modal (vision)
llm = OpenAIChatModel(model="gpt-4o")
reply = llm.invoke("What is in this image?", files=["photo.jpg"])
Structured output
from pydantic import BaseModel
class Answer(BaseModel):
capital: str
country: str
llm = OpenAIChatModel(model="gpt-4o", response_schema=Answer)
result = llm.invoke("Capital of France?")
# result["response"] contains the JSON string
Native tool-calling
tools = [
{
"name": "get_weather",
"description": "Get current weather for a city",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"],
},
}
]
response = llm.invoke_with_tools("What's the weather in Paris?", tools)
if response.has_tool_calls:
for call in response.tool_calls:
print(call.name, call.arguments)
Prompt templates
llm = OpenAIChatModel(
model="gpt-4o",
prompt_template="Translate the following to {language}: {text}",
)
reply = llm.invoke(prompt_variables={"language": "French", "text": "Hello"})
System instruction
llm = OpenAIChatModel(
model="gpt-4o",
system_instruction="You are a concise assistant. Reply in one sentence.",
)
Context manager
with OpenAIChatModel(model="gpt-4o") as llm:
reply = llm.invoke("Hello")
Constructor options
| Parameter | Type | Default | Description |
|---|---|---|---|
model |
str | required | Model name, e.g. "gpt-4o" |
api_key |
str | env OPENAI_API_KEY |
OpenAI API key |
base_url |
str | env OPENAI_BASE_URL |
Custom API base URL |
organization |
str | None | OpenAI org ID |
project |
str | None | OpenAI project ID |
system_instruction |
str | None | System prompt |
prompt_template |
str | None | Template with {placeholders} |
temperature |
float | None | Sampling temperature (0–2) |
top_p |
float | None | Nucleus sampling (0–1) |
max_tokens |
int | None | Max output tokens |
response_schema |
Pydantic model / dict | None | Structured JSON output |
response_mime_type |
str | None | "application/json" for JSON mode |
structured_output |
bool | False | Return metadata dict instead of string |
streaming |
bool | False | Stream internally and join |
max_retries |
int | 3 | Retry attempts on API errors |
timeout |
float | 60.0 | Request timeout in seconds |
backoff_factor |
float | 0.5 | Exponential back-off base |
input_pricing |
float | None | USD per 1M input tokens |
output_pricing |
float | None | USD per 1M output tokens |
circuit_failure_threshold |
int | 5 | Failures before circuit opens |
circuit_cooldown_time |
float | 30.0 | Seconds circuit stays open |
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file autourgos_openaichat-1.0.0.tar.gz.
File metadata
- Download URL: autourgos_openaichat-1.0.0.tar.gz
- Upload date:
- Size: 32.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e3d64fa82f1f1deb912391e84d5d3d3311e937a465ee3ddcb9bdf44d4938d9d
|
|
| MD5 |
321134154e20b0c442faee088cb739e7
|
|
| BLAKE2b-256 |
8bc386b36e4b84a284d384118ae0a5ca5180bca9c6f891337d35c3a317a3057a
|
File details
Details for the file autourgos_openaichat-1.0.0-py3-none-any.whl.
File metadata
- Download URL: autourgos_openaichat-1.0.0-py3-none-any.whl
- Upload date:
- Size: 18.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d495c744d4c9c3806fd246639d8f9b5d5b51102255cc266d4b4b2c39390397f0
|
|
| MD5 |
7fab79fc662e753ff0ebe4008585bc04
|
|
| BLAKE2b-256 |
decd9cb00a92adc2efe3fb65dcf6db6c535a354ca9a2429a71a2fc025de873ad
|