Feat/add xinference openllm provider (#958)

This commit is contained in:
zxhlyh
2023-08-22 18:19:10 +08:00
committed by GitHub
parent 5cba2e7087
commit 215a27fd95
21 changed files with 1119 additions and 3 deletions

View File

@@ -8,6 +8,8 @@ import tongyi from './tongyi'
import spark from './spark'
import minimax from './minimax'
import chatglm from './chatglm'
import xinference from './xinference'
import openllm from './openllm'
export default {
openai,
@@ -20,4 +22,6 @@ export default {
spark,
minimax,
chatglm,
xinference,
openllm,
}

View File

@@ -0,0 +1,89 @@
import { ProviderEnum } from '../declarations'
import type { ProviderConfig } from '../declarations'
import { Openllm, OpenllmText } from '@/app/components/base/icons/src/public/llm'
const config: ProviderConfig = {
selector: {
name: {
'en': 'OpenLLM',
'zh-Hans': 'OpenLLM',
},
icon: <Openllm className='w-full h-full' />,
},
item: {
key: ProviderEnum.openllm,
titleIcon: {
'en': <OpenllmText className='h-6' />,
'zh-Hans': <OpenllmText className='h-6' />,
},
disable: {
tip: {
'en': 'Only supports the ',
'zh-Hans': '仅支持',
},
link: {
href: {
'en': 'https://docs.dify.ai/getting-started/install-self-hosted',
'zh-Hans': 'https://docs.dify.ai/v/zh-hans/getting-started/install-self-hosted',
},
label: {
'en': 'community open-source version',
'zh-Hans': '社区开源版本',
},
},
},
},
modal: {
key: ProviderEnum.openllm,
title: {
'en': 'OpenLLM',
'zh-Hans': 'OpenLLM',
},
icon: <Openllm className='h-6' />,
link: {
href: 'https://github.com/bentoml/OpenLLM',
label: {
'en': 'How to deploy OpenLLM',
'zh-Hans': '如何部署 OpenLLM',
},
},
defaultValue: {
model_type: 'text-generation',
},
validateKeys: [
'model_type',
'model_name',
'server_url',
],
fields: [
{
type: 'text',
key: 'model_name',
required: true,
label: {
'en': 'Model Name',
'zh-Hans': '模型名称',
},
placeholder: {
'en': 'Enter your Model Name here',
'zh-Hans': '在此输入您的模型名称',
},
},
{
type: 'text',
key: 'server_url',
required: true,
label: {
'en': 'Server url',
'zh-Hans': 'Server url',
},
placeholder: {
'en': 'Enter your Server Url, eg: https://example.com/xxx',
'zh-Hans': '在此输入您的 Server Urlhttps://example.com/xxx',
},
},
],
},
}
export default config

View File

@@ -0,0 +1,128 @@
import { ProviderEnum } from '../declarations'
import type { ProviderConfig } from '../declarations'
import { XorbitsInference, XorbitsInferenceText } from '@/app/components/base/icons/src/public/llm'
const config: ProviderConfig = {
selector: {
name: {
'en': 'Xinference',
'zh-Hans': 'Xinference',
},
icon: <XorbitsInference className='w-full h-full' />,
},
item: {
key: ProviderEnum.xinference,
titleIcon: {
'en': <XorbitsInferenceText className='h-6' />,
'zh-Hans': <XorbitsInferenceText className='h-6' />,
},
disable: {
tip: {
'en': 'Only supports the ',
'zh-Hans': '仅支持',
},
link: {
href: {
'en': 'https://docs.dify.ai/getting-started/install-self-hosted',
'zh-Hans': 'https://docs.dify.ai/v/zh-hans/getting-started/install-self-hosted',
},
label: {
'en': 'community open-source version',
'zh-Hans': '社区开源版本',
},
},
},
},
modal: {
key: ProviderEnum.xinference,
title: {
'en': 'Xinference',
'zh-Hans': 'Xinference',
},
icon: <XorbitsInference className='h-6' />,
link: {
href: 'https://github.com/xorbitsai/inference',
label: {
'en': 'How to deploy Xinference',
'zh-Hans': '如何部署 Xinference',
},
},
defaultValue: {
model_type: 'text-generation',
},
validateKeys: [
'model_type',
'model_name',
'server_url',
'model_uid',
],
fields: [
{
type: 'radio',
key: 'model_type',
required: true,
label: {
'en': 'Model Type',
'zh-Hans': '模型类型',
},
options: [
{
key: 'text-generation',
label: {
'en': 'Text Generation',
'zh-Hans': '文本生成',
},
},
{
key: 'embeddings',
label: {
'en': 'Embeddings',
'zh-Hans': 'Embeddings',
},
},
],
},
{
type: 'text',
key: 'model_name',
required: true,
label: {
'en': 'Model Name',
'zh-Hans': '模型名称',
},
placeholder: {
'en': 'Enter your Model Name here',
'zh-Hans': '在此输入您的模型名称',
},
},
{
type: 'text',
key: 'server_url',
required: true,
label: {
'en': 'Server Url',
'zh-Hans': 'Server Url',
},
placeholder: {
'en': 'Enter your Server url, eg: https://example.com/xxx',
'zh-Hans': '在此输入您的 Server urlhttps://example.com/xxx',
},
},
{
type: 'text',
key: 'model_uid',
required: true,
label: {
'en': 'Model UID',
'zh-Hans': 'Model UID',
},
placeholder: {
'en': 'Enter your Model UID',
'zh-Hans': '在此输入您的 Model UID',
},
},
],
},
}
export default config

View File

@@ -39,6 +39,8 @@ export enum ProviderEnum {
'spark' = 'spark',
'minimax' = 'minimax',
'chatglm' = 'chatglm',
'xinference' = 'xinference',
'openllm' = 'openllm',
}
export type ProviderConfigItem = {

View File

@@ -83,6 +83,8 @@ const ModelPage = () => {
config.tongyi,
config.wenxin,
config.chatglm,
config.xinference,
config.openllm,
]
}
else {
@@ -95,6 +97,8 @@ const ModelPage = () => {
config.tongyi,
config.wenxin,
config.chatglm,
config.xinference,
config.openllm,
]
}

View File

@@ -59,8 +59,9 @@ const Setting: FC<SettingProps> = ({
{
configurable && (
<Button
className={`!px-3 !h-7 rounded-md bg-white !text-xs font-medium text-gray-700 ${!!modelItem.disable && '!text-gray-300'}`}
className={`!px-3 !h-7 rounded-md bg-white !text-xs font-medium text-gray-700 ${!!modelItem.disable && !IS_CE_EDITION && '!text-gray-300'}`}
onClick={() => onOpenModal()}
disabled={!!modelItem.disable && !IS_CE_EDITION}
>
{t('common.operation.add')}
</Button>

View File

@@ -2,7 +2,7 @@ import { ValidatedStatus } from '../key-validator/declarations'
import { ProviderEnum } from './declarations'
import { validateModelProvider } from '@/service/common'
export const ConfigurableProviders = [ProviderEnum.azure_openai, ProviderEnum.replicate, ProviderEnum.huggingface_hub]
export const ConfigurableProviders = [ProviderEnum.azure_openai, ProviderEnum.replicate, ProviderEnum.huggingface_hub, ProviderEnum.xinference, ProviderEnum.openllm]
export const validateModelProviderFn = async (providerName: ProviderEnum, v: any) => {
let body, url