feat: add LocalAI local embedding model support (#1021)
Co-authored-by: StyleZhang <jasonapring2015@outlook.com>
This commit is contained in:
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 76 KiB |
15
web/app/components/base/icons/assets/public/llm/localai.svg
Normal file
15
web/app/components/base/icons/assets/public/llm/localai.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 73 KiB |
107
web/app/components/base/icons/src/public/llm/Localai.json
Normal file
107
web/app/components/base/icons/src/public/llm/Localai.json
Normal file
File diff suppressed because one or more lines are too long
14
web/app/components/base/icons/src/public/llm/Localai.tsx
Normal file
14
web/app/components/base/icons/src/public/llm/Localai.tsx
Normal file
@@ -0,0 +1,14 @@
|
||||
// GENERATE BY script
|
||||
// DON NOT EDIT IT MANUALLY
|
||||
|
||||
import * as React from 'react'
|
||||
import data from './Localai.json'
|
||||
import IconBase from '@/app/components/base/icons/IconBase'
|
||||
import type { IconBaseProps, IconData } from '@/app/components/base/icons/IconBase'
|
||||
|
||||
const Icon = React.forwardRef<React.MutableRefObject<SVGElement>, Omit<IconBaseProps, 'data'>>((
|
||||
props,
|
||||
ref,
|
||||
) => <IconBase {...props} ref={ref} data={data as IconData} />)
|
||||
|
||||
export default Icon
|
||||
170
web/app/components/base/icons/src/public/llm/LocalaiText.json
Normal file
170
web/app/components/base/icons/src/public/llm/LocalaiText.json
Normal file
File diff suppressed because one or more lines are too long
14
web/app/components/base/icons/src/public/llm/LocalaiText.tsx
Normal file
14
web/app/components/base/icons/src/public/llm/LocalaiText.tsx
Normal file
@@ -0,0 +1,14 @@
|
||||
// GENERATE BY script
|
||||
// DON NOT EDIT IT MANUALLY
|
||||
|
||||
import * as React from 'react'
|
||||
import data from './LocalaiText.json'
|
||||
import IconBase from '@/app/components/base/icons/IconBase'
|
||||
import type { IconBaseProps, IconData } from '@/app/components/base/icons/IconBase'
|
||||
|
||||
const Icon = React.forwardRef<React.MutableRefObject<SVGElement>, Omit<IconBaseProps, 'data'>>((
|
||||
props,
|
||||
ref,
|
||||
) => <IconBase {...props} ref={ref} data={data as IconData} />)
|
||||
|
||||
export default Icon
|
||||
@@ -14,6 +14,8 @@ export { default as Huggingface } from './Huggingface'
|
||||
export { default as IflytekSparkTextCn } from './IflytekSparkTextCn'
|
||||
export { default as IflytekSparkText } from './IflytekSparkText'
|
||||
export { default as IflytekSpark } from './IflytekSpark'
|
||||
export { default as LocalaiText } from './LocalaiText'
|
||||
export { default as Localai } from './Localai'
|
||||
export { default as Microsoft } from './Microsoft'
|
||||
export { default as OpenaiBlack } from './OpenaiBlack'
|
||||
export { default as OpenaiBlue } from './OpenaiBlue'
|
||||
|
||||
@@ -10,6 +10,7 @@ import minimax from './minimax'
|
||||
import chatglm from './chatglm'
|
||||
import xinference from './xinference'
|
||||
import openllm from './openllm'
|
||||
import localai from './localai'
|
||||
|
||||
export default {
|
||||
openai,
|
||||
@@ -24,4 +25,5 @@ export default {
|
||||
chatglm,
|
||||
xinference,
|
||||
openllm,
|
||||
localai,
|
||||
}
|
||||
|
||||
@@ -0,0 +1,176 @@
|
||||
import { ProviderEnum } from '../declarations'
|
||||
import type { FormValue, ProviderConfig } from '../declarations'
|
||||
import { Localai, LocalaiText } from '@/app/components/base/icons/src/public/llm'
|
||||
|
||||
const config: ProviderConfig = {
|
||||
selector: {
|
||||
name: {
|
||||
'en': 'LocalAI',
|
||||
'zh-Hans': 'LocalAI',
|
||||
},
|
||||
icon: <Localai className='w-full h-full' />,
|
||||
},
|
||||
item: {
|
||||
key: ProviderEnum.localai,
|
||||
titleIcon: {
|
||||
'en': <LocalaiText className='h-6' />,
|
||||
'zh-Hans': <LocalaiText 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.localai,
|
||||
title: {
|
||||
'en': 'LocalAI',
|
||||
'zh-Hans': 'LocalAI',
|
||||
},
|
||||
icon: <Localai className='h-6' />,
|
||||
link: {
|
||||
href: 'https://github.com/go-skynet/LocalAI',
|
||||
label: {
|
||||
'en': 'How to deploy LocalAI',
|
||||
'zh-Hans': '如何部署 LocalAI',
|
||||
},
|
||||
},
|
||||
defaultValue: {
|
||||
model_type: 'text-generation',
|
||||
completion_type: 'completion',
|
||||
},
|
||||
validateKeys: (v?: FormValue) => {
|
||||
if (v?.model_type === 'text-generation') {
|
||||
return [
|
||||
'model_type',
|
||||
'model_name',
|
||||
'server_url',
|
||||
'completion_type',
|
||||
]
|
||||
}
|
||||
if (v?.model_type === 'embeddings') {
|
||||
return [
|
||||
'model_type',
|
||||
'model_name',
|
||||
'server_url',
|
||||
]
|
||||
}
|
||||
return []
|
||||
},
|
||||
filterValue: (v?: FormValue) => {
|
||||
let filteredKeys: string[] = []
|
||||
if (v?.model_type === 'text-generation') {
|
||||
filteredKeys = [
|
||||
'model_type',
|
||||
'model_name',
|
||||
'server_url',
|
||||
'completion_type',
|
||||
]
|
||||
}
|
||||
if (v?.model_type === 'embeddings') {
|
||||
filteredKeys = [
|
||||
'model_type',
|
||||
'model_name',
|
||||
'server_url',
|
||||
]
|
||||
}
|
||||
return filteredKeys.reduce((prev: FormValue, next: string) => {
|
||||
prev[next] = v?.[next] || ''
|
||||
return prev
|
||||
}, {})
|
||||
},
|
||||
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': '在此输入您的模型名称',
|
||||
},
|
||||
},
|
||||
{
|
||||
hidden: (value?: FormValue) => value?.model_type === 'embeddings',
|
||||
type: 'radio',
|
||||
key: 'completion_type',
|
||||
required: true,
|
||||
label: {
|
||||
'en': 'Completion Type',
|
||||
'zh-Hans': 'Completion Type',
|
||||
},
|
||||
options: [
|
||||
{
|
||||
key: 'completion',
|
||||
label: {
|
||||
'en': 'Completion',
|
||||
'zh-Hans': 'Completion',
|
||||
},
|
||||
},
|
||||
{
|
||||
key: 'chat_completion',
|
||||
label: {
|
||||
'en': 'Chat Completion',
|
||||
'zh-Hans': 'Chat Completion',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
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 Url,如:https://example.com/xxx',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
export default config
|
||||
@@ -41,6 +41,7 @@ export enum ProviderEnum {
|
||||
'chatglm' = 'chatglm',
|
||||
'xinference' = 'xinference',
|
||||
'openllm' = 'openllm',
|
||||
'localai' = 'localai',
|
||||
}
|
||||
|
||||
export type ProviderConfigItem = {
|
||||
|
||||
@@ -99,6 +99,7 @@ const ModelPage = () => {
|
||||
config.chatglm,
|
||||
config.xinference,
|
||||
config.openllm,
|
||||
config.localai,
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@@ -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, ProviderEnum.xinference, ProviderEnum.openllm]
|
||||
export const ConfigurableProviders = [ProviderEnum.azure_openai, ProviderEnum.replicate, ProviderEnum.huggingface_hub, ProviderEnum.xinference, ProviderEnum.openllm, ProviderEnum.localai]
|
||||
|
||||
export const validateModelProviderFn = async (providerName: ProviderEnum, v: any) => {
|
||||
let body, url
|
||||
|
||||
Reference in New Issue
Block a user