2023-07-27 13:27:34 +08:00
|
|
|
'use client'
|
|
|
|
import type { FC } from 'react'
|
|
|
|
import React from 'react'
|
|
|
|
import { useTranslation } from 'react-i18next'
|
2024-01-02 23:42:00 +08:00
|
|
|
import ModelSelector from '@/app/components/header/account-setting/model-provider-page/model-selector'
|
|
|
|
import { useProviderContext } from '@/context/provider-context'
|
|
|
|
|
2023-07-27 13:27:34 +08:00
|
|
|
export type IModelConfigProps = {
|
|
|
|
modelId: string
|
2024-01-02 23:42:00 +08:00
|
|
|
providerName: string
|
|
|
|
onChange?: (modelId: string, providerName: string) => void
|
2023-07-27 13:27:34 +08:00
|
|
|
readonly?: boolean
|
|
|
|
}
|
|
|
|
|
|
|
|
const ModelConfig: FC<IModelConfigProps> = ({
|
|
|
|
modelId,
|
2023-08-12 00:57:13 +08:00
|
|
|
providerName,
|
2023-07-27 13:27:34 +08:00
|
|
|
onChange,
|
|
|
|
readonly,
|
|
|
|
}) => {
|
|
|
|
const { t } = useTranslation()
|
2024-01-02 23:42:00 +08:00
|
|
|
const { agentThoughtModelList } = useProviderContext()
|
2023-07-27 13:27:34 +08:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className='flex items-center justify-between h-[52px] px-3 rounded-xl bg-gray-50'>
|
|
|
|
<div className='text-sm font-semibold text-gray-800'>{t('explore.universalChat.model')}</div>
|
2023-08-12 00:57:13 +08:00
|
|
|
<ModelSelector
|
2024-01-02 23:42:00 +08:00
|
|
|
triggerClassName={`${readonly && '!cursor-not-allowed !opacity-60'}`}
|
|
|
|
defaultModel={{ provider: providerName, model: modelId }}
|
|
|
|
modelList={agentThoughtModelList}
|
|
|
|
onSelect={(model) => {
|
|
|
|
onChange?.(model.model, model.provider)
|
2023-08-12 00:57:13 +08:00
|
|
|
}}
|
|
|
|
readonly={readonly}
|
|
|
|
/>
|
2023-07-27 13:27:34 +08:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
export default React.memo(ModelConfig)
|