Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions crates/coverage-report/src/requests_expected_differences.json
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,20 @@
"skip": true,
"reason": "Anthropic extracts system messages to separate system parameter"
},
{
"testCase": "systemMessageArrayContent",
"source": "ChatCompletions",
"target": "Anthropic",
"skip": true,
"reason": "Anthropic extracts system messages to separate system parameter"
},
{
"testCase": "systemMessageArrayContent",
"source": "Responses",
"target": "Anthropic",
"skip": true,
"reason": "Anthropic extracts system messages to separate system parameter"
},
{
"testCase": "multimodalRequest",
"source": "Responses",
Expand Down
20 changes: 15 additions & 5 deletions crates/lingua/src/providers/anthropic/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::providers::anthropic::params::AnthropicParams;
use crate::providers::anthropic::try_parse_anthropic;
use crate::serde_json::{self, Map, Value};
use crate::universal::convert::TryFromLLM;
use crate::universal::message::{Message, UserContent};
use crate::universal::message::{Message, UserContent, UserContentPart};
use crate::universal::tools::{tools_to_anthropic_value, UniversalTool};
use crate::universal::transform::extract_system_messages;
use crate::universal::{
Expand Down Expand Up @@ -147,10 +147,20 @@ impl ProviderAdapter for AnthropicAdapter {
// Add system message if present
if !system_contents.is_empty() {
let system_text: String = system_contents
.iter()
.filter_map(|c| match c {
UserContent::String(s) => Some(s.as_str()),
_ => None,
.into_iter()
.map(|c| match c {
UserContent::String(s) => s,
UserContent::Array(parts) => parts
.into_iter()
.filter_map(|p| {
if let UserContentPart::Text(t) = p {
Some(t.text)
} else {
None
}
})
.collect::<Vec<_>>()
.join("\n"),
})
.collect::<Vec<_>>()
.join("\n\n");
Expand Down
69 changes: 69 additions & 0 deletions payloads/cases/advanced.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,4 +395,73 @@ export const advancedCases: TestCaseCollection = {
},
},
},

systemMessageArrayContent: {
"chat-completions": {
model: OPENAI_CHAT_COMPLETIONS_MODEL,
messages: [
{
role: "system",
content: [
{
type: "text",
text: "You are a helpful data analyst. The default data source is project_logs with id abc-123.",
},
],
},
{
role: "user",
content: "What errors occurred recently?",
},
],
max_completion_tokens: 300,
},
responses: {
model: OPENAI_RESPONSES_MODEL,
instructions:
"You are a helpful data analyst. The default data source is project_logs with id abc-123.",
input: [
{
role: "user",
content: "What errors occurred recently?",
},
],
max_output_tokens: 300,
},
anthropic: {
model: ANTHROPIC_MODEL,
max_tokens: 300,
system: [
{
type: "text",
text: "You are a helpful data analyst. The default data source is project_logs with id abc-123.",
},
],
messages: [
{
role: "user",
content: "What errors occurred recently?",
},
],
},
google: {
systemInstruction: {
parts: [
{
text: "You are a helpful data analyst. The default data source is project_logs with id abc-123.",
},
],
},
contents: [
{
role: "user",
parts: [{ text: "What errors occurred recently?" }],
},
],
config: {
maxOutputTokens: 300,
},
},
bedrock: null,
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"model": "claude-sonnet-4-20250514",
"max_tokens": 300,
"system": [
{
"type": "text",
"text": "You are a helpful data analyst. The default data source is project_logs with id abc-123."
}
],
"messages": [
{
"role": "user",
"content": "What errors occurred recently?"
},
{
"role": "assistant",
"content": [
{
"type": "text",
"text": "I'll help you find recent errors from the project logs. Let me query the data to identify error events.\n\n```sql\nSELECT \n timestamp,\n level,\n message,\n source,\n error_code\nFROM project_logs \nWHERE level IN ('ERROR', 'CRITICAL', 'FATAL')\n AND timestamp >= DATETIME_SUB(CURRENT_TIMESTAMP(), INTERVAL 24 HOURS)\nORDER BY timestamp DESC\nLIMIT 20;\n```\n\nThis query will show:\n- **Recent errors** from the last 24 hours\n- **Error details** including timestamp, severity level, and error messages\n- **Source information** to help identify where errors originated\n- **Error codes** if available\n\nWould you like me to:\n1. Extend the time range (e.g., last week)?\n2. Filter by specific error types or sources?\n3. Group errors by frequency to show the most common issues?\n4. Include additional context like user IDs or request IDs if available?\n\nPlease let me know if you need the query adjusted or if you'd like me to analyze the results in a specific way!"
}
]
},
{
"role": "user",
"content": "What should I do next?"
}
]
}
Loading