matt HOFFNER
fix
dd225cf
raw
history blame
1.1 kB
import { Configuration, OpenAIApi } from "openai-edge";
import { OpenAIStream, StreamingTextResponse } from "ai";
import { createSearchApi } from "@/app/tools/search";
import { createOddsApi } from "@/app/tools/odds";
import { createSportsResultsApi } from "@/app/tools/scores";
const [, serpApiSchema] = createSearchApi({ apiKey: process.env.SERP_API_KEY || '' });
const [, sportsApiResultsSchema] = createSportsResultsApi({ apiKey: process.env.SERP_API_KEY || '' });
const [, oddsApiSchema] = createOddsApi({ apiKey: process.env.ODDS_API_KEY || '' });
const config = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(config);
const functions: any[] = [
serpApiSchema,
oddsApiSchema,
sportsApiResultsSchema
];
export async function POST(req: Request) {
const { messages, function_call } = await req.json()
const response = await openai.createChatCompletion({
model: 'gpt-3.5-turbo-1106',
stream: true,
messages,
functions,
function_call
})
const stream = OpenAIStream(response)
return new StreamingTextResponse(stream)
}