mirror of
https://github.com/zed-industries/zed.git
synced 2026-11-21 16:10:19 +01:00
d0f52e90e6
<img width="624" alt="image" src="https://github.com/user-attachments/assets/f492b0bd-14c3-49e2-b2ff-dc78e52b0815"> - [x] Correctly set custom model token count - [x] How to count tokens for Gemini models? - [x] Feature flag zed.dev provider - [x] Figure out how to configure custom models - [ ] Update docs Release Notes: - Added support for quickly switching between multiple language model providers in the assistant panel --------- Co-authored-by: Antonio <antonio@zed.dev>
85 lines
2.3 KiB
Rust
85 lines
2.3 KiB
Rust
mod model;
|
|
pub mod provider;
|
|
mod registry;
|
|
mod request;
|
|
mod role;
|
|
pub mod settings;
|
|
|
|
use std::sync::Arc;
|
|
|
|
use anyhow::Result;
|
|
use client::Client;
|
|
use futures::{future::BoxFuture, stream::BoxStream};
|
|
use gpui::{AnyView, AppContext, AsyncAppContext, SharedString, Task, WindowContext};
|
|
|
|
pub use model::*;
|
|
pub use registry::*;
|
|
pub use request::*;
|
|
pub use role::*;
|
|
|
|
pub fn init(client: Arc<Client>, cx: &mut AppContext) {
|
|
settings::init(cx);
|
|
registry::init(client, cx);
|
|
}
|
|
|
|
pub trait LanguageModel: Send + Sync {
|
|
fn id(&self) -> LanguageModelId;
|
|
fn name(&self) -> LanguageModelName;
|
|
fn provider_name(&self) -> LanguageModelProviderName;
|
|
fn telemetry_id(&self) -> String;
|
|
|
|
fn max_token_count(&self) -> usize;
|
|
|
|
fn count_tokens(
|
|
&self,
|
|
request: LanguageModelRequest,
|
|
cx: &AppContext,
|
|
) -> BoxFuture<'static, Result<usize>>;
|
|
|
|
fn stream_completion(
|
|
&self,
|
|
request: LanguageModelRequest,
|
|
cx: &AsyncAppContext,
|
|
) -> BoxFuture<'static, Result<BoxStream<'static, Result<String>>>>;
|
|
}
|
|
|
|
pub trait LanguageModelProvider: 'static {
|
|
fn name(&self) -> LanguageModelProviderName;
|
|
fn provided_models(&self, cx: &AppContext) -> Vec<Arc<dyn LanguageModel>>;
|
|
fn is_authenticated(&self, cx: &AppContext) -> bool;
|
|
fn authenticate(&self, cx: &AppContext) -> Task<Result<()>>;
|
|
fn authentication_prompt(&self, cx: &mut WindowContext) -> AnyView;
|
|
fn reset_credentials(&self, cx: &AppContext) -> Task<Result<()>>;
|
|
}
|
|
|
|
pub trait LanguageModelProviderState: 'static {
|
|
fn subscribe<T: 'static>(&self, cx: &mut gpui::ModelContext<T>) -> Option<gpui::Subscription>;
|
|
}
|
|
|
|
#[derive(Clone, Eq, PartialEq, Hash, Debug)]
|
|
pub struct LanguageModelId(pub SharedString);
|
|
|
|
#[derive(Clone, Eq, PartialEq, Hash, Debug)]
|
|
pub struct LanguageModelName(pub SharedString);
|
|
|
|
#[derive(Clone, Eq, PartialEq, Hash, Debug)]
|
|
pub struct LanguageModelProviderName(pub SharedString);
|
|
|
|
impl From<String> for LanguageModelId {
|
|
fn from(value: String) -> Self {
|
|
Self(SharedString::from(value))
|
|
}
|
|
}
|
|
|
|
impl From<String> for LanguageModelName {
|
|
fn from(value: String) -> Self {
|
|
Self(SharedString::from(value))
|
|
}
|
|
}
|
|
|
|
impl From<String> for LanguageModelProviderName {
|
|
fn from(value: String) -> Self {
|
|
Self(SharedString::from(value))
|
|
}
|
|
}
|