mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-17 09:05:55 +08:00
Feat/model providers (#951)
This commit is contained in:
parent
9d5299e9ec
commit
b3c2bf125f
@ -1,6 +1,7 @@
|
|||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import useSWR from 'swr'
|
import useSWR from 'swr'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { useContext } from 'use-context-selector'
|
||||||
import type {
|
import type {
|
||||||
BackendModel,
|
BackendModel,
|
||||||
FormValue,
|
FormValue,
|
||||||
@ -30,23 +31,13 @@ import { ModelType } from '@/app/components/header/account-setting/model-page/de
|
|||||||
import { useEventEmitterContextContext } from '@/context/event-emitter'
|
import { useEventEmitterContextContext } from '@/context/event-emitter'
|
||||||
import { useProviderContext } from '@/context/provider-context'
|
import { useProviderContext } from '@/context/provider-context'
|
||||||
import Tooltip from '@/app/components/base/tooltip'
|
import Tooltip from '@/app/components/base/tooltip'
|
||||||
|
import I18n from '@/context/i18n'
|
||||||
|
|
||||||
const MODEL_CARD_LIST = [
|
const MODEL_CARD_LIST = [
|
||||||
config.openai,
|
config.openai,
|
||||||
config.anthropic,
|
config.anthropic,
|
||||||
]
|
]
|
||||||
|
|
||||||
const MODEL_LIST = [
|
|
||||||
config.azure_openai,
|
|
||||||
config.replicate,
|
|
||||||
config.huggingface_hub,
|
|
||||||
config.minimax,
|
|
||||||
config.spark,
|
|
||||||
config.tongyi,
|
|
||||||
config.wenxin,
|
|
||||||
config.chatglm,
|
|
||||||
]
|
|
||||||
|
|
||||||
const titleClassName = `
|
const titleClassName = `
|
||||||
flex items-center h-9 text-sm font-medium text-gray-900
|
flex items-center h-9 text-sm font-medium text-gray-900
|
||||||
`
|
`
|
||||||
@ -61,6 +52,7 @@ type DeleteModel = {
|
|||||||
|
|
||||||
const ModelPage = () => {
|
const ModelPage = () => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
const { locale } = useContext(I18n)
|
||||||
const {
|
const {
|
||||||
updateModelList,
|
updateModelList,
|
||||||
embeddingsDefaultModel,
|
embeddingsDefaultModel,
|
||||||
@ -79,6 +71,33 @@ const ModelPage = () => {
|
|||||||
const [deleteModel, setDeleteModel] = useState<DeleteModel & { providerKey: ProviderEnum }>()
|
const [deleteModel, setDeleteModel] = useState<DeleteModel & { providerKey: ProviderEnum }>()
|
||||||
const [modalMode, setModalMode] = useState('add')
|
const [modalMode, setModalMode] = useState('add')
|
||||||
|
|
||||||
|
let modelList = []
|
||||||
|
|
||||||
|
if (locale === 'en') {
|
||||||
|
modelList = [
|
||||||
|
config.azure_openai,
|
||||||
|
config.replicate,
|
||||||
|
config.huggingface_hub,
|
||||||
|
config.minimax,
|
||||||
|
config.spark,
|
||||||
|
config.tongyi,
|
||||||
|
config.wenxin,
|
||||||
|
config.chatglm,
|
||||||
|
]
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
modelList = [
|
||||||
|
config.huggingface_hub,
|
||||||
|
config.minimax,
|
||||||
|
config.spark,
|
||||||
|
config.azure_openai,
|
||||||
|
config.replicate,
|
||||||
|
config.tongyi,
|
||||||
|
config.wenxin,
|
||||||
|
config.chatglm,
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
const handleOpenModal = (newModelModalConfig: ProviderConfigModal | undefined, editValue?: FormValue) => {
|
const handleOpenModal = (newModelModalConfig: ProviderConfigModal | undefined, editValue?: FormValue) => {
|
||||||
if (newModelModalConfig) {
|
if (newModelModalConfig) {
|
||||||
setShowModal(true)
|
setShowModal(true)
|
||||||
@ -284,7 +303,7 @@ const ModelPage = () => {
|
|||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
{
|
{
|
||||||
MODEL_LIST.slice(0, showMoreModel ? MODEL_LIST.length : 3).map((model, index) => (
|
modelList.slice(0, showMoreModel ? modelList.length : 3).map((model, index) => (
|
||||||
<ModelItem
|
<ModelItem
|
||||||
key={index}
|
key={index}
|
||||||
modelItem={model.item}
|
modelItem={model.item}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import type { FC } from 'react'
|
import type { FC } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { formatNumber } from '@/utils/format'
|
||||||
|
|
||||||
type QuotaCardProps = {
|
type QuotaCardProps = {
|
||||||
remainTokens: number
|
remainTokens: number
|
||||||
@ -17,7 +18,7 @@ const QuotaCard: FC<QuotaCardProps> = ({
|
|||||||
{t('common.modelProvider.item.freeQuota')}
|
{t('common.modelProvider.item.freeQuota')}
|
||||||
</div>
|
</div>
|
||||||
<div className='flex items-center h-5 text-sm font-medium text-gray-700'>
|
<div className='flex items-center h-5 text-sm font-medium text-gray-700'>
|
||||||
{remainTokens}
|
{formatNumber(remainTokens)}
|
||||||
<div className='ml-1 font-normal'>Tokens</div>
|
<div className='ml-1 font-normal'>Tokens</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user