Skip to content

v0.17.0

Choose a tag to compare

@thorrester thorrester released this 14 Mar 14:48
· 58 commits to main since this release
21c5b3b

v0.17.0 Release Summary

What Changed

The ResponseAdapter trait now supports unified extraction of model name, finish reason, token usage, and tool calls across all LLM provider response types. A new ChatResponse::from_response_value method enables dynamic deserialization of unknown JSON payloads into the correct provider variant.


Breaking Changes

The ResponseAdapter trait gains 6 new required methods. Any type implementing ResponseAdapter outside of this crate must add the following:

Method Return type
model_name() Option<&str>
finish_reason() Option<&str>
input_tokens() Option<i64>
output_tokens() Option<i64>
total_tokens() Option<i64>
get_tool_calls() Vec<ToolCallInfo>

ToolCallInfo is a new public struct in potato_type::tools.


Changes

ResponseAdapter trait extensions

Six methods added to ResponseAdapter in potato_type::traits. Each provider implements them against its native response schema:

  • OpenAI: Reads from choices[0].finish_reason, usage.prompt_tokens / completion_tokens / total_tokens, and choices[*].message.tool_calls.
  • Anthropic: Maps stop_reason enum variants to string slices ("end_turn", "max_tokens", "stop_sequence", "tool_use"). Extracts tool calls from content blocks of type ToolUse.
  • Google Gemini / Vertex Generate: Reads candidates[0].finish_reason (via new FinishReason::as_str()), usage_metadata token counts, and functionCall parts. FinishReason also gains a Display impl.
  • Google Vertex Predict (embeddings): All new methods return None or empty — embeddings have no finish reason, token counts, or tool calls.

ToolCallInfo

New struct in potato_type::tools:

pub struct ToolCallInfo {
    pub name: String,
    pub arguments: serde_json::Value,
    pub call_id: Option<String>,
    pub result: Option<serde_json::Value>,
}

Provides a provider-agnostic representation of a tool call. Each provider's get_tool_calls() maps its native format (OpenAI's stringified JSON arguments, Anthropic's direct Value input, Google's Map<String, Value> args) into this struct.

ChatResponse::from_response_value

Discriminant-based JSON router on the ChatResponse enum. Inspects top-level keys to select the correct variant:

Key(s) present Deserializes as
choices OpenAIChatResponse
predictions PredictResponse (Vertex)
candidates GenerateContentResponse (Gemini)
stop_reason + content AnthropicMessageResponse

Returns ProviderError::DeserializationError (new variant) if no pattern matches or deserialization fails.

ChatResponse trait dispatch

ChatResponse now delegates all 6 new ResponseAdapter methods to the inner variant, matching the existing pattern for the other trait methods.

Test coverage

98 new tests across 5 files covering all ResponseAdapter implementations, ChatResponse dispatch, from_response_value routing, and JSON deserialization from raw strings.


Upgrading from v0.16.1

  1. If you implement ResponseAdapter on custom types, add the 6 new methods listed in Breaking Changes above.
  2. Add use potato_type::tools::ToolCallInfo where needed for get_tool_calls() return values.
  3. No schema changes, no config changes, no migration required beyond the trait additions.