feat: introduce config serialization framework - #56
Merged
Conversation
…chema support Add the provider/ package with: - ProviderEnvelope: JSON envelope with provider type discriminator - Registry: thread-safe map of provider name to deserialization Handler - DefaultRegistry: global singleton for provider auto-registration - Serialize/Deserialize: marshal config to envelope, unmarshal and dispatch - SchemaProvider interface and ReflectSchema: reflection-based JSON Schema generation - SchemaHandler: provider-agnostic schema lookup in the registry - DefaultRegistry.RegisterSchema/GetSchema/Schema: schema registration and retrieval - Unit tests for registry, I/O, and schema functionality
Add JSON-serializable config types for the OpenAI provider: - Connection: endpoint, API key, model, org, project, retries, timeout - Generation: temperature, top_p, max_tokens, penalties, logprobs, seed, etc. - Cache: prompt_cache_key, prompt_cache_retention, safety_identifier, user - Metadata: key-value pairs for tracking and querying - StreamConfig: include_usage, include_obfuscation with ToSDK converter - Convert utilities: optFloat64, optInt64, optBool, optString for *T to param.Opt[T]
…o-registration Add: - ResponseFormat: union type for text/json_object/json_schema with ToSDK converter - Stop: union type for string/array stop sequences with ToSDK converter - ProviderConfig: complete config combining Connection, Generation, Cache, Format, Stop, Metadata, Stream - ToClient: converts ProviderConfig to ready-to-use *openai_connect.OpenAIClient - toChatCompletionParams: maps all config fields to openai.ChatCompletionNewParams - Auto-registration in DefaultRegistry via init() for openai provider
Test serialize → deserialize → ToClient for: - Minimal config (endpoint, api_key, model only) - Full config with all fields (Gen, Cache, Format json_schema, Stop array, Meta, Stream) - ResponseFormat text variant - ResponseFormat json_object variant - Stop string variant
Add JSONSchema() methods for ResponseFormat, Stop, and JSONSchemaDef using orderedmap for property ordering. Add ProviderConfigSchema() function that uses invopop/jsonschema reflector to generate a full JSON Schema document for ProviderConfig. Register the schema handler in DefaultRegistry via init(). Add integration test verifying the openai schema is registered and returns a valid schema.
x2d7
force-pushed
the
feat/client-serialization
branch
from
August 10, 2026 21:20
8242bae to
71da7ae
Compare
Replace direct OpenAIClient construction with provider.Deserialize() using a JSON config string. Demonstrates the provider-agnostic serialization workflow: import config package for auto-registration, then deserialize from JSON to get a chat.Client.
- Add github.com/wk8/go-ordered-map/v2 as direct dependency (used by schema generation) - Update examples/go.mod: bump openai-go to v3.37.0, add go.uber.org/goleak
x2d7
force-pushed
the
feat/client-serialization
branch
from
August 10, 2026 21:22
71da7ae to
05cfabb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
v0.3.4
The official OpenAI SDK makes config serialization a pain — every optional field requires
param.Opt[T]wrapping, union types rely on a custom encoder incompatible with standardencoding/json, and round-tripping params through JSON is lossy. This release introduces a provider-agnostic serialization framework — the first step toward unifying API formats across providers.Features
provider/package — registry, envelope-based serialization, and JSON Schema generationprovider.Serialize()/Deserialize()— marshal config toProviderEnvelopeJSON, unmarshal and dispatch to registered handlerprovider.ReflectSchema()— automatic JSON Schema generation from Go config structs viainvopop/jsonschemaconnect/openai/config/package — full OpenAI config as JSON-serializable structs:Connection,Generation,Cache,ResponseFormat,Stop,StreamConfig,MetadataProviderConfig.ToClient()— converts a config struct to a ready-to-use*OpenAIClientDefaultRegistryviainit()+import _patternChanges
examples/simple-chat.go— now usesprovider.Deserialize()instead of directOpenAIClientconstruction