mirror of
https://github.com/labring/FastGPT.git
synced 2026-05-16 01:09:01 +08:00
Feat: system tool support stream response (#5206)
* Match SSE for FastGPT (#5168) * Match SSE for FastGPT * Modify the judgment * Optimize logic for SSE transmission * Refactor imports * directly use workflowStreamResponse from props * improve error handling and streamline onStreamData logic * Refactor API client configuration * perf: system tool support sse * update doc --------- Co-authored-by: Zhuangzai fa <143257420+ctrlz526@users.noreply.github.com>
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
import createClient, { type SystemVarType } from '@fastgpt-sdk/plugin';
|
||||
import createClient, { RunToolWithStream } from '@fastgpt-sdk/plugin';
|
||||
import { PluginSourceEnum } from '@fastgpt/global/core/app/plugin/constants';
|
||||
|
||||
const BASE_URL = process.env.PLUGIN_BASE_URL || '';
|
||||
const TOKEN = process.env.PLUGIN_TOKEN || '';
|
||||
|
||||
const client = createClient({
|
||||
baseUrl: process.env.PLUGIN_BASE_URL || '',
|
||||
token: process.env.PLUGIN_TOKEN || ''
|
||||
baseUrl: BASE_URL,
|
||||
token: TOKEN
|
||||
});
|
||||
|
||||
export async function getSystemToolList() {
|
||||
@@ -26,26 +29,8 @@ export async function getSystemToolList() {
|
||||
return Promise.reject(res.body);
|
||||
}
|
||||
|
||||
export async function runTool({
|
||||
toolId,
|
||||
inputs,
|
||||
systemVar
|
||||
}: {
|
||||
toolId: string;
|
||||
inputs: Record<string, any>;
|
||||
systemVar: SystemVarType;
|
||||
}) {
|
||||
const res = await client.tool.run({
|
||||
body: {
|
||||
toolId,
|
||||
inputs,
|
||||
systemVar
|
||||
}
|
||||
});
|
||||
|
||||
if (res.status === 200 && res.body.output) {
|
||||
return res.body.output;
|
||||
} else {
|
||||
return Promise.reject(res.body);
|
||||
}
|
||||
}
|
||||
const runToolInstance = new RunToolWithStream({
|
||||
baseUrl: BASE_URL,
|
||||
token: TOKEN
|
||||
});
|
||||
export const runSystemTool = runToolInstance.run.bind(runToolInstance);
|
||||
|
||||
Reference in New Issue
Block a user