assistant: Add foundation for receiving tool uses from Anthropic models (#17170)
This PR updates the Assistant with support for receiving tool uses from Anthropic models and capturing them as text in the context editor. This is just laying the foundation for tool use. We don't yet fulfill the tool uses yet, or define any tools for the model to use. Here's an example of what it looks like using the example `get_weather` tool from the Anthropic docs: <img width="644" alt="Screenshot 2024-08-30 at 1 51 13 PM" src="https://github.com/user-attachments/assets/3614f953-0689-423c-8955-b146729ea638"> Release Notes: - N/A
This commit is contained in:
parent
ea25d438d1
commit
68ea661711
8 changed files with 114 additions and 25 deletions
|
@ -370,7 +370,7 @@ impl LanguageModel for AnthropicModel {
|
|||
let request = self.stream_completion(request, cx);
|
||||
let future = self.request_limiter.stream(async move {
|
||||
let response = request.await.map_err(|err| anyhow!(err))?;
|
||||
Ok(anthropic::extract_text_from_events(response))
|
||||
Ok(anthropic::extract_content_from_events(response))
|
||||
});
|
||||
async move {
|
||||
Ok(future
|
||||
|
|
|
@ -515,9 +515,9 @@ impl LanguageModel for CloudLanguageModel {
|
|||
},
|
||||
)
|
||||
.await?;
|
||||
Ok(anthropic::extract_text_from_events(
|
||||
Ok(anthropic::extract_content_from_events(Box::pin(
|
||||
response_lines(response).map_err(AnthropicError::Other),
|
||||
))
|
||||
)))
|
||||
});
|
||||
async move {
|
||||
Ok(future
|
||||
|
|
|
@ -221,9 +221,17 @@ impl LanguageModelRequestMessage {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Hash, Clone, Serialize, Deserialize)]
|
||||
pub struct LanguageModelRequestTool {
|
||||
pub name: String,
|
||||
pub description: String,
|
||||
pub input_schema: serde_json::Value,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq)]
|
||||
pub struct LanguageModelRequest {
|
||||
pub messages: Vec<LanguageModelRequestMessage>,
|
||||
pub tools: Vec<LanguageModelRequestTool>,
|
||||
pub stop: Vec<String>,
|
||||
pub temperature: f32,
|
||||
}
|
||||
|
@ -355,7 +363,15 @@ impl LanguageModelRequest {
|
|||
messages: new_messages,
|
||||
max_tokens: max_output_tokens,
|
||||
system: Some(system_message),
|
||||
tools: Vec::new(),
|
||||
tools: self
|
||||
.tools
|
||||
.into_iter()
|
||||
.map(|tool| anthropic::Tool {
|
||||
name: tool.name,
|
||||
description: tool.description,
|
||||
input_schema: tool.input_schema,
|
||||
})
|
||||
.collect(),
|
||||
tool_choice: None,
|
||||
metadata: None,
|
||||
stop_sequences: Vec::new(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue