File size: 1,232 Bytes
640c3b0 c2df9c2 caaca78 a73e8b4 9c9d521 7ec7db5 c2df9c2 caaca78 9c9d521 a73e8b4 7ec7db5 c2df9c2 a73e8b4 9c9d521 7ec7db5 c2df9c2 e842b6d fd598d8 e842b6d c2df9c2 640c3b0 b8fadbb c2df9c2 fd598d8 c2df9c2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
import OpenAI from "openai";
import { OpenAIStream, StreamingTextResponse } from "ai";
import { createSearchApi } from "@/app/tools/search";
import { createOddsApi } from "@/app/tools/odds";
import { createSportsResultsApi } from "@/app/tools/scores";
import { createCoinMarketCapApi } from "@/app/tools/coin";
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 [, coinMarketCapApiSchema] = createCoinMarketCapApi({ apiKey: process.env.COINMARKETCAP_API_KEY || '' });
const functions: any[] = [
serpApiSchema,
oddsApiSchema,
sportsApiResultsSchema,
coinMarketCapApiSchema
];
export async function POST(req: Request) {
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY
});
const { messages, function_call } = await req.json()
const response = await openai.chat.completions.create({
model: 'gpt-3.5-turbo',
stream: true,
messages,
functions,
function_call
})
const stream = OpenAIStream(response)
return new StreamingTextResponse(stream)
} |