feat: ai基础更新
parent
a4249f95c3
commit
95ad03bdf1
|
|
@ -3,7 +3,7 @@ import type { AgentConfig, ModelConfig } from '../components/agent-config'
|
|||
import type { AiMessage } from '@/store/ai'
|
||||
import { useAiStore } from '@/store'
|
||||
import {
|
||||
defaultAgentConfig,
|
||||
defaultModelAgentConfig,
|
||||
defaultModelConfig,
|
||||
generateMessageId,
|
||||
} from '../components/agent-config'
|
||||
|
|
@ -17,7 +17,10 @@ definePage({
|
|||
},
|
||||
})
|
||||
|
||||
const agentConfig = reactive<AgentConfig>({ ...defaultAgentConfig })
|
||||
const agentConfig = reactive<AgentConfig>({
|
||||
// 当前页面默认走模型直连;如需切回 bot,改成 ...defaultAgentConfig
|
||||
...defaultModelAgentConfig,
|
||||
})
|
||||
const modelConfig = reactive<ModelConfig>({ ...defaultModelConfig })
|
||||
|
||||
const aiStore = useAiStore()
|
||||
|
|
@ -41,14 +44,6 @@ onLoad(() => {
|
|||
|
||||
aiStore.ensureThreadId()
|
||||
|
||||
wx.cloud.extend.AI.bot.getRecommendQuestions({
|
||||
data: {
|
||||
botId: 'agent-wxai-4gl75um61026324f',
|
||||
msg: '你是谁',
|
||||
},
|
||||
}).then((resp) => {
|
||||
console.log(resp)
|
||||
})
|
||||
})
|
||||
|
||||
// z-paging 聊天模式:第一页直接把 store 里的历史灌给它
|
||||
|
|
@ -124,9 +119,9 @@ async function handleSend(text: string) {
|
|||
|
||||
// 当前 V2 agent 后端不支持 getRecommendQuestions(端点 404),先关掉这一调用。
|
||||
// 等切换到 bot-xxx 旧版 agent 或后端补上对应路由再开启。
|
||||
// if (!cancelFlag) {
|
||||
// void loadRecommendQuestions(aiMsg.id, text)
|
||||
// }
|
||||
if (!cancelFlag) {
|
||||
void loadRecommendQuestions(aiMsg.id, text)
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
aiStore.updateMessage(aiMsg.id, {
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ export interface AgentConfig {
|
|||
}
|
||||
|
||||
export interface ModelConfig {
|
||||
/** 模型 provider,如 'cloudbase' / 'youtu' / 'hunyuan' */
|
||||
/** createModel 的 provider / GroupName,如 'cloudbase' / 'hunyuan-exp' / 'custom-xxx' */
|
||||
modelProvider: string
|
||||
/** 具体的模型 ID */
|
||||
quickResponseModel: string
|
||||
|
|
@ -43,12 +43,30 @@ export const defaultAgentConfig: AgentConfig = {
|
|||
],
|
||||
}
|
||||
|
||||
/**
|
||||
* model 模式配置示例:
|
||||
* 1. 把 defaultAgentConfig.chatMode 改成 'model'
|
||||
* 2. createModel 传 provider / GroupName,具体模型写在 quickResponseModel
|
||||
*
|
||||
* 对应调用示例:
|
||||
* wx.cloud.extend.AI.createModel('cloudbase').streamText({
|
||||
* data: { model: 'hy3-preview', messages: [...] },
|
||||
* })
|
||||
*/
|
||||
export const defaultModelConfig: ModelConfig = {
|
||||
modelProvider: 'youtu-intent-pro',
|
||||
quickResponseModel: '',
|
||||
modelProvider: 'hunyuan-v3',
|
||||
quickResponseModel: 'hy3-preview',
|
||||
logo: '',
|
||||
}
|
||||
|
||||
/** 切换到 model 模式时可直接复用的示例 */
|
||||
export const defaultModelAgentConfig: AgentConfig = {
|
||||
...defaultAgentConfig,
|
||||
chatMode: 'bot',
|
||||
botName: 'AI 模型助手',
|
||||
welcomeMsg: '你好,我是 AI 模型助手,可以直接用大模型和你对话。',
|
||||
}
|
||||
|
||||
export function generateMessageId() {
|
||||
const timestamp = Date.now().toString().slice(-8)
|
||||
const random = Math.floor(Math.random() * 10000).toString().padStart(4, '0')
|
||||
|
|
|
|||
|
|
@ -51,9 +51,10 @@ export interface SendMessageOptions {
|
|||
export async function streamMessage(options: SendMessageOptions): Promise<string> {
|
||||
if (options.chatMode === 'model') {
|
||||
return streamModel(options)
|
||||
}
|
||||
}else{
|
||||
return streamBot(options)
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- bot 模式:wx.cloud.extend.AI.bot.sendMessage ----------
|
||||
|
||||
|
|
@ -140,6 +141,8 @@ async function streamModel(options: SendMessageOptions): Promise<string> {
|
|||
// #ifdef MP-WEIXIN
|
||||
const ai = wx.cloud.extend.AI
|
||||
const aiModel = ai.createModel(modelProvider)
|
||||
console.log("aimodel创建",aiModel);
|
||||
|
||||
const res = await aiModel.streamText({
|
||||
data: {
|
||||
model: quickResponseModel,
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ definePage({
|
|||
// #endif
|
||||
|
||||
const tokenStore = useTokenStore()
|
||||
console.log(systemInfo);
|
||||
|
||||
onShareAppMessage(() => {
|
||||
return {
|
||||
|
|
|
|||
Loading…
Reference in New Issue