cargo fmt
This commit is contained in:
@@ -25,11 +25,7 @@ use llm_worker::llm_client::scheme::{
|
||||
};
|
||||
use llm_worker::llm_client::transport::{HttpTransport, ResolvedAuth};
|
||||
|
||||
fn make_transport<S: Scheme>(
|
||||
scheme: S,
|
||||
model: &str,
|
||||
auth: ResolvedAuth,
|
||||
) -> HttpTransport<S> {
|
||||
fn make_transport<S: Scheme>(scheme: S, model: &str, auth: ResolvedAuth) -> HttpTransport<S> {
|
||||
let cap = scheme.default_capability();
|
||||
let base_url = scheme.default_base_url().to_string();
|
||||
HttpTransport::new(scheme, model.to_string(), base_url, auth, cap)
|
||||
@@ -71,11 +67,7 @@ async fn run_scenario_with_anthropic(
|
||||
let api_key = std::env::var("ANTHROPIC_API_KEY")
|
||||
.expect("ANTHROPIC_API_KEY environment variable must be set");
|
||||
let model = model.as_deref().unwrap_or("claude-sonnet-4-20250514");
|
||||
let client = make_transport(
|
||||
AnthropicScheme::new(),
|
||||
model,
|
||||
ResolvedAuth::ApiKey(api_key),
|
||||
);
|
||||
let client = make_transport(AnthropicScheme::new(), model, ResolvedAuth::ApiKey(api_key));
|
||||
|
||||
recorder::record_request(
|
||||
&client,
|
||||
|
||||
@@ -338,11 +338,7 @@ fn default_capability() -> ModelCapability {
|
||||
}
|
||||
}
|
||||
|
||||
fn build_transport<S: Scheme>(
|
||||
scheme: S,
|
||||
model: String,
|
||||
auth: ResolvedAuth,
|
||||
) -> Box<dyn LlmClient> {
|
||||
fn build_transport<S: Scheme>(scheme: S, model: String, auth: ResolvedAuth) -> Box<dyn LlmClient> {
|
||||
let cap = scheme.default_capability();
|
||||
let base_url = scheme.default_base_url().to_string();
|
||||
Box::new(HttpTransport::new(scheme, model, base_url, auth, cap))
|
||||
|
||||
@@ -7,9 +7,9 @@ use std::collections::BTreeSet;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::llm_client::{
|
||||
capability::{CacheStrategy, ModelCapability, ReasoningControl, ReasoningSupport},
|
||||
types::{parse_tool_arguments, ContentPart, Item, Role, ToolDefinition},
|
||||
Request,
|
||||
capability::{CacheStrategy, ModelCapability, ReasoningControl, ReasoningSupport},
|
||||
types::{ContentPart, Item, Role, ToolDefinition, parse_tool_arguments},
|
||||
};
|
||||
|
||||
use super::AnthropicScheme;
|
||||
@@ -600,7 +600,7 @@ mod tests {
|
||||
let scheme = AnthropicScheme::new();
|
||||
let mut items = completed_turn();
|
||||
items.push(Item::user_message("next turn")); // index 5 = latest user
|
||||
// cache_anchor=None, turn_end=4, head=5.
|
||||
// cache_anchor=None, turn_end=4, head=5.
|
||||
let request = Request::new().items(items);
|
||||
|
||||
let req = scheme.build_request("claude-sonnet-4-20250514", &request, &cap_explicit());
|
||||
|
||||
@@ -7,9 +7,9 @@ use serde_json::Value;
|
||||
|
||||
use crate::llm_client::{
|
||||
ClientError,
|
||||
auth::AuthRequirement,
|
||||
capability::ModelCapability,
|
||||
event::{BlockStop, BlockType, Event},
|
||||
auth::AuthRequirement,
|
||||
scheme::Scheme,
|
||||
types::Request,
|
||||
};
|
||||
|
||||
@@ -6,9 +6,9 @@ use serde::Serialize;
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::llm_client::{
|
||||
capability::{ModelCapability, ReasoningControl, ReasoningSupport},
|
||||
types::{parse_tool_arguments, Item, Role, ToolDefinition},
|
||||
Request,
|
||||
capability::{ModelCapability, ReasoningControl, ReasoningSupport},
|
||||
types::{Item, Role, ToolDefinition, parse_tool_arguments},
|
||||
};
|
||||
|
||||
use super::GeminiScheme;
|
||||
|
||||
@@ -3,11 +3,7 @@
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::llm_client::{
|
||||
ClientError,
|
||||
capability::ModelCapability,
|
||||
event::Event,
|
||||
auth::AuthRequirement,
|
||||
scheme::Scheme,
|
||||
ClientError, auth::AuthRequirement, capability::ModelCapability, event::Event, scheme::Scheme,
|
||||
types::Request,
|
||||
};
|
||||
|
||||
|
||||
@@ -90,4 +90,3 @@ pub trait Scheme: Clone + Send + Sync + 'static {
|
||||
Vec::new()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,9 +6,9 @@ use serde::Serialize;
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::llm_client::{
|
||||
capability::{ModelCapability, ReasoningControl, ReasoningSupport},
|
||||
types::{parse_tool_arguments, Item, Role, ToolDefinition},
|
||||
Request,
|
||||
capability::{ModelCapability, ReasoningControl, ReasoningSupport},
|
||||
types::{Item, Role, ToolDefinition, parse_tool_arguments},
|
||||
};
|
||||
|
||||
use super::OpenAIScheme;
|
||||
|
||||
@@ -38,11 +38,7 @@ impl OpenAIResponsesState {
|
||||
/// 既存 slot を取得。無ければ `block_type` で暗黙に確保し、
|
||||
/// 新規確保したかを併せて返す。delta 先行 / content_part.added が
|
||||
/// 抜けたときの防御。
|
||||
fn get_or_allocate(
|
||||
&mut self,
|
||||
key: SlotKey,
|
||||
block_type: BlockType,
|
||||
) -> (SlotInfo, bool) {
|
||||
fn get_or_allocate(&mut self, key: SlotKey, block_type: BlockType) -> (SlotInfo, bool) {
|
||||
if let Some(info) = self.slots.get(&key).copied() {
|
||||
(info, false)
|
||||
} else {
|
||||
@@ -303,15 +299,12 @@ pub(crate) fn parse_sse(
|
||||
match ev.item {
|
||||
OutputItem::FunctionCall { call_id, name, .. }
|
||||
| OutputItem::CustomToolCall { call_id, name, .. } => {
|
||||
let info = state
|
||||
.allocate(SlotKey::OutputItem(ev.output_index), BlockType::ToolUse);
|
||||
let info =
|
||||
state.allocate(SlotKey::OutputItem(ev.output_index), BlockType::ToolUse);
|
||||
Ok(vec![Event::BlockStart(BlockStart {
|
||||
index: info.flat_index,
|
||||
block_type: BlockType::ToolUse,
|
||||
metadata: BlockMetadata::ToolUse {
|
||||
id: call_id,
|
||||
name,
|
||||
},
|
||||
metadata: BlockMetadata::ToolUse { id: call_id, name },
|
||||
})])
|
||||
}
|
||||
_ => Ok(Vec::new()),
|
||||
@@ -530,11 +523,7 @@ mod tests {
|
||||
(events, state)
|
||||
}
|
||||
|
||||
fn with(
|
||||
state: &mut OpenAIResponsesState,
|
||||
event_type: &str,
|
||||
data: &str,
|
||||
) -> Vec<Event> {
|
||||
fn with(state: &mut OpenAIResponsesState, event_type: &str, data: &str) -> Vec<Event> {
|
||||
parse_sse(event_type, data, state).unwrap()
|
||||
}
|
||||
|
||||
@@ -551,7 +540,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn completed_emits_usage_and_status() {
|
||||
let data = r#"{"response":{"usage":{"input_tokens":10,"output_tokens":20,"total_tokens":30}}}"#;
|
||||
let data =
|
||||
r#"{"response":{"usage":{"input_tokens":10,"output_tokens":20,"total_tokens":30}}}"#;
|
||||
let (events, _) = run("response.completed", data);
|
||||
assert!(matches!(events[0], Event::Usage(_)));
|
||||
assert!(matches!(
|
||||
@@ -761,8 +751,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn failed_response_emits_error_and_status() {
|
||||
let data =
|
||||
r#"{"response":{"error":{"type":"invalid_request_error","message":"bad"}}}"#;
|
||||
let data = r#"{"response":{"error":{"type":"invalid_request_error","message":"bad"}}}"#;
|
||||
let (events, _) = run("response.failed", data);
|
||||
assert_eq!(events.len(), 2);
|
||||
assert!(matches!(events[0], Event::Error(_)));
|
||||
|
||||
@@ -3,11 +3,7 @@
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::llm_client::{
|
||||
ClientError,
|
||||
auth::AuthRequirement,
|
||||
capability::ModelCapability,
|
||||
event::Event,
|
||||
scheme::Scheme,
|
||||
ClientError, auth::AuthRequirement, capability::ModelCapability, event::Event, scheme::Scheme,
|
||||
types::Request,
|
||||
};
|
||||
|
||||
|
||||
@@ -46,7 +46,9 @@ impl ResolvedAuth {
|
||||
(Self::Custom(_), _) => true,
|
||||
(
|
||||
Self::ApiKey(_),
|
||||
AuthRequirement::Bearer | AuthRequirement::XApiKey | AuthRequirement::QueryParam { .. },
|
||||
AuthRequirement::Bearer
|
||||
| AuthRequirement::XApiKey
|
||||
| AuthRequirement::QueryParam { .. },
|
||||
) => true,
|
||||
_ => false,
|
||||
}
|
||||
|
||||
@@ -568,9 +568,7 @@ impl<C: LlmClient, S: WorkerState> Worker<C, S> {
|
||||
// Attach the cache prefix anchor (may be narrower than `context`
|
||||
// if the prune projection trimmed items from the head — keep it
|
||||
// in range).
|
||||
request.cache_anchor = self
|
||||
.cache_anchor
|
||||
.filter(|&anchor| anchor < context.len());
|
||||
request.cache_anchor = self.cache_anchor.filter(|&anchor| anchor < context.len());
|
||||
|
||||
request
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user