Skip to content

Commit

Permalink
🐛 fix: 替换 plugins 为 nodejs 运行时,以解决调用插件会超时的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Jul 23, 2023
1 parent 1395a3b commit 0f99edf
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/pages/api/plugins.api.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { StreamingTextResponse } from 'ai';
import { streamToResponse } from 'ai';
import { NextApiRequest, NextApiResponse } from 'next';
import { ChatCompletionRequestMessage } from 'openai-edge';

import { OpenAIStreamPayload } from '@/types/openai';

import pluginList from '../../plugins';
import { createChatCompletion, openai } from './openai';

export const runtime = 'edge';

export default async function handler(req: Request) {
const payload = (await req.json()) as OpenAIStreamPayload;
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const payload = req.body as OpenAIStreamPayload;

const stream = await createChatCompletion(payload, (payload) => ({
experimental_onFunctionCall: async ({ name, arguments: args }, createFunctionCallMessages) => {
Expand All @@ -32,5 +31,5 @@ export default async function handler(req: Request) {
},
}));

return new StreamingTextResponse(stream);
return streamToResponse(stream, res);
}

0 comments on commit 0f99edf

Please sign in to comment.