$ show ogx-ai/ogx-client-python
This repository is a Python client SDK for the OGX AI inference API, which is OpenAI-compatible. It provides both synchronous (`OgxClient`) and asynchronous (`AsyncOgxClient`) clients with typed resources for chat completions, embeddings, vector stores, models, prompts, responses, batches, files, and more. The SDK is auto-generated by Stainless from an OpenAPI spec, ensuring the API surface stays aligned with the backend. It includes a CLI tool (`ogx-client`) for interacting with the OGX server, and a higher-level agent library (`lib/agents/`) for building conversational agents with tool use, turn/step event models, and ReAct-style reasoning. The architecture follows a resource pattern: each API endpoint group (e.g., `chat/completions`, `vector_stores`) is a class inheriting from `SyncAPIResource`/`AsyncAPIResource`, registered as properties on the client. The base client handles HTTP transport via `httpx`, retries with exponential backoff, streaming via SSE, cursor-based pagination, and error classification. The agent library wraps the Responses API, manages conversation state, and synthesizes structured events from raw stream data. The CLI uses `click` for command groups covering models, vector stores, eval, datasets, providers, and inference. Key data flows: users instantiate a client, call resource methods (e.g., `client.chat.completions.create()`), which serialize parameters via Pydantic models, send HTTP requests, and parse responses. Streaming responses are handled by `Stream`/`AsyncStream` classes that decode SSE events. The agent library consumes stream events and emits turn/step lifecycle events for UI or logging. External dependencies are minimal: `httpx`, `pydantic`, `typing-extensions`, and optional `aiohttp` for async transport. The codebase is well-structured but heavily generated; the custom agent code is the most reusable and demonstrates non-obvious skill in event synthesis and tool orchestration.
The LLM identified 4 files worth highlighting for reuse:
Provides a `client_tool` decorator that converts any Python function into a `ClientTool` with auto-generated JSON schema from type hints and RST-style docstrings. This is a self-contained, reusable pattern for defining LLM-callable tools without manual schema authoring. It can be extracted and used in any agent framework that needs tool definitions.
Implements a custom SSE (Server-Sent Events) decoder (`SSEDecoder`) and `Stream`/`AsyncStream` classes for handling streaming HTTP responses. The decoder handles multi-byte characters, chunked data, and multiple event types. This is a standalone, well-tested component that can be reused in any Python project requiring SSE parsing.
Contains utility functions `to_httpx_files`, `deepcopy_with_paths`, and `extract_files` for safely extracting file-type fields from nested dictionaries and preparing multipart uploads. The `deepcopy_with_paths` function ensures idempotent handling of file paths without mutating the original data. This is a reusable pattern for any SDK that needs to handle file uploads with complex nested parameters.
Provides compatibility shims between Pydantic v1 and v2, including `model_dump`, `model_dump_json`, `model_copy`, and `construct` functions. This allows the SDK to work with both major Pydantic versions. The pattern of abstracting version-specific APIs behind a compatibility layer is reusable for any Python library that depends on Pydantic and wants to support multiple versions.