Skip to content
Merged
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
74 changes: 0 additions & 74 deletions bindings/typescript/tests/two-step-conversion.test.ts

This file was deleted.

184 changes: 0 additions & 184 deletions crates/lingua/src/processing/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,187 +395,3 @@ pub fn import_and_deduplicate_messages(spans: Vec<Span>) -> Vec<Message> {
let messages = import_messages_from_spans(spans);
super::dedup::deduplicate_messages(messages)
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_import_empty_spans() {
let spans = vec![];
let messages = import_messages_from_spans(spans);
assert_eq!(messages.len(), 0);
}

#[test]
fn test_import_spans_with_no_messages() {
let span = Span {
input: Some(crate::serde_json::json!({"random": "data"})),
output: None,
other: crate::serde_json::Map::new(),
};
let messages = import_messages_from_spans(vec![span]);
assert_eq!(messages.len(), 0);
}

#[test]
fn test_import_spans_with_chat_completion_messages() {
let span = Span {
input: Some(crate::serde_json::json!([
{"role": "user", "content": "Hello"},
{"role": "assistant", "content": "Hi there"}
])),
output: None,
other: crate::serde_json::Map::new(),
};
let messages = import_messages_from_spans(vec![span]);
assert_eq!(messages.len(), 2);
}

#[test]
fn test_import_spans_with_choices_array_output() {
let span = Span {
input: Some(crate::serde_json::json!([
{"role": "user", "content": "Hello"}
])),
output: Some(crate::serde_json::json!([
{
"finish_reason": "stop",
"index": 0,
"logprobs": null,
"message": {
"content": "Hi there!",
"role": "assistant"
}
}
])),
other: crate::serde_json::Map::new(),
};
let messages = import_messages_from_spans(vec![span]);
assert_eq!(messages.len(), 2); // 1 from input, 1 from output
}

#[test]
fn test_import_spans_with_single_message_object() {
let span = Span {
input: Some(crate::serde_json::json!([
{"role": "user", "content": "Hello"}
])),
output: Some(crate::serde_json::json!({
"role": "assistant",
"content": [
{
"type": "text",
"text": "Hi there!",
"citations": null
}
]
})),
other: crate::serde_json::Map::new(),
};
let messages = import_messages_from_spans(vec![span]);
assert_eq!(messages.len(), 2); // 1 from input, 1 from output
}

#[test]
fn test_import_anthropic_tool_message_with_choice_output() {
// Mirrors "complex anthropic example" from TypeScript tests
let span = Span {
input: Some(crate::serde_json::json!([
{
"content": [
{
"cache_control": {
"type": "ephemeral"
},
"text": "results:\n ",
"type": "text"
}
],
"role": "tool",
"tool_call_id": "call_uZG3WxdNadqhidWK9milQNxR"
}
])),
output: Some(crate::serde_json::json!([
{
"finish_reason": "stop",
"index": 0,
"logprobs": null,
"message": {
"content": "The scorer still returns",
"role": "assistant"
}
}
])),
other: crate::serde_json::Map::new(),
};
let messages = import_messages_from_spans(vec![span]);
assert_eq!(messages.len(), 2); // 1 tool message from input, 1 assistant from output
}

#[test]
fn test_import_single_anthropic_message_with_citations() {
// Mirrors "complex anthropic example 2" from TypeScript tests
let span = Span {
input: Some(crate::serde_json::json!([
{
"content": "How do I create a custom scorer?",
"role": "user"
},
{
"content": "You are a helpful assistant.",
"role": "system"
}
])),
output: Some(crate::serde_json::json!({
"content": [
{
"citations": null,
"text": "A dataset record in Braintrust has the following fields...",
"type": "text"
}
],
"role": "assistant"
})),
other: crate::serde_json::Map::new(),
};
let messages = import_messages_from_spans(vec![span]);
assert_eq!(messages.len(), 3); // 2 from input, 1 from output
}

#[test]
fn test_import_spans_with_prompt_wrapper_and_tool_calls() {
let span = Span {
input: Some(crate::serde_json::json!({
"prompt": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": [{"type": "text", "text": "Hello"}]},
{
"role": "assistant",
"content": [{
"type": "tool-call",
"toolCallId": "call_1",
"toolName": "bash",
"input": {"command": "ls"}
}]
},
{
"role": "tool",
"content": [{
"type": "tool-result",
"toolCallId": "call_1",
"toolName": "bash",
"output": {"stdout": "ok"}
}]
},
{"role": "assistant", "content": [{"type": "text", "text": "Done"}]}
]
})),
output: None,
other: crate::serde_json::Map::new(),
};

let messages = import_messages_from_spans(vec![span]);
assert_eq!(messages.len(), 5);
}
}
Loading