Skip to content

Commit

Permalink
fix: missing endpoint bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Jazee6 committed Sep 20, 2024
1 parent 1b74aef commit ca11405
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions server/api/auth/openai.post.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import { handleErr, openaiParser, streamResponse } from "~/utils/helper";
import { OpenAIBody, OpenAIReq } from "~/utils/types";
import {handleErr, openaiParser, streamResponse} from "~/utils/helper";
import {OpenAIBody, OpenAIReq} from "~/utils/types";

export default defineEventHandler(async (event) => {
const body: OpenAIReq = await readBody(event);
const { model, messages, key } = body;
const {model, messages, key, endpoint} = body;

const openAIBody: OpenAIBody = {
stream: true,
model, // 使用传入的模型参数
model,
messages,
};

// 检查是否提供了自定义的 OPENAI_API_URL
const apiUrl = process.env.OPENAI_API_URL ?
`${process.env.OPENAI_API_URL}/v1/chat/completions` :
`${process.env.CF_GATEWAY}/openai/${endpoint}`;
const apiUrl = process.env.OPENAI_API_URL ?
`${process.env.OPENAI_API_URL}/v1/chat/completions` :
`${process.env.CF_GATEWAY}/openai/${endpoint}`;

const res = await fetch(apiUrl, {
method: 'POST',
Expand Down

0 comments on commit ca11405

Please sign in to comment.