update
This commit is contained in:
@@ -48,7 +48,6 @@
|
||||
"@kevisual/query": "0.0.29",
|
||||
"@kevisual/query-login": "0.0.6",
|
||||
"@kevisual/router": "^0.0.30",
|
||||
"@kevisual/task-command": "^0.0.7",
|
||||
"@kevisual/types": "^0.0.10",
|
||||
"@kevisual/use-config": "^1.0.19",
|
||||
"@types/bun": "^1.3.2",
|
||||
|
||||
@@ -4,14 +4,20 @@ import { HttpsPem } from '@/module/assistant/https/sign.ts';
|
||||
import { AssistantInit, parseHomeArg } from '@/services/init/index.ts';
|
||||
import { configDir as HomeConfigDir } from '@/module/assistant/config/index.ts';
|
||||
import { useContextKey } from '@kevisual/use-config/context';
|
||||
|
||||
import { AssistantQuery } from '@/module/assistant/query/index.ts';
|
||||
const manualParse = parseHomeArg(HomeConfigDir);
|
||||
const _configDir = manualParse.configDir;
|
||||
export const configDir = AssistantInit.detectConfigDir(_configDir);
|
||||
const isInit = manualParse?.options?.help ? false : true;
|
||||
export const assistantConfig = new AssistantInit({
|
||||
path: configDir,
|
||||
init: isInit,
|
||||
export const assistantConfig = useContextKey<AssistantInit>('assistantConfig', () => {
|
||||
return new AssistantInit({
|
||||
path: configDir,
|
||||
init: isInit,
|
||||
});
|
||||
});
|
||||
|
||||
export const assistantQuery = useContextKey('assistantQuery', () => {
|
||||
return new AssistantQuery(assistantConfig);
|
||||
});
|
||||
|
||||
const httpsPem = new HttpsPem(assistantConfig);
|
||||
|
||||
@@ -5,4 +5,6 @@ export * from './process/index.ts';
|
||||
|
||||
export * from './proxy/index.ts';
|
||||
|
||||
export * from './local-app-manager/index.ts';
|
||||
export * from './local-app-manager/index.ts';
|
||||
|
||||
export * from './query/index.ts';
|
||||
19
assistant/src/module/assistant/query/index.ts
Normal file
19
assistant/src/module/assistant/query/index.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { DataOpts, Query } from "@kevisual/query/query";
|
||||
import { AssistantConfig } from "../config/index.ts";
|
||||
|
||||
|
||||
export class AssistantQuery {
|
||||
config: AssistantConfig;
|
||||
query: Query ;
|
||||
constructor(config: AssistantConfig) {
|
||||
config.checkMounted();
|
||||
this.config = config;
|
||||
this.query = new Query({ url: config.getRegistry() + '/api/router' });
|
||||
}
|
||||
post(body: any, options?: DataOpts) {
|
||||
return this.query.post(body, options);
|
||||
}
|
||||
get(body: any, options?: DataOpts) {
|
||||
return this.query.get(body, options);
|
||||
}
|
||||
}
|
||||
@@ -1,29 +1,40 @@
|
||||
import { useContextKey } from '@kevisual/use-config/context';
|
||||
// import { appDefine } from '@/query/query-ai/defines/ai.ts';
|
||||
import { ProviderManager } from '@kevisual/ai';
|
||||
import { App } from '@kevisual/router';
|
||||
import { assistantConfig } from '@/app.ts';
|
||||
import { Query } from '@kevisual/query';
|
||||
const app = useContextKey<App>('app');
|
||||
const query = useContextKey<Query>('assistantQuery');
|
||||
|
||||
app
|
||||
.route({
|
||||
path: 'ai',
|
||||
key: 'chat',
|
||||
description: '与 AI 进行对话, 调用 GPT 的AI 服务,生成结果,并返回。',
|
||||
middleware: ['auth'],
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
const { messages = [], username, group, question, chatOpts = {} } = ctx.query;
|
||||
// if (!username || !model || !group) {
|
||||
// return ctx.throw(4001, 'username, model, group is required');
|
||||
// }
|
||||
if (messages.length === 0 && question) {
|
||||
messages.push({
|
||||
role: 'user',
|
||||
content: question,
|
||||
});
|
||||
} else {
|
||||
ctx.throw(4001, 'messages or question is required');
|
||||
}
|
||||
|
||||
const as = assistantConfig.getCacheAssistantConfig();
|
||||
const { provider, apiKey, model } = as.ai || {};
|
||||
if (!provider) {
|
||||
const response = await query.post(ctx.query);
|
||||
if (response.code === 200) {
|
||||
ctx.body = response.data;
|
||||
return;
|
||||
} else {
|
||||
return ctx.throw(response.code, response.message);
|
||||
}
|
||||
}
|
||||
const pm = new ProviderManager({
|
||||
provider: provider,
|
||||
apiKey: apiKey,
|
||||
|
||||
Reference in New Issue
Block a user