This commit is contained in:
Archer
2023-12-18 16:24:50 +08:00
committed by GitHub
parent d33c99f564
commit 703583fff7
130 changed files with 3418 additions and 2579 deletions

View File

@@ -78,12 +78,12 @@ export function request(url: string, data: any, config: ConfigType, method: Meth
return instance
.request({
baseURL: `http://localhost:${process.env.PORT || 3000}`,
baseURL: `http://${process.env.HOSTNAME || 'localhost'}:${process.env.PORT || 3000}`,
url,
method,
data: ['POST', 'PUT'].includes(method) ? data : null,
params: !['POST', 'PUT'].includes(method) ? data : null,
...config // 用户自定义配置,可以覆盖前面的配置
...config // custom config
})
.then((res) => checkRes(res.data))
.catch((err) => responseError(err));

View File

@@ -243,8 +243,8 @@ function formatSplitText(text: string, rawText: string) {
// empty result. direct split chunk
if (result.length === 0) {
const splitRes = splitText2Chunks({ text: rawText, chunkLen: 512 });
splitRes.chunks.forEach((chunk) => {
const { chunks } = splitText2Chunks({ text: rawText, chunkLen: 512, countTokens: false });
chunks.forEach((chunk) => {
result.push({
q: chunk,
a: '',

View File

@@ -40,7 +40,7 @@ export async function dispatchContentExtract(props: Props): Promise<Response> {
const extractModel = global.extractModels[0];
const chatHistories = getHistories(history, histories);
const { arg, tokens } = await (async () => {
const { arg, tokens, rawResponse } = await (async () => {
if (extractModel.functionCall) {
return functionCall({
...props,
@@ -176,6 +176,7 @@ ${content}
const tokens = response.usage?.total_tokens || 0;
return {
rawResponse: response?.choices?.[0]?.message?.tool_calls?.[0]?.function?.arguments || '',
tokens,
arg
};
@@ -195,7 +196,7 @@ async function completions({
json: extractKeys
.map(
(item) =>
`{"key":"${item.key}", "description":"${item.required}", "required":${item.required}${
`{"key":"${item.key}", "description":"${item.desc}", "required":${item.required}${
item.enum ? `, "enum":"[${item.enum.split('\n')}]"` : ''
}}`
)
@@ -223,6 +224,7 @@ Human: ${content}`
if (start === -1 || end === -1)
return {
rawResponse: answer,
tokens: totalTokens,
arg: {}
};
@@ -234,11 +236,13 @@ Human: ${content}`
try {
return {
rawResponse: answer,
tokens: totalTokens,
arg: JSON.parse(jsonStr) as Record<string, any>
};
} catch (error) {
return {
rawResponse: answer,
tokens: totalTokens,
arg: {}
};

View File

@@ -50,6 +50,7 @@ export async function dispatchModules({
appId,
modules,
chatId,
responseChatItemId,
histories = [],
startParams = {},
variables = {},
@@ -63,6 +64,7 @@ export async function dispatchModules({
appId: string;
modules: ModuleItemType[];
chatId?: string;
responseChatItemId?: string;
histories: ChatItemType[];
startParams?: Record<string, any>;
variables?: Record<string, any>;
@@ -201,6 +203,7 @@ export async function dispatchModules({
user,
appId,
chatId,
responseChatItemId,
stream,
detail,
variables,

View File

@@ -21,6 +21,7 @@ export const dispatchHttpRequest = async (props: HttpRequestProps): Promise<Http
let {
appId,
chatId,
responseChatItemId,
variables,
inputs: {
system_httpMethod: httpMethod,
@@ -57,6 +58,7 @@ export const dispatchHttpRequest = async (props: HttpRequestProps): Promise<Http
requestBody: {
appId,
chatId,
responseChatItemId,
variables,
data: body
},

View File

@@ -4,7 +4,6 @@ import { initPg } from '@fastgpt/service/common/pg';
import { MongoUser } from '@fastgpt/service/support/user/schema';
import { connectMongo } from '@fastgpt/service/common/mongo/init';
import { hashStr } from '@fastgpt/global/common/string/tools';
import { getInitConfig } from '@/pages/api/system/getInitData';
import { createDefaultTeam } from '@fastgpt/service/support/user/team/controller';
import { exit } from 'process';
@@ -13,9 +12,7 @@ import { exit } from 'process';
*/
export function connectToDatabase(): Promise<void> {
return connectMongo({
beforeHook: () => {
getInitConfig();
},
beforeHook: () => {},
afterHook: () => {
initPg();
// start queue