latest
This commit is contained in:
@@ -3,7 +3,8 @@ import UTASChatBot from '@/lib/chatbot';
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const { message } = await request.json();
|
||||
// Extract message and userContext from the request
|
||||
const { message, userContext } = await request.json();
|
||||
|
||||
if (!message || typeof message !== 'string') {
|
||||
return NextResponse.json({
|
||||
@@ -15,14 +16,15 @@ export async function POST(request: NextRequest) {
|
||||
const apiKey = process.env.OPENROUTER_API_KEY || '';
|
||||
const chatbot = new UTASChatBot(apiKey);
|
||||
|
||||
// Generate AI response using OpenRouter
|
||||
const response = await chatbot.generateResponse(message);
|
||||
// Generate AI response using OpenRouter or Ollama, passing userContext
|
||||
const response = await chatbot.generateResponse(message, userContext);
|
||||
|
||||
// Log the interaction for demo purposes
|
||||
console.log('UTAS Chat:', {
|
||||
timestamp: new Date().toISOString(),
|
||||
message: message.substring(0, 100),
|
||||
response: response.substring(0, 100)
|
||||
response: response.substring(0, 100),
|
||||
userRole: userContext?.role || 'anonymous'
|
||||
});
|
||||
|
||||
// Return both message and response for backward compatibility
|
||||
|
||||
Reference in New Issue
Block a user