Skip to content

feat: introduce config serialization framework - #56

Merged
x2d7 merged 7 commits into
mainfrom
feat/client-serialization
Aug 10, 2026
Merged

feat: introduce config serialization framework#56
x2d7 merged 7 commits into
mainfrom
feat/client-serialization

Conversation

@x2d7

@x2d7 x2d7 commented Aug 10, 2026

Copy link
Copy Markdown
Owner

v0.3.4

"why they did it so uncomfy?"

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 standard encoding/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

  • New provider/ package — registry, envelope-based serialization, and JSON Schema generation
  • provider.Serialize() / Deserialize() — marshal config to ProviderEnvelope JSON, unmarshal and dispatch to registered handler
  • provider.ReflectSchema() — automatic JSON Schema generation from Go config structs via invopop/jsonschema
  • New connect/openai/config/ package — full OpenAI config as JSON-serializable structs: Connection, Generation, Cache, ResponseFormat, Stop, StreamConfig, Metadata
  • ProviderConfig.ToClient() — converts a config struct to a ready-to-use *OpenAIClient
  • OpenAI provider auto-registered in DefaultRegistry via init() + import _ pattern

Changes

  • examples/simple-chat.go — now uses provider.Deserialize() instead of direct OpenAIClient construction

x2d7 added 5 commits August 10, 2026 20:48
…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
x2d7 force-pushed the feat/client-serialization branch from 8242bae to 71da7ae Compare August 10, 2026 21:20
x2d7 added 2 commits August 11, 2026 01:22
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
x2d7 force-pushed the feat/client-serialization branch from 71da7ae to 05cfabb Compare August 10, 2026 21:22
@x2d7
x2d7 merged commit 4d00cb0 into main Aug 10, 2026
1 check passed
@x2d7
x2d7 deleted the feat/client-serialization branch August 10, 2026 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant