Send up Zed version with edit prediction and completion requests (#30136)

This PR makes it so we send up an `x-zed-version` header with the
client's version when making a request to llm.zed.dev for edit
predictions and completions.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2025-05-07 11:44:30 -04:00 committed by GitHub
parent 5ca114be24
commit a34fb6f6b1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 26 additions and 9 deletions

View file

@ -41,6 +41,7 @@ open_ai = { workspace = true, features = ["schemars"] }
partial-json-fixer.workspace = true
project.workspace = true
proto.workspace = true
release_channel.workspace = true
schemars.workspace = true
serde.workspace = true
serde_json.workspace = true

View file

@ -6,7 +6,9 @@ use feature_flags::{FeatureFlagAppExt, LlmClosedBetaFeatureFlag, ZedProFeatureFl
use futures::{
AsyncBufReadExt, FutureExt, Stream, StreamExt, future::BoxFuture, stream::BoxStream,
};
use gpui::{AnyElement, AnyView, App, AsyncApp, Context, Entity, Subscription, Task};
use gpui::{
AnyElement, AnyView, App, AsyncApp, Context, Entity, SemanticVersion, Subscription, Task,
};
use http_client::{AsyncBody, HttpClient, Method, Response, StatusCode};
use language_model::{
AuthenticateError, CloudModel, LanguageModel, LanguageModelCacheConfiguration,
@ -20,6 +22,7 @@ use language_model::{
MaxMonthlySpendReachedError, PaymentRequiredError, RefreshLlmTokenListener,
};
use proto::Plan;
use release_channel::AppVersion;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize, de::DeserializeOwned};
use settings::{Settings, SettingsStore};
@ -39,7 +42,7 @@ use zed_llm_client::{
CompletionRequestStatus, CountTokensBody, CountTokensResponse, EXPIRED_LLM_TOKEN_HEADER_NAME,
MAX_LLM_MONTHLY_SPEND_REACHED_HEADER_NAME, MODEL_REQUESTS_RESOURCE_HEADER_VALUE,
SERVER_SUPPORTS_STATUS_MESSAGES_HEADER_NAME, SUBSCRIPTION_LIMIT_RESOURCE_HEADER_NAME,
TOOL_USE_LIMIT_REACHED_HEADER_NAME,
TOOL_USE_LIMIT_REACHED_HEADER_NAME, ZED_VERSION_HEADER_NAME,
};
use crate::AllLanguageModelSettings;
@ -526,6 +529,7 @@ impl CloudLanguageModel {
async fn perform_llm_completion(
client: Arc<Client>,
llm_api_token: LlmApiToken,
app_version: Option<SemanticVersion>,
body: CompletionBody,
) -> Result<PerformLlmCompletionResponse> {
let http_client = &client.http_client();
@ -542,6 +546,12 @@ impl CloudLanguageModel {
} else {
request_builder.uri(http_client.build_zed_llm_url("/completions", &[])?.as_ref())
};
let request_builder = if let Some(app_version) = app_version {
request_builder.header(ZED_VERSION_HEADER_NAME, app_version.to_string())
} else {
request_builder
};
let request = request_builder
.header("Content-Type", "application/json")
.header("Authorization", format!("Bearer {token}"))
@ -774,7 +784,7 @@ impl LanguageModel for CloudLanguageModel {
fn stream_completion(
&self,
request: LanguageModelRequest,
_cx: &AsyncApp,
cx: &AsyncApp,
) -> BoxFuture<
'static,
Result<
@ -784,6 +794,7 @@ impl LanguageModel for CloudLanguageModel {
let thread_id = request.thread_id.clone();
let prompt_id = request.prompt_id.clone();
let mode = request.mode;
let app_version = cx.update(|cx| AppVersion::global(cx)).ok();
match &self.model {
CloudModel::Anthropic(model) => {
let request = into_anthropic(
@ -804,6 +815,7 @@ impl LanguageModel for CloudLanguageModel {
} = Self::perform_llm_completion(
client.clone(),
llm_api_token,
app_version,
CompletionBody {
thread_id,
prompt_id,
@ -855,6 +867,7 @@ impl LanguageModel for CloudLanguageModel {
} = Self::perform_llm_completion(
client.clone(),
llm_api_token,
app_version,
CompletionBody {
thread_id,
prompt_id,
@ -891,6 +904,7 @@ impl LanguageModel for CloudLanguageModel {
} = Self::perform_llm_completion(
client.clone(),
llm_api_token,
app_version,
CompletionBody {
thread_id,
prompt_id,