(req: NextRequest)
| 17 | }); |
| 18 | |
| 19 | export async function POST(req: NextRequest) { |
| 20 | console.log('CREATE THREAD started'); |
| 21 | if (req.method === 'POST') { |
| 22 | try { |
| 23 | const data = await req.json(); |
| 24 | const inputMessage = data.inputmessage; |
| 25 | |
| 26 | // Überprüfen, ob die Eingabemessage vorhanden und ein String ist |
| 27 | if (!inputMessage || typeof inputMessage !== 'string') { |
| 28 | throw new Error('inputmessage is missing or not a string'); |
| 29 | } |
| 30 | |
| 31 | // Thread erstellen |
| 32 | const thread = await openai.beta.threads.create({ |
| 33 | messages: [ |
| 34 | { |
| 35 | role: "user", |
| 36 | content: inputMessage, |
| 37 | }, |
| 38 | ], |
| 39 | }); |
| 40 | const threadId = thread.id; |
| 41 | console.log('Thread ID:', threadId); |
| 42 | |
| 43 | return NextResponse.json({ threadId }); |
| 44 | } catch (error) { |
| 45 | console.error('Error:', error); |
| 46 | return NextResponse.json({ error: (error as Error).message }); |
| 47 | } |
| 48 | } else { |
| 49 | return NextResponse.json({ error: 'Method not allowed' }); |
| 50 | } |
| 51 | } |
nothing calls this directly
no outgoing calls
no test coverage detected