Skip to content

Commit

Permalink
fix(openai): Reorder model matching logic to prioritize tool calls
Browse files Browse the repository at this point in the history
The change swaps the order of the two model matching cases to give
    priority to processing the tool call message. This is because
    in some cases, the tool call message may be more important and
    should be processed first. The updated code first matches the
    tool call message, and then the content message. This ensures
    that the tool call message is processed correctly and promptly.
  • Loading branch information
M4n5ter committed Dec 18, 2024
1 parent 51e15b0 commit f55768d
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions rig-core/src/providers/openai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,17 +375,6 @@ impl TryFrom<CompletionResponse> for completion::CompletionResponse<CompletionRe

fn try_from(value: CompletionResponse) -> std::prelude::v1::Result<Self, Self::Error> {
match value.choices.as_slice() {
[Choice {
message:
Message {
content: Some(content),
..
},
..
}, ..] => Ok(completion::CompletionResponse {
choice: completion::ModelChoice::Message(content.to_string()),
raw_response: value,
}),
[Choice {
message:
Message {
Expand All @@ -406,6 +395,17 @@ impl TryFrom<CompletionResponse> for completion::CompletionResponse<CompletionRe
raw_response: value,
})
}
[Choice {
message:
Message {
content: Some(content),
..
},
..
}, ..] => Ok(completion::CompletionResponse {
choice: completion::ModelChoice::Message(content.to_string()),
raw_response: value,
}),
_ => Err(CompletionError::ResponseError(
"Response did not contain a message or tool call".into(),
)),
Expand Down

0 comments on commit f55768d

Please sign in to comment.