Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions web-app/src/containers/dialogs/AddModel.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {

Check warning on line 1 in web-app/src/containers/dialogs/AddModel.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

1 line is not covered with tests
Dialog,
DialogContent,
DialogDescription,
Expand All @@ -7,71 +7,77 @@
DialogTrigger,
DialogFooter,
} from '@/components/ui/dialog'
import { Button } from '@/components/ui/button'
import { useModelProvider } from '@/hooks/useModelProvider'
import { useProviderModels } from '@/hooks/useProviderModels'
import { ModelCombobox } from '@/containers/ModelCombobox'
import { IconPlus } from '@tabler/icons-react'
import { useState } from 'react'
import { getProviderTitle } from '@/lib/utils'
import { useTranslation } from '@/i18n/react-i18next-compat'
import { ModelCapabilities } from '@/types/models'
import { models as providerModels } from 'token.js'
import { toast } from 'sonner'

Check warning on line 20 in web-app/src/containers/dialogs/AddModel.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

10-20 lines are not covered with tests

type DialogAddModelProps = {
provider: ModelProvider
trigger?: React.ReactNode
}

export const DialogAddModel = ({ provider, trigger }: DialogAddModelProps) => {
const { t } = useTranslation()
const { updateProvider } = useModelProvider()
const [modelId, setModelId] = useState<string>('')
const [open, setOpen] = useState(false)
const [isComboboxOpen, setIsComboboxOpen] = useState(false)

Check warning on line 32 in web-app/src/containers/dialogs/AddModel.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

27-32 lines are not covered with tests

// Fetch models from provider API (API key is optional)
const { models, loading, error, refetch } = useProviderModels(
provider.base_url ? provider : undefined
)

Check warning on line 37 in web-app/src/containers/dialogs/AddModel.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

35-37 lines are not covered with tests

// Handle form submission
const handleSubmit = () => {
if (!modelId.trim()) {
return // Don't submit if model ID is empty
if (!modelId.trim()) return // Don't submit if model ID is empty

Check warning on line 41 in web-app/src/containers/dialogs/AddModel.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

40-41 lines are not covered with tests

if (provider.models.some((e) => e.id === modelId)) {
toast.error(t('providers:addModel.modelExists'), {
description: t('providers:addModel.modelExistsDesc'),
})
return // Don't submit if model ID already exists
}

Check warning on line 48 in web-app/src/containers/dialogs/AddModel.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

43-48 lines are not covered with tests

// Create the new model
const newModel = {
id: modelId,
model: modelId,
name: modelId,
capabilities: [
ModelCapabilities.COMPLETION,

Check warning on line 56 in web-app/src/containers/dialogs/AddModel.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

51-56 lines are not covered with tests
(
providerModels[
provider.provider as unknown as keyof typeof providerModels
]?.supportsToolCalls as unknown as string[]
)?.includes(modelId)
? ModelCapabilities.TOOLS
: undefined,

Check warning on line 63 in web-app/src/containers/dialogs/AddModel.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

58-63 lines are not covered with tests
(
providerModels[
provider.provider as unknown as keyof typeof providerModels
]?.supportsImages as unknown as string[]
)?.includes(modelId)
? ModelCapabilities.VISION
: undefined,
].filter(Boolean) as string[],
version: '1.0',
}

Check warning on line 73 in web-app/src/containers/dialogs/AddModel.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

65-73 lines are not covered with tests

// Update the provider with the new model
const updatedModels = [...provider.models, newModel]
updateProvider(provider.provider, {
...provider,
models: updatedModels,
})

Check warning on line 80 in web-app/src/containers/dialogs/AddModel.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

76-80 lines are not covered with tests

// Reset form and close dialog
setModelId('')
Expand Down
4 changes: 3 additions & 1 deletion web-app/src/locales/de-DE/providers.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
"modelId": "Modell ID",
"enterModelId": "Modell ID eingeben",
"exploreModels": "Sehe Modellliste von {{provider}}",
"addModel": "Modell hinzufügen"
"addModel": "Modell hinzufügen",
"modelExists": "Modell bereits vorhanden",
"modelExistsDesc": "Bitte wähle eine andere Modell-ID."
},
"deleteModel": {
"title": "Lösche Modell: {{modelId}}",
Expand Down
6 changes: 4 additions & 2 deletions web-app/src/locales/en/providers.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
"modelId": "Model ID",
"enterModelId": "Enter model ID",
"exploreModels": "See model list from {{provider}}",
"addModel": "Add Model"
"addModel": "Add Model",
"modelExists": "Model already exists",
"modelExistsDesc": "Please choose a different model ID."
},
"deleteModel": {
"title": "Delete Model: {{modelId}}",
Expand Down Expand Up @@ -69,4 +71,4 @@
"addProvider": "Add Provider",
"addOpenAIProvider": "Add OpenAI Provider",
"enterNameForProvider": "Enter name for provider"
}
}
6 changes: 4 additions & 2 deletions web-app/src/locales/id/providers.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
"modelId": "ID Model",
"enterModelId": "Masukkan ID model",
"exploreModels": "Lihat daftar model dari {{provider}}",
"addModel": "Tambah Model"
"addModel": "Tambah Model",
"modelExists": "Model sudah ada",
"modelExistsDesc": "Silakan pilih ID model yang berbeda."
},
"deleteModel": {
"title": "Hapus Model: {{modelId}}",
Expand Down Expand Up @@ -69,4 +71,4 @@
"addProvider": "Tambah Penyedia",
"addOpenAIProvider": "Tambah Penyedia OpenAI",
"enterNameForProvider": "Masukkan nama untuk penyedia"
}
}
4 changes: 3 additions & 1 deletion web-app/src/locales/pl/providers.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
"modelId": "Identyfikator Modelu",
"enterModelId": "Wprowadź identyfikator modelu",
"exploreModels": "Zobacz listę modeli dostawcy {{provider}}",
"addModel": "Dodaj Model"
"addModel": "Dodaj Model",
"modelExists": "Model już istnieje",
"modelExistsDesc": "Wybierz inny identyfikator modelu."
},
"deleteModel": {
"title": "Usuń Model: {{modelId}}",
Expand Down
6 changes: 4 additions & 2 deletions web-app/src/locales/vn/providers.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
"modelId": "ID mô hình",
"enterModelId": "Nhập ID mô hình",
"exploreModels": "Xem danh sách mô hình từ {{provider}}",
"addModel": "Thêm mô hình"
"addModel": "Thêm mô hình",
"modelExists": "Mô hình đã tồn tại",
"modelExistsDesc": "Vui lòng chọn một ID mô hình khác."
},
"deleteModel": {
"title": "Xóa mô hình: {{modelId}}",
Expand Down Expand Up @@ -69,4 +71,4 @@
"addProvider": "Thêm nhà cung cấp",
"addOpenAIProvider": "Thêm nhà cung cấp OpenAI",
"enterNameForProvider": "Nhập tên cho nhà cung cấp"
}
}
6 changes: 4 additions & 2 deletions web-app/src/locales/zh-CN/providers.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
"modelId": "模型 ID",
"enterModelId": "输入模型 ID",
"exploreModels": "查看 {{provider}} 的模型列表",
"addModel": "添加模型"
"addModel": "添加模型",
"modelExists": "模型已存在",
"modelExistsDesc": "请选择不同的模型 ID。"
},
"deleteModel": {
"title": "删除模型:{{modelId}}",
Expand Down Expand Up @@ -69,4 +71,4 @@
"addProvider": "添加提供商",
"addOpenAIProvider": "添加 OpenAI 提供商",
"enterNameForProvider": "输入提供商名称"
}
}
6 changes: 4 additions & 2 deletions web-app/src/locales/zh-TW/providers.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
"modelId": "模型 ID",
"enterModelId": "輸入模型 ID",
"exploreModels": "查看 {{provider}} 的模型清單",
"addModel": "新增模型"
"addModel": "新增模型",
"modelExists": "模型已存在",
"modelExistsDesc": "請選擇不同的模型 ID。"
},
"deleteModel": {
"title": "刪除模型:{{modelId}}",
Expand Down Expand Up @@ -69,4 +71,4 @@
"addProvider": "新增提供者",
"addOpenAIProvider": "新增 OpenAI 提供者",
"enterNameForProvider": "輸入提供者名稱"
}
}
Loading