mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 05:12:39 +00:00
v4.4.7-2 (#388)
This commit is contained in:
@@ -1,28 +1,16 @@
|
||||
import { UserModelSchema } from '../user/type';
|
||||
import { Configuration, OpenAIApi } from 'openai';
|
||||
import OpenAI 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 || ''
|
||||
}
|
||||
};
|
||||
export const getAIApi = (props?: UserModelSchema['openaiAccount'], timeout = 6000) => {
|
||||
return new OpenAI({
|
||||
apiKey: props?.key || systemAIChatKey,
|
||||
baseURL: props?.baseUrl || baseUrl,
|
||||
httpAgent: global.httpsAgent,
|
||||
timeout
|
||||
});
|
||||
};
|
||||
|
@@ -1 +1,6 @@
|
||||
export { ChatCompletionRequestMessageRoleEnum } from 'openai';
|
||||
export enum ChatCompletionRequestMessageRoleEnum {
|
||||
'System' = 'system',
|
||||
'User' = 'user',
|
||||
'Assistant' = 'assistant',
|
||||
'Function' = 'function'
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { ChatCompletionRequestMessage } from '../type';
|
||||
import { getAIChatApi } from '../config';
|
||||
import { getAIApi } from '../config';
|
||||
|
||||
export const Prompt_QuestionGuide = `我不太清楚问你什么问题,请帮我生成 3 个问题,引导我继续提问。问题的长度应小于20个字符,按 JSON 格式返回: ["问题1", "问题2", "问题3"]`;
|
||||
|
||||
@@ -10,8 +10,8 @@ export async function createQuestionGuide({
|
||||
messages: ChatCompletionRequestMessage[];
|
||||
model: string;
|
||||
}) {
|
||||
const chatAPI = getAIChatApi();
|
||||
const { data } = await chatAPI.createChatCompletion({
|
||||
const ai = getAIApi();
|
||||
const data = await ai.chat.completions.create({
|
||||
model: model,
|
||||
temperature: 0,
|
||||
max_tokens: 200,
|
||||
|
7
packages/core/ai/type.d.ts
vendored
7
packages/core/ai/type.d.ts
vendored
@@ -1 +1,6 @@
|
||||
export type { CreateChatCompletionRequest, ChatCompletionRequestMessage } from 'openai';
|
||||
import OpenAI from 'openai';
|
||||
export type ChatCompletionRequestMessage = OpenAI.Chat.CreateChatCompletionRequestMessage;
|
||||
export type ChatCompletion = OpenAI.Chat.ChatCompletion;
|
||||
export type CreateChatCompletionRequest = OpenAI.Chat.ChatCompletionCreateParams;
|
||||
|
||||
export type StreamChatType = Stream<OpenAI.Chat.ChatCompletionChunk>;
|
||||
|
Reference in New Issue
Block a user