Skip to content

Commit

Permalink
chore: apply pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
carlos-verdes committed Feb 11, 2025
1 parent 3e13b71 commit 97448c4
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 30 deletions.
1 change: 0 additions & 1 deletion rig-core/examples/multi_turn_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ impl<M: rig::completion::CompletionModel> MultiTurnAgent<M> {

let ToolCall {
id,
index: _,
function: ToolFunction { name, arguments },
} = content;

Expand Down
3 changes: 0 additions & 3 deletions rig-core/src/completion/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ pub enum ToolResultContent {
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
pub struct ToolCall {
pub id: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub index: Option<usize>,
pub function: ToolFunction,
}

Expand Down Expand Up @@ -302,7 +300,6 @@ impl AssistantContent {
) -> Self {
AssistantContent::ToolCall(ToolCall {
id: id.into(),
index: None,
function: ToolFunction {
name: name.into(),
arguments,
Expand Down
22 changes: 8 additions & 14 deletions rig-core/src/providers/anthropic/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,15 +292,13 @@ impl From<message::AssistantContent> for Content {
fn from(text: message::AssistantContent) -> Self {
match text {
message::AssistantContent::Text(message::Text { text }) => Content::Text { text },
message::AssistantContent::ToolCall(message::ToolCall {
id,
index: _,
function,
}) => Content::ToolUse {
id,
name: function.name,
input: function.arguments,
},
message::AssistantContent::ToolCall(message::ToolCall { id, function }) => {
Content::ToolUse {
id,
name: function.name,
input: function.arguments,
}
}
}
}
}
Expand Down Expand Up @@ -933,11 +931,7 @@ mod tests {
assert_eq!(content.len(), 1);

match content.first() {
message::AssistantContent::ToolCall(message::ToolCall {
id,
index: _,
function,
}) => {
message::AssistantContent::ToolCall(message::ToolCall { id, function }) => {
assert_eq!(id, "toolu_01A09q90qw90lq917835lq9");
assert_eq!(function.name, "get_weather");
assert_eq!(function.arguments, json!({"location": "San Francisco, CA"}));
Expand Down
5 changes: 3 additions & 2 deletions rig-core/src/providers/deepseek.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl Client {
headers
})
.build()
.expect("DeeSeek reqwest client should build"),
.expect("DeepSeek reqwest client should build"),
}
}

Expand Down Expand Up @@ -177,7 +177,8 @@ impl From<message::ToolCall> for ToolCall {
fn from(tool_call: message::ToolCall) -> Self {
Self {
id: tool_call.id,
index: tool_call.index.unwrap_or_default(),
// TODO: update index when we have it
index: 0,
r#type: ToolType::Function,
function: Function {
name: tool_call.function.name,
Expand Down
1 change: 0 additions & 1 deletion rig-core/src/providers/gemini/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,6 @@ pub mod gemini_api_types {
fn from(function_call: FunctionCall) -> Self {
Self {
id: function_call.name.clone(),
index: None,
function: message::ToolFunction {
name: function_call.name,
arguments: function_call.args,
Expand Down
14 changes: 5 additions & 9 deletions rig-core/src/providers/openai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::{
};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
use serde_json::json;

// ================================================================
// Main OpenAI Client
Expand Down Expand Up @@ -710,7 +710,6 @@ impl From<ToolCall> for message::ToolCall {
fn from(tool_call: ToolCall) -> Self {
Self {
id: tool_call.id,
index: None,
function: message::ToolFunction {
name: tool_call.function.name,
arguments: tool_call.function.arguments,
Expand Down Expand Up @@ -928,10 +927,10 @@ impl completion::CompletionModel for CompletionModel {
.await?;

if response.status().is_success() {
let t: Value = response.json().await?;
tracing::debug!(target: "rig", "OpenAI completion success: {}", serde_json::to_string_pretty(&t).unwrap());
let t = response.text().await?;
tracing::debug!(target: "rig", "OpenAI completion error: {}", t);

match serde_json::from_value::<ApiResponse<CompletionResponse>>(t)? {
match serde_json::from_str::<ApiResponse<CompletionResponse>>(&t)? {
ApiResponse::Ok(response) => {
tracing::info!(target: "rig",
"OpenAI completion token usage: {:?}",
Expand All @@ -942,10 +941,7 @@ impl completion::CompletionModel for CompletionModel {
ApiResponse::Err(err) => Err(CompletionError::ProviderError(err.message)),
}
} else {
let t = response.text().await?;
tracing::debug!(target: "rig", "OpenAI completion error: {}", &t);

Err(CompletionError::ProviderError(t))
Err(CompletionError::ProviderError(response.text().await?))
}
}
}
Expand Down

0 comments on commit 97448c4

Please sign in to comment.