Skip to content

Conversation

@knjiang
Copy link
Contributor

@knjiang knjiang commented Dec 30, 2025

This PR adds testing matrix + provider adapters for:

  • OpenAI (ChatCompletions)
  • Anthropic
  • Google
  • Bedrock (Converse)
  • OpenAI (Responses)

and callers use transform_request and transform_response to translate between providers.

The file below explains how to add a new provider based on the ProviderAdapter trait and also a closed testing loop so LLMs can just iterate:

https://github.com/braintrustdata/lingua/blob/a6019a6fc0a082a373d1f55c188df6483772b864/crates/lingua/docs/ADDING_PROVIDER_FORMAT.md

Current coverage status for the testing matrix is here ->:

https://github.com/braintrustdata/lingua/actions/runs/20666751649?pr=50

Copy link
Contributor Author

knjiang commented Dec 30, 2025

@knjiang knjiang force-pushed the 12-29-add_provideradapter_providerformat_transform_request_response_stream_chunk_patterns_to_lingua branch 6 times, most recently from c8c1f9b to a6019a6 Compare January 2, 2026 21:09
@knjiang knjiang marked this pull request as ready for review January 2, 2026 21:13
@knjiang knjiang requested a review from remh January 2, 2026 22:02
@remh remh mentioned this pull request Jan 5, 2026
.unwrap_or_else(|| "end_turn".to_string());

let mut obj = serde_json::json!({
"id": resp.extras.get("id").and_then(Value::as_str).unwrap_or("transformed"),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think extras are always an empty Map (see line 223 https://github.com/braintrustdata/lingua/pull/50/changes#diff-73d9a68f8109812b0b890dd8d1391334c99cbbee0595bd14a47a11f6dc0f06c5R223 ).
I'm not sure how important is this id though ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its required for anthropic response bodies but im gonna get rid of extras for now becuase it isn't really used. gonna just use a default value for id

.map(|r| match r {
"STOP" => "stop".to_string(),
"MAX_TOKENS" => "length".to_string(),
"SAFETY" | "RECITATION" | "OTHER" => "stop".to_string(),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

});

Ok(UniversalResponse {
model: None, // Bedrock doesn't include model in response
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, is that actually always the case? wonder if that might break things if we don't return the model?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, response bodys that require a model have a default when we go from response_from_universal in a openai/anthropic adapter. I made the strings less magic and added https://github.com/braintrustdata/lingua/blob/5f9c000a3f021c5544e78b312a1f83346c9ae545/crates/lingua/src/universal/defaults.rs

@knjiang knjiang force-pushed the 12-29-add_provideradapter_providerformat_transform_request_response_stream_chunk_patterns_to_lingua branch from a6019a6 to 5f9c000 Compare January 6, 2026 22:58
@knjiang knjiang requested a review from remh January 6, 2026 23:33
@knjiang knjiang merged commit cf24f3b into main Jan 8, 2026
5 checks passed
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.

3 participants