forked from Patrick-Davis-MSFT/chatbot-ui
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes to move away from edge endpoint
- Loading branch information
Showing
4 changed files
with
84 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,39 @@ | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
import handler from './chat'; // Adjust this path based on the actual location of 'chat' | ||
import { NextApiRequest, NextApiResponse } from 'next'; | ||
import handler from './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) { | ||
export default async function healthCheck(req: NextApiRequest, res: NextApiResponse) { | ||
try { | ||
const mockReq: Request = new Request("http://example.org", { | ||
method: 'POST', | ||
headers: { | ||
'content-type': 'application/json', | ||
'x-ms-client-principal-name': req.headers?.get("x-ms-client-principal-name") || '', | ||
'x-ms-token-aad-access-token': req.headers?.get("x-ms-token-aad-access-token") || '', | ||
'x-ms-client-principal-id': req.headers?.get("x-ms-client-principal-id") || '' | ||
req.method = 'POST'; | ||
req.headers['content-type'] = 'application/json'; | ||
req.headers['x-ms-client-principal-name'] = req.headers['x-ms-client-principal-name'] || ''; | ||
req.headers['x-ms-token-aad-access-token'] = req.headers['x-ms-token-aad-access-token'] || ''; | ||
req.headers['x-ms-client-principal-id'] = req.headers['x-ms-client-principal-id'] || ''; | ||
|
||
req.body = { | ||
model: { | ||
id: 'gpt-35-turbo', | ||
name: 'GPT-3.5', | ||
maxLength: 12000, | ||
tokenLimit: 4000, | ||
}, | ||
body: JSON.stringify({ | ||
model: { | ||
id: 'gpt-35-turbo', | ||
name: 'GPT-3.5', | ||
maxLength: 12000, | ||
tokenLimit: 4000, | ||
messages: [ | ||
{ | ||
role: 'user', | ||
content: 'test', | ||
}, | ||
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:Response = await handler(mockReq); | ||
if (mockRes.status != 200) { | ||
throw Error("Status not 200") | ||
} | ||
|
||
// Return a successful health check | ||
return NextResponse.json({ message: 'Health check passed successfully' }, { status: 200 }); | ||
], | ||
key: '', | ||
prompt: "You are Gov Chat an AI Assistant using Azure OpenAI. Follow the user's instructions carefully. Respond using markdown.", | ||
temperature: 0.5, | ||
}; | ||
await handler(req, res); | ||
} 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 }); | ||
return res.status(500).send(error.message ); | ||
} else { | ||
// Handle cases where a non-Error object is thrown | ||
return NextResponse.json({ message: 'Unknown error occurred' }, { status: 500 }); | ||
return res.status(500).send('Unknown error occurred'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters