Skip to content

Commit

Permalink
更多大模型支持插件
Browse files Browse the repository at this point in the history
  • Loading branch information
classfang committed Apr 30, 2024
1 parent e09d41b commit bc2b6de
Show file tree
Hide file tree
Showing 13 changed files with 197 additions and 109 deletions.
16 changes: 13 additions & 3 deletions src/renderer/src/assets/json/chat-models.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,18 @@
],
"Tiangong": [{ "name": "SkyChat-MegaVerse", "value": "SkyChat-MegaVerse", "type": "text" }],
"MoonshotAI": [
{ "name": "moonshot-v1-128k", "value": "moonshot-v1-128k", "type": "text" },
{ "name": "moonshot-v1-32k", "value": "moonshot-v1-32k", "type": "text" },
{ "name": "moonshot-v1-8k", "value": "moonshot-v1-8k", "type": "text" }
{
"name": "moonshot-v1-128k",
"value": "moonshot-v1-128k",
"type": "text",
"isSupportPlugin": true
},
{
"name": "moonshot-v1-32k",
"value": "moonshot-v1-32k",
"type": "text",
"isSupportPlugin": true
},
{ "name": "moonshot-v1-8k", "value": "moonshot-v1-8k", "type": "text", "isSupportPlugin": true }
]
}
3 changes: 2 additions & 1 deletion src/renderer/src/assets/json/drawing-models.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
],
"Tongyi": [{ "name": "wanx-v1", "value": "wanx-v1" }],
"ERNIE": [{ "name": "stable-diffusion-xl", "value": "sd_xl" }],
"Spark": [{ "name": "tti-v2.1", "value": "tti-v2.1" }]
"Spark": [{ "name": "tti-v2.1", "value": "tti-v2.1" }],
"ZhipuAI": [{ "name": "cogview-3", "value": "cogview-3" }]
}
7 changes: 1 addition & 6 deletions src/renderer/src/components/views/ai-calendar/AICalendar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,7 @@ const generateReport = async () => {
}
// 各家大模型特有选项
// 各家大模型特有选项
const otherOption = settingStore.getBigModelConfig(
settingStore.aiCalendar.bigModel.provider,
null,
null
)
const otherOption = settingStore.getBigModelConfig(settingStore.aiCalendar.bigModel.provider)
// 大模型能力调用
await chat2bigModel(settingStore.aiCalendar.bigModel.provider, {
Expand Down
54 changes: 3 additions & 51 deletions src/renderer/src/components/views/ai-drawing/AIDrawing.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,30 +54,7 @@ const newDrawingTask = () => {
// 开始生成
const startGenerate = () => {
// 检查大模型配置
let configErrorFlag = false
switch (drawingStore.getCurrentTask.provider) {
case 'OpenAI':
if (!settingStore.openAI.baseUrl || !settingStore.openAI.key) {
configErrorFlag = true
}
break
case 'Tongyi':
if (!settingStore.tongyi.apiKey) {
configErrorFlag = true
}
break
case 'ERNIE':
if (!settingStore.ernie.apiKey || !settingStore.ernie.secretKey) {
configErrorFlag = true
}
break
case 'Spark':
if (!settingStore.spark.appId || !settingStore.spark.secret || !settingStore.spark.key) {
configErrorFlag = true
}
break
}
if (configErrorFlag) {
if (settingStore.checkBigModelConfig(drawingStore.getCurrentTask.provider)) {
Modal.confirm({
title: t('common.configError'),
content: t(`chatWindow.configMiss.${drawingStore.getCurrentTask.provider}`),
Expand Down Expand Up @@ -127,34 +104,9 @@ const startGenerate = () => {
},
abortCtr: abortCtr
}
// 各家大模型特有选项
let otherOption = {}
switch (drawingStore.getCurrentTask.provider) {
case 'OpenAI':
otherOption = {
apiKey: settingStore.openAI.key,
baseURL: settingStore.openAI.baseUrl
}
break
case 'Tongyi':
otherOption = {
apiKey: settingStore.tongyi.apiKey
}
break
case 'ERNIE':
otherOption = {
apiKey: settingStore.ernie.apiKey,
secretKey: settingStore.ernie.secretKey
}
break
case 'Spark':
otherOption = {
appId: settingStore.spark.appId,
secretKey: settingStore.spark.secret,
apiKey: settingStore.spark.key
}
break
}
const otherOption = settingStore.getBigModelConfig(drawingStore.getCurrentTask.provider)
// 调用能力
drawingByBigModel(drawingStore.getCurrentTask.provider, {
Expand Down
21 changes: 7 additions & 14 deletions src/renderer/src/components/views/ai-drawing/AIDrawingConsole.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,8 @@ watch(
() => drawingStore.getCurrentTask.provider,
(value) => {
drawingStore.getCurrentTask.options = {}
switch (value) {
case 'OpenAI':
drawingStore.getCurrentTask.model = 'dall-e-3'
break
case 'Spark':
drawingStore.getCurrentTask.model = 'tti-v2.1'
break
case 'Tongyi':
drawingStore.getCurrentTask.model = 'wanx-v1'
break
case 'ERNIE':
drawingStore.getCurrentTask.model = 'sd_xl'
break
if (drawingModels[value]) {
drawingStore.getCurrentTask.model = drawingModels[value][0].name
}
}
)
Expand Down Expand Up @@ -85,7 +74,11 @@ watch(
<a-input-number v-model="drawingStore.getCurrentTask.options.n" :min="1" :max="4" />
</a-form-item>
<!-- 图片大小 -->
<a-form-item field="size" :label="$t('aiDrawing.size')">
<a-form-item
v-if="drawingStore.getCurrentTask.model != 'cogview-3'"
field="size"
:label="$t('aiDrawing.size')"
>
<a-select v-model="drawingStore.getCurrentTask.options.size" :fallback-option="false">
<template v-if="drawingStore.getCurrentTask.model === 'dall-e-2'">
<a-option value="256x256">256x256</a-option>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ const useBigModel = async () => {
maxTokens: data.currentAssistant.maxTokens,
contextSize: data.currentAssistant.contextSize,
messages: copyObj(bigModelMessageList),
abortCtr: abortCtr,
chatPlugins: chatPluginStore.getPluginListByIds(data.currentAssistant.chatPluginIdList, true),
startAnswer: (sessionId: string, content?: string) => {
if (data.currentSessionId != sessionId) {
return
Expand Down Expand Up @@ -324,11 +326,7 @@ const useBigModel = async () => {
}
// 各家大模型特有选项
const otherOption = settingStore.getBigModelConfig(
data.currentAssistant.provider,
abortCtr,
chatPluginStore.getPluginListByIds(data.currentAssistant.chatPluginIdList)
)
const otherOption = settingStore.getBigModelConfig(data.currentAssistant.provider)
// 大模型能力调用
await chat2bigModel(data.currentAssistant.provider, {
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type BigModelProvider =
| 'Spark'
| 'Tiangong'
| 'MoonshotAI'
type AIDrawingProvider = 'OpenAI' | 'Tongyi' | 'ERNIE' | 'Spark'
type AIDrawingProvider = 'OpenAI' | 'ZhipuAI' | 'Tongyi' | 'ERNIE' | 'Spark'
type AIAudioProvider = 'OpenAI'
type TranslatorProvider = 'youdao' | 'baiduTranslation'
type AssistantType = 'chat'
Expand Down
14 changes: 12 additions & 2 deletions src/renderer/src/store/chat-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,21 @@ export const useChatPluginStore = defineStore({
}
return importFlag
},
getPluginListByIds(ids: string[]): ChatPlugin[] {
getPluginListByIds(ids: string[], newId?: boolean): ChatPlugin[] {
if (!ids || ids.length === 0) {
return []
}
return copyObj(this.chatPluginList.filter((p) => ids.includes(p.id)))

const pluginList = copyObj(this.chatPluginList.filter((p) => ids.includes(p.id)))

if (newId) {
// 重新设置插件id
for (let i = 0; i < pluginList.length; i++) {
pluginList[i].id = `plugin_${i}`
}
}

return pluginList
}
},
persist: {
Expand Down
23 changes: 6 additions & 17 deletions src/renderer/src/store/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,18 +195,13 @@ export const useSettingStore = defineStore({
}
return configErrorFlag
},
getBigModelConfig(
provider: BigModelProvider,
abortCtr: AbortController | null,
chatPlugins: ChatPlugin[] | null
) {
getBigModelConfig(provider: BigModelProvider) {
let otherOption = {}
switch (provider) {
case 'OpenAI':
otherOption = {
apiKey: this.openAI.key,
baseURL: this.openAI.baseUrl,
chatPlugins
baseURL: this.openAI.baseUrl
}
break
case 'Ollama':
Expand All @@ -217,15 +212,12 @@ export const useSettingStore = defineStore({
case 'Gemini':
otherOption = {
apiKey: this.gemini.key,
baseURL: this.gemini.baseUrl,
abortCtr
baseURL: this.gemini.baseUrl
}
break
case 'ZhipuAI':
otherOption = {
apiKey: this.zhipuAI.apiKey,
abortCtr,
chatPlugins
apiKey: this.zhipuAI.apiKey
}
break
case 'Spark':
Expand All @@ -238,15 +230,12 @@ export const useSettingStore = defineStore({
case 'ERNIE':
otherOption = {
apiKey: this.ernie.apiKey,
secretKey: this.ernie.secretKey,
abortCtr
secretKey: this.ernie.secretKey
}
break
case 'Tongyi':
otherOption = {
apiKey: this.tongyi.apiKey,
chatPlugins,
abortCtr
apiKey: this.tongyi.apiKey
}
break
case 'Tiangong':
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/src/utils/big-model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { chat2openai, drawingByOpenAI, speechByOpenAI } from '@renderer/utils/bi
import { chat2spark, drawingBySpark } from '@renderer/utils/big-model/spark-util'
import { chat2tiangong } from '@renderer/utils/big-model/tiangong-util'
import { chat2tongyi, drawingByTongyi } from '@renderer/utils/big-model/tongyi-util'
import { chat2zhipu } from '@renderer/utils/big-model/zhipu-util'
import { chat2zhipu, drawingByZhipu } from '@renderer/utils/big-model/zhipu-util'

type ChatFunctionMap = {
[provider in BigModelProvider]: (option: CommonChatOption) => Promise<any>
Expand Down Expand Up @@ -83,6 +83,7 @@ const chatFunctionMap: ChatFunctionMap = {

const drawingFunctionMap: DrawingFunctionMap = {
OpenAI: drawingByOpenAI,
ZhipuAI: drawingByZhipu,
Tongyi: drawingByTongyi,
ERNIE: drawingByERNIE,
Spark: drawingBySpark
Expand Down
Loading

0 comments on commit bc2b6de

Please sign in to comment.