Skip to content

Commit

Permalink
Add /api/health-check
Browse files Browse the repository at this point in the history
  • Loading branch information
andychase committed Oct 7, 2024
1 parent a957264 commit 33fec2d
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions pages/api/health-check.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { NextRequest, NextResponse } from 'next/server';
import handler from './chat'; // Adjust this path based on the actual location of 'chat'

// Declare the function as an edge runtime function
export const config = {
runtime: 'edge', // Ensure this is executed in Edge runtime
};

export default async function healthCheck(req: NextRequest) {
try {
const mockReq: Request = new Request("http://example.org", {
method: 'POST',
headers: {
'content-type': 'application/json',
'x-ms-client-principal-name': 'test-principal', // These can be mock values
'x-ms-token-aad-access-token': 'mock-token',
},
body: JSON.stringify({
model: {
id: 'gpt-35-turbo',
name: 'GPT-3.5',
maxLength: 12000,
tokenLimit: 4000,
},
messages: [
{
role: 'user',
content: 'test',
},
],
key: '',
prompt: "You are Gov Chat an AI Assistant using Azure OpenAI. Follow the user's instructions carefully. Respond using markdown.",
temperature: 0.5,
}),
});

// Simulate the handler with the mock request
const mockRes = await handler(mockReq);

// Return a successful health check
return NextResponse.json({ message: 'Health check passed successfully' }, { status: 200 });
} catch (error: unknown) {
if (error instanceof Error) {
console.error('Health check failed:', error.message);
return NextResponse.json({ message: 'Health check failed', error: error.message }, { status: 500 });
} else {
// Handle cases where a non-Error object is thrown
return NextResponse.json({ message: 'Unknown error occurred' }, { status: 500 });
}
}
}

0 comments on commit 33fec2d

Please sign in to comment.