feat: make custom ai CE + add together AI provider (#5522)
* feat: make custom ai CE + add together AI provider * fix build
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,12 +246,14 @@
|
||||
|
||||
<div class="flex flex-row justify-end items-center gap-2 px-0.5">
|
||||
<div class="min-w-0">
|
||||
<Popover disablePopup={$copilotInfo.aiModels.length <= 1}>
|
||||
<Popover disablePopup={$copilotInfo.aiModels.length <= 1} class="max-w-full">
|
||||
<svelte:fragment slot="trigger">
|
||||
<div class="text-tertiary text-xs flex flex-row items-center gap-0.5 font-normal">
|
||||
{providerModel.model}
|
||||
<span class="truncate">{providerModel.model}</span>
|
||||
{#if $copilotInfo.aiModels.length > 1}
|
||||
<ChevronDown size={16} />
|
||||
<div class="shrink-0">
|
||||
<ChevronDown size={16} />
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</svelte:fragment>
|
||||
|
||||
@@ -35,9 +35,19 @@ export const AI_DEFAULT_MODELS: Record<AIProvider, string[]> = {
|
||||
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<AIProvider, ChatCompletionCreateParams> = {
|
||||
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<AIProvider, ChatCompletionCr
|
||||
} as ChatCompletionCreateParams,
|
||||
mistral: {
|
||||
...DEFAULT_COMPLETION_CONFIG,
|
||||
seed: undefined,
|
||||
max_tokens: 32000
|
||||
seed: undefined
|
||||
},
|
||||
anthropic: DEFAULT_COMPLETION_CONFIG
|
||||
} as const
|
||||
@@ -379,6 +385,7 @@ function getProviderAndCompletionConfig<K extends boolean>({
|
||||
temperature: 0,
|
||||
tools
|
||||
}),
|
||||
max_tokens: getModelMaxTokens(modelProvider.model),
|
||||
messages: processedMessages,
|
||||
stream
|
||||
} as any
|
||||
|
||||
@@ -267,6 +267,7 @@
|
||||
<ToggleButton value="deepseek" label="DeepSeek" {item} />
|
||||
<ToggleButton value="groq" label="Groq" {item} />
|
||||
<ToggleButton value="openrouter" label="OpenRouter" {item} />
|
||||
<ToggleButton value="togetherai" label="Together AI" {item} />
|
||||
</ToggleButtonGroup>
|
||||
</div>
|
||||
</label>
|
||||
|
||||
@@ -126,6 +126,7 @@
|
||||
['googleai', 'Google AI'],
|
||||
['groq', 'Groq'],
|
||||
['openrouter', 'OpenRouter'],
|
||||
['togetherai', 'Together AI'],
|
||||
['customai', 'Custom AI']
|
||||
]
|
||||
|
||||
@@ -1080,10 +1081,8 @@
|
||||
<div class="flex flex-col gap-2">
|
||||
<Toggle
|
||||
options={{
|
||||
right:
|
||||
label + (provider === 'customai' && !$enterpriseLicense ? ' (EE only)' : '')
|
||||
right: label
|
||||
}}
|
||||
disabled={provider === 'customai' && !$enterpriseLicense}
|
||||
checked={!!aiProviders[provider]}
|
||||
on:change={(e) => {
|
||||
if (e.detail) {
|
||||
|
||||
Reference in New Issue
Block a user