mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-21 11:43:56 +00:00
v4.4.5-2 (#355)
This commit is contained in:
28
packages/core/aiApi/config.ts
Normal file
28
packages/core/aiApi/config.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { UserModelSchema } from '../user/type';
|
||||
import { Configuration, OpenAIApi } from 'openai';
|
||||
|
||||
export const openaiBaseUrl = process.env.OPENAI_BASE_URL || 'https://api.openai.com/v1';
|
||||
export const baseUrl = process.env.ONEAPI_URL || openaiBaseUrl;
|
||||
|
||||
export const systemAIChatKey = process.env.CHAT_API_KEY || '';
|
||||
|
||||
export const getAIChatApi = (props?: UserModelSchema['openaiAccount']) => {
|
||||
return new OpenAIApi(
|
||||
new Configuration({
|
||||
basePath: props?.baseUrl || baseUrl,
|
||||
apiKey: props?.key || systemAIChatKey
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
/* openai axios config */
|
||||
export const axiosConfig = (props?: UserModelSchema['openaiAccount']) => {
|
||||
return {
|
||||
baseURL: props?.baseUrl || baseUrl, // 此处仅对非 npm 模块有效
|
||||
httpsAgent: global.httpsAgent,
|
||||
headers: {
|
||||
Authorization: `Bearer ${props?.key || systemAIChatKey}`,
|
||||
auth: process.env.OPENAI_BASE_URL_AUTH || ''
|
||||
}
|
||||
};
|
||||
};
|
1
packages/core/aiApi/constant.ts
Normal file
1
packages/core/aiApi/constant.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { ChatCompletionRequestMessageRoleEnum } from 'openai';
|
1
packages/core/aiApi/type.d.ts
vendored
Normal file
1
packages/core/aiApi/type.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export type { CreateChatCompletionRequest, ChatCompletionRequestMessage } from 'openai';
|
13
packages/core/init.ts
Normal file
13
packages/core/init.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import tunnel from 'tunnel';
|
||||
|
||||
export function initHttpAgent() {
|
||||
// proxy obj
|
||||
if (process.env.AXIOS_PROXY_HOST && process.env.AXIOS_PROXY_PORT) {
|
||||
global.httpsAgent = tunnel.httpsOverHttp({
|
||||
proxy: {
|
||||
host: process.env.AXIOS_PROXY_HOST,
|
||||
port: +process.env.AXIOS_PROXY_PORT
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@@ -1,4 +1,11 @@
|
||||
{
|
||||
"name": "@fastgpt/core",
|
||||
"version": "1.0.0"
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"openai": "^3.3.0",
|
||||
"tunnel": "^0.0.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/tunnel": "^0.0.4"
|
||||
}
|
||||
}
|
||||
|
5
packages/core/types/index.d.ts
vendored
Normal file
5
packages/core/types/index.d.ts
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import type { Agent } from 'http';
|
||||
|
||||
declare global {
|
||||
var httpsAgent: Agent;
|
||||
}
|
19
packages/core/user/type.d.ts
vendored
Normal file
19
packages/core/user/type.d.ts
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
export type UserModelSchema = {
|
||||
_id: string;
|
||||
username: string;
|
||||
password: string;
|
||||
avatar: string;
|
||||
balance: number;
|
||||
promotionRate: number;
|
||||
inviterId?: string;
|
||||
openaiKey: string;
|
||||
createTime: number;
|
||||
timezone: string;
|
||||
openaiAccount?: {
|
||||
key: string;
|
||||
baseUrl: string;
|
||||
};
|
||||
limit: {
|
||||
exportKbTime?: Date;
|
||||
};
|
||||
};
|
Reference in New Issue
Block a user