Skip to content

Commit 65729f4

Browse files
Vlaaaaaaadbenbrandt
authored andcommitted
opencode: Model updates + thinking levels (zed-industries#54880)
Leftovers after zed-industries#53651 Updated models: - **Zen**: GPT 5.5 and GPT 5.5 Pro - not tested because I don't have a Zen subscription and I stubbornly refuse to get one - **Go**: DeepSeek V4 Pro and DeepSeek V4 Flash - failing due to anomalyco/opencode#24224 - **Go**: MiMo V2.5 and MiMo V2.5 Pro - tested, confirmed working - **Free**: Ling 2.6 Flash, [available for "a limited time"](https://x.com/opencode/status/2046717718028513694) - tested, confirmed working - **Free**: Hy3 Preview, [available until May 8](https://x.com/opencode/status/2047328981435756824) - tested, confirmed working When testing the new models and comparing with OpenCode CLI, I realized the [variants](https://opencode.ai/docs/models/#built-in-variants)/thinking effort configuration was not supported by the Zed Agent implementation. I added that for OpenCode Go models, after manually checking what each model supports in OpenCode. Reasoning levels and everything seems to work (UI looks good, model works) but I have no idea how to specifically test reasoning levels without doing a full benchmark 🤷 I did not add the same thing for OpenCode Zen models because I could not figure out a way to get the supported variants. @benbrandt let me know if you want me to take this out of this PR and to keep just the model updates! Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content is consistent with the [UI/UX checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) - [ ] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable Release Notes: - OpenCode: add new models (GPT 5.5, DeepSeek V4, MiMo V2.5, Ling 2.6, Hy3) - OpenCode Go: add support for configurable reasoning effort levels --------- Co-authored-by: Ben Brandt <[email protected]>
1 parent fe99eb1 commit 65729f4

6 files changed

Lines changed: 201 additions & 19 deletions

File tree

‎Cargo.lock‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎crates/language_models/src/provider/opencode.rs‎

Lines changed: 80 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ use gpui::{AnyView, App, AsyncApp, Context, Entity, SharedString, Task, Window};
77
use http_client::{AsyncBody, HttpClient, http};
88
use language_model::{
99
ApiKeyState, AuthenticateError, EnvVar, IconOrSvg, LanguageModel, LanguageModelCompletionError,
10-
LanguageModelCompletionEvent, LanguageModelId, LanguageModelName, LanguageModelProvider,
11-
LanguageModelProviderId, LanguageModelProviderName, LanguageModelProviderState,
12-
LanguageModelRequest, LanguageModelToolChoice, RateLimiter, env_var,
10+
LanguageModelCompletionEvent, LanguageModelEffortLevel, LanguageModelId, LanguageModelName,
11+
LanguageModelProvider, LanguageModelProviderId, LanguageModelProviderName,
12+
LanguageModelProviderState, LanguageModelRequest, LanguageModelToolChoice, RateLimiter,
13+
ReasoningEffort, env_var,
1314
};
1415
use opencode::{ApiProtocol, OPENCODE_API_URL, OpenCodeSubscription};
1516
pub use settings::OpenCodeAvailableModel as AvailableModel;
@@ -29,6 +30,27 @@ use crate::provider::open_ai::{
2930
OpenAiEventMapper, OpenAiResponseEventMapper, into_open_ai, into_open_ai_response,
3031
};
3132

33+
fn normalize_reasoning_effort(effort: &str) -> Option<ReasoningEffort> {
34+
match effort.trim().to_ascii_lowercase().as_str() {
35+
"minimal" => Some(ReasoningEffort::Minimal),
36+
"low" => Some(ReasoningEffort::Low),
37+
"medium" => Some(ReasoningEffort::Medium),
38+
"high" => Some(ReasoningEffort::High),
39+
"max" | "xhigh" => Some(ReasoningEffort::XHigh),
40+
_ => None,
41+
}
42+
}
43+
44+
fn reasoning_effort_display(effort: ReasoningEffort) -> (&'static str, &'static str) {
45+
match effort {
46+
ReasoningEffort::Minimal => ("Minimal", "minimal"),
47+
ReasoningEffort::Low => ("Low", "low"),
48+
ReasoningEffort::Medium => ("Medium", "medium"),
49+
ReasoningEffort::High => ("High", "high"),
50+
ReasoningEffort::XHigh => ("Max", "max"),
51+
}
52+
}
53+
3254
const PROVIDER_ID: LanguageModelProviderId = LanguageModelProviderId::new("opencode");
3355
const PROVIDER_NAME: LanguageModelProviderName = LanguageModelProviderName::new("OpenCode");
3456

@@ -254,6 +276,7 @@ impl LanguageModelProvider for OpenCodeLanguageModelProvider {
254276
max_tokens: model.max_tokens,
255277
max_output_tokens: model.max_output_tokens,
256278
protocol,
279+
reasoning_effort_levels: model.reasoning_effort_levels.clone(),
257280
custom_model_api_url: model.custom_model_api_url.clone(),
258281
};
259282
let key = format!("{}/{}", subscription.id_prefix(), model.name);
@@ -522,6 +545,36 @@ impl LanguageModel for OpenCodeLanguageModel {
522545
self.model.supports_images()
523546
}
524547

548+
fn supports_thinking(&self) -> bool {
549+
self.model
550+
.supported_reasoning_effort_levels()
551+
.is_some_and(|levels| !levels.is_empty())
552+
}
553+
554+
fn supported_effort_levels(&self) -> Vec<LanguageModelEffortLevel> {
555+
self.model
556+
.supported_reasoning_effort_levels()
557+
.map(|levels| {
558+
if levels.is_empty() {
559+
return Vec::new();
560+
}
561+
let default_index = levels.len() - 1;
562+
levels
563+
.into_iter()
564+
.enumerate()
565+
.map(|(i, effort)| {
566+
let (name, value) = reasoning_effort_display(effort);
567+
LanguageModelEffortLevel {
568+
name: name.into(),
569+
value: value.into(),
570+
is_default: i == default_index,
571+
}
572+
})
573+
.collect()
574+
})
575+
.unwrap_or_default()
576+
}
577+
525578
fn supports_tool_choice(&self, choice: LanguageModelToolChoice) -> bool {
526579
match choice {
527580
LanguageModelToolChoice::Auto | LanguageModelToolChoice::Any => true,
@@ -576,12 +629,17 @@ impl LanguageModel for OpenCodeLanguageModel {
576629

577630
match self.model.protocol(self.subscription) {
578631
ApiProtocol::Anthropic => {
632+
let mode = if self.supports_thinking() && request.thinking_allowed {
633+
anthropic::AnthropicModelMode::AdaptiveThinking
634+
} else {
635+
anthropic::AnthropicModelMode::Default
636+
};
579637
let anthropic_request = into_anthropic(
580638
request,
581639
self.model.id().to_string(),
582640
1.0,
583641
self.model.max_output_tokens().unwrap_or(8192),
584-
anthropic::AnthropicModelMode::Default,
642+
mode,
585643
);
586644
let stream = self.stream_anthropic(anthropic_request, http_client, cx);
587645
async move {
@@ -591,13 +649,21 @@ impl LanguageModel for OpenCodeLanguageModel {
591649
.boxed()
592650
}
593651
ApiProtocol::OpenAiChat => {
652+
let reasoning_effort = if request.thinking_allowed {
653+
request
654+
.thinking_effort
655+
.as_deref()
656+
.and_then(normalize_reasoning_effort)
657+
} else {
658+
None
659+
};
594660
let openai_request = into_open_ai(
595661
request,
596662
self.model.id(),
597663
false,
598664
false,
599665
self.model.max_output_tokens(),
600-
None,
666+
reasoning_effort,
601667
false,
602668
);
603669
let stream = self.stream_openai_chat(openai_request, http_client, cx);
@@ -608,13 +674,21 @@ impl LanguageModel for OpenCodeLanguageModel {
608674
.boxed()
609675
}
610676
ApiProtocol::OpenAiResponses => {
677+
let reasoning_effort = if request.thinking_allowed {
678+
request
679+
.thinking_effort
680+
.as_deref()
681+
.and_then(normalize_reasoning_effort)
682+
} else {
683+
None
684+
};
611685
let response_request = into_open_ai_response(
612686
request,
613687
self.model.id(),
614688
false,
615689
false,
616690
self.model.max_output_tokens(),
617-
None,
691+
reasoning_effort,
618692
);
619693
let stream = self.stream_openai_response(response_request, http_client, cx);
620694
async move {

‎crates/opencode/Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ anyhow.workspace = true
2121
futures.workspace = true
2222
google_ai.workspace = true
2323
http_client.workspace = true
24+
language_model_core.workspace = true
2425
schemars = { workspace = true, optional = true }
2526
serde.workspace = true
2627
serde_json.workspace = true

0 commit comments

Comments
 (0)