Merge 62b69ffdca
into bd4e943597
This commit is contained in:
commit
76c84f07e3
15 changed files with 2862 additions and 16 deletions
|
@ -1,7 +1,7 @@
|
|||
use anyhow::{Result, anyhow};
|
||||
use futures::{FutureExt, StreamExt, future::BoxFuture, stream::BoxStream};
|
||||
use futures::{Stream, TryFutureExt, stream};
|
||||
use gpui::{AnyView, App, AsyncApp, Context, Subscription, Task};
|
||||
use gpui::{AnyView, App, AsyncApp, Context, Entity, Global, Subscription, Task};
|
||||
use http_client::HttpClient;
|
||||
use language_model::{
|
||||
AuthenticateError, LanguageModel, LanguageModelCompletionError, LanguageModelCompletionEvent,
|
||||
|
@ -81,7 +81,7 @@ impl State {
|
|||
|
||||
// As a proxy for the server being "authenticated", we'll check if its up by fetching the models
|
||||
cx.spawn(async move |this, cx| {
|
||||
let models = get_models(http_client.as_ref(), &api_url, None).await?;
|
||||
let models = get_models(http_client.as_ref(), &api_url, None, None).await?;
|
||||
|
||||
let tasks = models
|
||||
.into_iter()
|
||||
|
@ -94,7 +94,8 @@ impl State {
|
|||
let api_url = api_url.clone();
|
||||
async move {
|
||||
let name = model.name.as_str();
|
||||
let capabilities = show_model(http_client.as_ref(), &api_url, name).await?;
|
||||
let capabilities =
|
||||
show_model(http_client.as_ref(), &api_url, None, name).await?;
|
||||
let ollama_model = ollama::Model::new(
|
||||
name,
|
||||
None,
|
||||
|
@ -141,6 +142,29 @@ impl State {
|
|||
}
|
||||
|
||||
impl OllamaLanguageModelProvider {
|
||||
pub fn global(cx: &App) -> Option<Entity<Self>> {
|
||||
cx.try_global::<GlobalOllamaLanguageModelProvider>()
|
||||
.map(|provider| provider.0.clone())
|
||||
}
|
||||
|
||||
pub fn set_global(provider: Entity<Self>, cx: &mut App) {
|
||||
cx.set_global(GlobalOllamaLanguageModelProvider(provider));
|
||||
}
|
||||
|
||||
pub fn available_models_for_completion(&self, cx: &App) -> Vec<ollama::Model> {
|
||||
self.state.read(cx).available_models.clone()
|
||||
}
|
||||
|
||||
pub fn http_client(&self) -> Arc<dyn HttpClient> {
|
||||
self.http_client.clone()
|
||||
}
|
||||
|
||||
pub fn refresh_models(&self, cx: &mut App) {
|
||||
self.state.update(cx, |state, cx| {
|
||||
state.restart_fetch_models_task(cx);
|
||||
});
|
||||
}
|
||||
|
||||
pub fn new(http_client: Arc<dyn HttpClient>, cx: &mut App) -> Self {
|
||||
let this = Self {
|
||||
http_client: http_client.clone(),
|
||||
|
@ -676,6 +700,10 @@ impl Render for ConfigurationView {
|
|||
}
|
||||
}
|
||||
|
||||
struct GlobalOllamaLanguageModelProvider(Entity<OllamaLanguageModelProvider>);
|
||||
|
||||
impl Global for GlobalOllamaLanguageModelProvider {}
|
||||
|
||||
fn tool_into_ollama(tool: LanguageModelRequestTool) -> ollama::OllamaTool {
|
||||
ollama::OllamaTool::Function {
|
||||
function: OllamaFunctionTool {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue