Merge branch 'zed-industries:main' into main
This commit is contained in:
commit
62af5e6542
489 changed files with 13211 additions and 10509 deletions
|
@ -554,7 +554,7 @@ pub fn into_anthropic(
|
|||
.into_iter()
|
||||
.filter_map(|content| match content {
|
||||
MessageContent::Text(text) => {
|
||||
let text = if text.chars().last().map_or(false, |c| c.is_whitespace()) {
|
||||
let text = if text.chars().last().is_some_and(|c| c.is_whitespace()) {
|
||||
text.trim_end().to_string()
|
||||
} else {
|
||||
text
|
||||
|
@ -633,11 +633,11 @@ pub fn into_anthropic(
|
|||
Role::Assistant => anthropic::Role::Assistant,
|
||||
Role::System => unreachable!("System role should never occur here"),
|
||||
};
|
||||
if let Some(last_message) = new_messages.last_mut() {
|
||||
if last_message.role == anthropic_role {
|
||||
last_message.content.extend(anthropic_message_content);
|
||||
continue;
|
||||
}
|
||||
if let Some(last_message) = new_messages.last_mut()
|
||||
&& last_message.role == anthropic_role
|
||||
{
|
||||
last_message.content.extend(anthropic_message_content);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Mark the last segment of the message as cached
|
||||
|
@ -813,7 +813,7 @@ impl AnthropicEventMapper {
|
|||
))];
|
||||
}
|
||||
}
|
||||
return vec![];
|
||||
vec![]
|
||||
}
|
||||
},
|
||||
Event::ContentBlockStop { index } => {
|
||||
|
|
|
@ -412,10 +412,10 @@ impl BedrockModel {
|
|||
.region(Region::new(region))
|
||||
.timeout_config(TimeoutConfig::disabled());
|
||||
|
||||
if let Some(endpoint_url) = endpoint {
|
||||
if !endpoint_url.is_empty() {
|
||||
config_builder = config_builder.endpoint_url(endpoint_url);
|
||||
}
|
||||
if let Some(endpoint_url) = endpoint
|
||||
&& !endpoint_url.is_empty()
|
||||
{
|
||||
config_builder = config_builder.endpoint_url(endpoint_url);
|
||||
}
|
||||
|
||||
match auth_method {
|
||||
|
@ -728,11 +728,11 @@ pub fn into_bedrock(
|
|||
Role::Assistant => bedrock::BedrockRole::Assistant,
|
||||
Role::System => unreachable!("System role should never occur here"),
|
||||
};
|
||||
if let Some(last_message) = new_messages.last_mut() {
|
||||
if last_message.role == bedrock_role {
|
||||
last_message.content.extend(bedrock_message_content);
|
||||
continue;
|
||||
}
|
||||
if let Some(last_message) = new_messages.last_mut()
|
||||
&& last_message.role == bedrock_role
|
||||
{
|
||||
last_message.content.extend(bedrock_message_content);
|
||||
continue;
|
||||
}
|
||||
new_messages.push(
|
||||
BedrockMessage::builder()
|
||||
|
|
|
@ -270,7 +270,7 @@ impl State {
|
|||
if response.status().is_success() {
|
||||
let mut body = String::new();
|
||||
response.body_mut().read_to_string(&mut body).await?;
|
||||
return Ok(serde_json::from_str(&body)?);
|
||||
Ok(serde_json::from_str(&body)?)
|
||||
} else {
|
||||
let mut body = String::new();
|
||||
response.body_mut().read_to_string(&mut body).await?;
|
||||
|
@ -597,15 +597,13 @@ impl CloudLanguageModel {
|
|||
.headers()
|
||||
.get(SUBSCRIPTION_LIMIT_RESOURCE_HEADER_NAME)
|
||||
.and_then(|resource| resource.to_str().ok())
|
||||
{
|
||||
if let Some(plan) = response
|
||||
&& let Some(plan) = response
|
||||
.headers()
|
||||
.get(CURRENT_PLAN_HEADER_NAME)
|
||||
.and_then(|plan| plan.to_str().ok())
|
||||
.and_then(|plan| cloud_llm_client::Plan::from_str(plan).ok())
|
||||
{
|
||||
return Err(anyhow!(ModelRequestLimitReachedError { plan }));
|
||||
}
|
||||
{
|
||||
return Err(anyhow!(ModelRequestLimitReachedError { plan }));
|
||||
}
|
||||
} else if status == StatusCode::PAYMENT_REQUIRED {
|
||||
return Err(anyhow!(PaymentRequiredError));
|
||||
|
@ -662,29 +660,29 @@ where
|
|||
|
||||
impl From<ApiError> for LanguageModelCompletionError {
|
||||
fn from(error: ApiError) -> Self {
|
||||
if let Ok(cloud_error) = serde_json::from_str::<CloudApiError>(&error.body) {
|
||||
if cloud_error.code.starts_with("upstream_http_") {
|
||||
let status = if let Some(status) = cloud_error.upstream_status {
|
||||
status
|
||||
} else if cloud_error.code.ends_with("_error") {
|
||||
error.status
|
||||
} else {
|
||||
// If there's a status code in the code string (e.g. "upstream_http_429")
|
||||
// then use that; otherwise, see if the JSON contains a status code.
|
||||
cloud_error
|
||||
.code
|
||||
.strip_prefix("upstream_http_")
|
||||
.and_then(|code_str| code_str.parse::<u16>().ok())
|
||||
.and_then(|code| StatusCode::from_u16(code).ok())
|
||||
.unwrap_or(error.status)
|
||||
};
|
||||
if let Ok(cloud_error) = serde_json::from_str::<CloudApiError>(&error.body)
|
||||
&& cloud_error.code.starts_with("upstream_http_")
|
||||
{
|
||||
let status = if let Some(status) = cloud_error.upstream_status {
|
||||
status
|
||||
} else if cloud_error.code.ends_with("_error") {
|
||||
error.status
|
||||
} else {
|
||||
// If there's a status code in the code string (e.g. "upstream_http_429")
|
||||
// then use that; otherwise, see if the JSON contains a status code.
|
||||
cloud_error
|
||||
.code
|
||||
.strip_prefix("upstream_http_")
|
||||
.and_then(|code_str| code_str.parse::<u16>().ok())
|
||||
.and_then(|code| StatusCode::from_u16(code).ok())
|
||||
.unwrap_or(error.status)
|
||||
};
|
||||
|
||||
return LanguageModelCompletionError::UpstreamProviderError {
|
||||
message: cloud_error.message,
|
||||
status,
|
||||
retry_after: cloud_error.retry_after.map(Duration::from_secs_f64),
|
||||
};
|
||||
}
|
||||
return LanguageModelCompletionError::UpstreamProviderError {
|
||||
message: cloud_error.message,
|
||||
status,
|
||||
retry_after: cloud_error.retry_after.map(Duration::from_secs_f64),
|
||||
};
|
||||
}
|
||||
|
||||
let retry_after = None;
|
||||
|
|
|
@ -530,7 +530,7 @@ pub fn into_google(
|
|||
let system_instructions = if request
|
||||
.messages
|
||||
.first()
|
||||
.map_or(false, |msg| matches!(msg.role, Role::System))
|
||||
.is_some_and(|msg| matches!(msg.role, Role::System))
|
||||
{
|
||||
let message = request.messages.remove(0);
|
||||
Some(SystemInstruction {
|
||||
|
|
|
@ -404,7 +404,7 @@ pub fn into_open_ai(
|
|||
match content {
|
||||
MessageContent::Text(text) | MessageContent::Thinking { text, .. } => {
|
||||
add_message_content_part(
|
||||
open_ai::MessagePart::Text { text: text },
|
||||
open_ai::MessagePart::Text { text },
|
||||
message.role,
|
||||
&mut messages,
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue