feat: Add JSON schema support for structured output, drop jsony - #19
Merged
Conversation
* Implement `--schema` flag for enforcing JSON output structure. * Update README with examples for using JSON schema. * Modify provider interfaces to accept schema, enabling structured responses. * Add `schema` parameter to `chat` methods across providers. * Integrate schema parsing and validation within provider logic. * Update tests to verify schema enforcement.
* Remove `jsony` from `seance.nimble` and `nimble.lock`. * Replace `jsony` serialization/deserialization with Nim's built-in `json` and `std/options` for all providers. * Update `openai.nim` to use `$(%*request)` for serialization and `to(parseJson(responseBodyContent), ChatResponse)` for deserialization. * Update `openrouter.nim` to use `$(%*request)` for serialization and `to(parseJson(responseBodyContent), ChatResponse)` for deserialization. * Update `anthropic.nim` to use `$(%*request)` for serialization and a custom `fromAnthropic` proc for deserialization. * Update `gemini.nim` to use `$(%*request)` for serialization and a custom `fromGemini` proc for deserialization.
* Implemented `fromOpenAI` procedure to parse OpenAI API responses. * Added `fromOpenRouter` procedure for parsing OpenRouter API responses. * Modified `OpenAIRouter` and `OpenRouter` providers to use their respective parsing procedures. * Updated tests for `OpenAI` and `OpenRouter` providers to include the "role" field in mock responses. * Removed unnecessary fields from OpenRouter requests.
* Refactor ProviderConfig to use Option[string] for model. * Update default models for Anthropic and OpenRouter. * Adjust tests for OpenAI, Gemini, and OpenRouter providers to use Option[string]. * Simplify getFinalModel logic in common.nim. * Add json_schema to OpenRouter provider. * Update version to 0.4.0. * Include options module in config.nim and t_config_loading.nim.
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.
fromOpenAIprocedure to parse OpenAI API responses.fromOpenRouterprocedure for parsing OpenRouter API responses.OpenAIRouterandOpenRouterproviders to use their respectiveparsing procedures.
OpenAIandOpenRouterproviders to include the"role" field in mock responses.
jsonyfromseance.nimbleandnimble.lock.jsonyserialization/deserialization with Nim's built-injsonand
std/optionsfor all providers.openai.nimto use$(%*request)for serialization andto(parseJson(responseBodyContent), ChatResponse)for deserialization.openrouter.nimto use$(%*request)for serialization andto(parseJson(responseBodyContent), ChatResponse)for deserialization.anthropic.nimto use$(%*request)for serialization anda custom
fromAnthropicproc for deserialization.gemini.nimto use$(%*request)for serialization anda custom
fromGeminiproc for deserialization.--schemaflag for enforcing JSON output structure.schemaparameter tochatmethods across providers.