From d5d020ef726799a11ac94fc403528e5d4ff635e2 Mon Sep 17 00:00:00 2001 From: HugoCasa Date: Thu, 27 Mar 2025 18:26:04 +0100 Subject: [PATCH] feat: make custom ai CE + add together AI provider (#5522) * feat: make custom ai CE + add together AI provider * fix build --- backend/windmill-api/openapi.yaml | 2 +- backend/windmill-api/src/ai.rs | 3 +++ backend/windmill-api/src/workspaces.rs | 12 ----------- .../copilot/chat/AIChatDisplay.svelte | 8 ++++--- frontend/src/lib/components/copilot/lib.ts | 21 ++++++++++++------- .../user/(user)/create_workspace/+page.svelte | 1 + .../(logged)/workspace_settings/+page.svelte | 5 ++--- 7 files changed, 26 insertions(+), 26 deletions(-) diff --git a/backend/windmill-api/openapi.yaml b/backend/windmill-api/openapi.yaml index c89d759c41..c96155a91b 100644 --- a/backend/windmill-api/openapi.yaml +++ b/backend/windmill-api/openapi.yaml @@ -12497,7 +12497,7 @@ components: AIProvider: type: string - enum: [openai, anthropic, mistral, deepseek, googleai, groq, openrouter, customai] + enum: [openai, anthropic, mistral, deepseek, googleai, groq, openrouter, togetherai, customai] AIProviderModel: type: object diff --git a/backend/windmill-api/src/ai.rs b/backend/windmill-api/src/ai.rs index 4ff0f77d57..6c66690774 100644 --- a/backend/windmill-api/src/ai.rs +++ b/backend/windmill-api/src/ai.rs @@ -314,6 +314,7 @@ pub enum AIProvider { GoogleAI, Groq, OpenRouter, + TogetherAI, CustomAI, } @@ -326,6 +327,7 @@ impl AIProvider { )), AIProvider::Groq => Ok(Some("https://api.groq.com/openai/v1".to_string())), AIProvider::OpenRouter => Ok(Some("https://openrouter.ai/api/v1".to_string())), + AIProvider::TogetherAI => Ok(Some("https://api.together.xyz/v1".to_string())), AIProvider::Anthropic => Ok(Some("https://api.anthropic.com/v1".to_string())), AIProvider::Mistral => Ok(Some("https://api.mistral.ai/v1".to_string())), AIProvider::CustomAI => Ok(None), @@ -343,6 +345,7 @@ impl TryFrom<&str> for AIProvider { "mistral" => Ok(AIProvider::Mistral), "groq" => Ok(AIProvider::Groq), "openrouter" => Ok(AIProvider::OpenRouter), + "togetherai" => Ok(AIProvider::TogetherAI), "deepseek" => Ok(AIProvider::DeepSeek), "googleai" => Ok(AIProvider::GoogleAI), "customai" => Ok(AIProvider::CustomAI), diff --git a/backend/windmill-api/src/workspaces.rs b/backend/windmill-api/src/workspaces.rs index f82a3a29c6..abd13601e9 100644 --- a/backend/windmill-api/src/workspaces.rs +++ b/backend/windmill-api/src/workspaces.rs @@ -52,9 +52,6 @@ use windmill_git_sync::handle_deployment_metadata; #[cfg(feature = "enterprise")] use windmill_common::utils::require_admin_or_devops; -#[cfg(not(feature = "enterprise"))] -use crate::ai::AIProvider; - use hyper::StatusCode; use serde::{Deserialize, Serialize}; use sqlx::{FromRow, Postgres, Transaction}; @@ -707,15 +704,6 @@ async fn edit_copilot_config( if let Some(ref providers) = ai_config.providers { for provider in providers.keys() { - #[cfg(not(feature = "enterprise"))] - { - if matches!(provider, &AIProvider::CustomAI) { - return Err(Error::BadRequest( - "Custom AI is only available on EE".to_string(), - )); - } - } - AI_KEY_CACHE.remove(&(w_id.clone(), provider.clone())); } } diff --git a/frontend/src/lib/components/copilot/chat/AIChatDisplay.svelte b/frontend/src/lib/components/copilot/chat/AIChatDisplay.svelte index 34815f91ea..cf3b7d92bd 100644 --- a/frontend/src/lib/components/copilot/chat/AIChatDisplay.svelte +++ b/frontend/src/lib/components/copilot/chat/AIChatDisplay.svelte @@ -246,12 +246,14 @@
- +
- {providerModel.model} + {providerModel.model} {#if $copilotInfo.aiModels.length > 1} - +
+ +
{/if}
diff --git a/frontend/src/lib/components/copilot/lib.ts b/frontend/src/lib/components/copilot/lib.ts index a4f86ef012..e925da87f3 100644 --- a/frontend/src/lib/components/copilot/lib.ts +++ b/frontend/src/lib/components/copilot/lib.ts @@ -35,9 +35,19 @@ export const AI_DEFAULT_MODELS: Record = { googleai: ['gemini-1.5-pro', 'gemini-2.0-flash', 'gemini-1.5-flash'], groq: ['llama-3.3-70b-versatile', 'llama-3.1-8b-instant'], openrouter: ['meta-llama/llama-3.2-3b-instruct:free'], + togetherai: ['meta-llama/Llama-3.3-70B-Instruct-Turbo'], customai: [] } +function getModelMaxTokens(model: string) { + if (model.startsWith('gpt-4o') || model.startsWith('codestral')) { + return 16384 + } else if (model.startsWith('gpt-4-turbo') || model.startsWith('gpt-3.5')) { + return 4096 + } + return 8192 +} + function prepareMessages(aiProvider: AIProvider, messages: ChatCompletionMessageParam[]) { switch (aiProvider) { case 'googleai': @@ -65,18 +75,15 @@ function prepareMessages(aiProvider: AIProvider, messages: ChatCompletionMessage const DEFAULT_COMPLETION_CONFIG: ChatCompletionCreateParams = { model: '', - max_tokens: 8192, //TODO: make this dynamic seed: 42, messages: [] } export const PROVIDER_COMPLETION_CONFIG_MAP: Record = { - openai: { - ...DEFAULT_COMPLETION_CONFIG, - max_tokens: 16384 - }, + openai: DEFAULT_COMPLETION_CONFIG, groq: DEFAULT_COMPLETION_CONFIG, openrouter: DEFAULT_COMPLETION_CONFIG, + togetherai: DEFAULT_COMPLETION_CONFIG, deepseek: DEFAULT_COMPLETION_CONFIG, customai: DEFAULT_COMPLETION_CONFIG, googleai: { @@ -85,8 +92,7 @@ export const PROVIDER_COMPLETION_CONFIG_MAP: Record({ temperature: 0, tools }), + max_tokens: getModelMaxTokens(modelProvider.model), messages: processedMessages, stream } as any diff --git a/frontend/src/routes/(root)/(logged)/user/(user)/create_workspace/+page.svelte b/frontend/src/routes/(root)/(logged)/user/(user)/create_workspace/+page.svelte index e0f61ce544..f186824690 100644 --- a/frontend/src/routes/(root)/(logged)/user/(user)/create_workspace/+page.svelte +++ b/frontend/src/routes/(root)/(logged)/user/(user)/create_workspace/+page.svelte @@ -267,6 +267,7 @@ +
diff --git a/frontend/src/routes/(root)/(logged)/workspace_settings/+page.svelte b/frontend/src/routes/(root)/(logged)/workspace_settings/+page.svelte index 2efc44f6d1..68bc5a6232 100644 --- a/frontend/src/routes/(root)/(logged)/workspace_settings/+page.svelte +++ b/frontend/src/routes/(root)/(logged)/workspace_settings/+page.svelte @@ -126,6 +126,7 @@ ['googleai', 'Google AI'], ['groq', 'Groq'], ['openrouter', 'OpenRouter'], + ['togetherai', 'Together AI'], ['customai', 'Custom AI'] ] @@ -1080,10 +1081,8 @@
{ if (e.detail) {