Feat: LLM Generation Client Returns Json #570
Closed
+85
−91
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.
Implements #400
Note: Still testing OpenAI and Anthropic clients, Gemini and Ollama work as expected.
Return Type:
LlmGenerationResponseAll client files (
anthropic.rs, gemini.rs, ollama.rs, openai.rs) implement theLlmGenerationClienttrait and theirgenerate()methods returnLlmGenerationResponse, which supports bothJson(serde_json::Value)andText(String).This is consistent with the enum definition in
mod.rs.Strict JSON Prompt Handling
Anthropic:
output_formatisJsonSchemaand prependsSTRICT_JSON_PROMPTto the system prompt.payload["system"] = ...for the system prompt.json5fallback removed as no longer required.Gemini:
payload["systemInstruction"] = ...for the system prompt.Ollama:
system: Some(system_prompt.as_str())in the request.OpenAI:
STRICT_JSON_PROMPT. Instead, uses OpenAI’s native strict JSON mode viaResponseFormat::JsonSchema { ... strict: Some(true), ... }.Prompt Utility (
prompt_utils.rs)Follow Up: Requires Unit Tests to test all LLM Clients at once at once after its merged.
httpmockcratejsonschema