Metadata-Version: 2.4
Name: autourgos-openaichat
Version: 1.0.0
Summary: Autourgos LLM wrapper for the OpenAI Chat Completions API
Author-email: Jitin Kumar Sengar <devxjitin@gmail.com>
License: MIT License
        
        Copyright (c) 2026 Jitin Kumar Sengar
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/autourgos/autourgos-openaichat
Project-URL: Repository, https://github.com/autourgos/autourgos-openaichat
Project-URL: Issues, https://github.com/autourgos/autourgos-openaichat/issues
Keywords: autourgos,openai,llm,chat,completions,ai,agent,wrapper,gpt
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: openai>=1.0.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.21; extra == "dev"
Requires-Dist: pydantic>=2.0; extra == "dev"
Requires-Dist: build; extra == "dev"
Requires-Dist: twine; extra == "dev"
Dynamic: license-file

# autourgos-openaichat

LLM wrapper for the **OpenAI Chat Completions API**, part of the [Autourgos](https://github.com/autourgos) framework.

Fully self-contained — no `autourgos-core` dependency required.

## Install

```bash
pip install autourgos-openaichat
```

## Quick start

```python
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)

```python
llm = OpenAIChatModel(model="gpt-4o")
reply = llm.invoke("What is in this image?", files=["photo.jpg"])
```

## Structured output

```python
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

```python
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

```python
llm = OpenAIChatModel(
    model="gpt-4o",
    prompt_template="Translate the following to {language}: {text}",
)
reply = llm.invoke(prompt_variables={"language": "French", "text": "Hello"})
```

## System instruction

```python
llm = OpenAIChatModel(
    model="gpt-4o",
    system_instruction="You are a concise assistant. Reply in one sentence.",
)
```

## Context manager

```python
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
