generated from template/apps-template
update
This commit is contained in:
@@ -3,6 +3,7 @@ import { NocoLifeService } from './services/life.ts';
|
||||
import dayjs from 'dayjs';
|
||||
import { useContextKey } from '@kevisual/context';
|
||||
import { BaseChat, AIUtils } from '@kevisual/ai';
|
||||
import { pick } from 'es-toolkit'
|
||||
app.route({
|
||||
path: 'noco-life',
|
||||
key: 'config-update',
|
||||
@@ -18,17 +19,20 @@ app.route({
|
||||
const config = await nocoLifeService.getLifeConfig()
|
||||
if (question) {
|
||||
const ai: BaseChat = useContextKey('ai');
|
||||
const originConfig = JSON.stringify(config);
|
||||
const pickData = pick(config, ['baseURL', 'token', 'baseId', 'tableId']);
|
||||
const originConfig = JSON.stringify(pickData);
|
||||
await ai.chat([
|
||||
{ role: 'system', content: `你是一个多维表格配置助理,你的任务是帮助用户解析多维表格的配置信息。用户会提供配置信息,你需要从中提取出 baseURL, token, baseId, tableId 等字段,并以 JSON 格式返回。如果某个字段缺失,可以不返回该字段。请确保返回的 JSON 格式正确且易于解析。` },
|
||||
{
|
||||
role: 'system', content: `你是一个多维表格配置助理,你的任务是帮助用户解析多维表格的配置信息。用户会提供配置信息,你需要从中提取出 baseURL, token, baseId, tableId 等字段,并以 JSON 格式返回。如果某个字段缺失,可以不返回该字段。请确保返回的 JSON 格式正确且易于解析。
|
||||
返回的数据例子: { "baseURL": "https://example.com", "token": "abc123", "baseId": "base_01", "tableId": "table_01" }` },
|
||||
{ role: 'user', content: `当前已有的多维表格配置信息是: ${originConfig}` },
|
||||
{ role: 'user', content: question },
|
||||
{ role: 'user', content: `当前已有的多维表格配置信息是: ${originConfig}` }
|
||||
])
|
||||
let msg = AIUtils.extractJsonFromMarkdown(ai.responseText || '');
|
||||
if (msg == null) {
|
||||
ctx.throw(500, 'AI 返回结果解析失败');
|
||||
}
|
||||
data = msg;
|
||||
data = { ...data, ...config, ...msg };
|
||||
}
|
||||
if (!data?.baseURL || !data?.token || !data?.baseId) {
|
||||
ctx.throw(400, '缺少参数 baseURL, token, baseId, tableId');
|
||||
|
||||
Reference in New Issue
Block a user