(req: NextRequest)
| 20 | |
| 21 | |
| 22 | export async function POST(req: NextRequest) { |
| 23 | if (req.method === 'POST') { |
| 24 | try { |
| 25 | const { assistantName, assistantModel, assistantDescription, fileIds } = await req.json(); |
| 26 | |
| 27 | // Log the fileIds |
| 28 | console.log('File IDs:', fileIds); |
| 29 | |
| 30 | if (!assistantName || !assistantModel || !assistantDescription) { |
| 31 | throw new Error('Missing required assistant parameters'); |
| 32 | } |
| 33 | |
| 34 | const assistantOptions: any = { |
| 35 | name: assistantName, |
| 36 | instructions: assistantDescription, |
| 37 | model: assistantModel, |
| 38 | tools: [{ "type": "retrieval" }], |
| 39 | }; |
| 40 | if (fileIds) { |
| 41 | assistantOptions.file_ids = fileIds; |
| 42 | } |
| 43 | |
| 44 | // Log the assistantOptions |
| 45 | console.log('Assistant Options:', assistantOptions); |
| 46 | |
| 47 | const assistant = await openai.beta.assistants.create(assistantOptions); |
| 48 | const assistantId = assistant.id; |
| 49 | |
| 50 | return NextResponse.json({ |
| 51 | message: 'Assistant created successfully', |
| 52 | assistantId: assistantId |
| 53 | }); |
| 54 | } catch (error) { |
| 55 | if (error instanceof Error) { |
| 56 | console.error('Error:', error); |
| 57 | return NextResponse.json({ error: error.message }); |
| 58 | } else { |
| 59 | console.error('Unknown error:', error); |
| 60 | return NextResponse.json({ error: 'An unknown error occurred' }); |
| 61 | } |
| 62 | } |
| 63 | } else { |
| 64 | return NextResponse.json({ error: 'Method Not Allowed' }); |
| 65 | } |
| 66 | }; |
nothing calls this directly
no outgoing calls
no test coverage detected