assistant: Overhaul provider infrastructure (#14929)
<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>
This commit is contained in:
co-authored by
Antonio
parent
17ef9a367f
commit
d0f52e90e6
@@ -29,6 +29,11 @@ impl FeatureFlag for Remoting {
|
||||
const NAME: &'static str = "remoting";
|
||||
}
|
||||
|
||||
pub struct LanguageModels {}
|
||||
impl FeatureFlag for LanguageModels {
|
||||
const NAME: &'static str = "language-models";
|
||||
}
|
||||
|
||||
pub struct TerminalInlineAssist {}
|
||||
impl FeatureFlag for TerminalInlineAssist {
|
||||
const NAME: &'static str = "terminal-inline-assist";
|
||||
@@ -65,6 +70,10 @@ pub trait FeatureFlagAppExt {
|
||||
fn set_staff(&mut self, staff: bool);
|
||||
fn has_flag<T: FeatureFlag>(&self) -> bool;
|
||||
fn is_staff(&self) -> bool;
|
||||
|
||||
fn observe_flag<T: FeatureFlag, F>(&mut self, callback: F) -> Subscription
|
||||
where
|
||||
F: Fn(bool, &mut AppContext) + 'static;
|
||||
}
|
||||
|
||||
impl FeatureFlagAppExt for AppContext {
|
||||
@@ -90,4 +99,14 @@ impl FeatureFlagAppExt for AppContext {
|
||||
.map(|flags| flags.staff)
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
fn observe_flag<T: FeatureFlag, F>(&mut self, callback: F) -> Subscription
|
||||
where
|
||||
F: Fn(bool, &mut AppContext) + 'static,
|
||||
{
|
||||
self.observe_global::<FeatureFlags>(move |cx| {
|
||||
let feature_flags = cx.global::<FeatureFlags>();
|
||||
callback(feature_flags.has_flag(<T as FeatureFlag>::NAME), cx);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user