Skip to content
This repository has been archived by the owner on Mar 27, 2023. It is now read-only.

Commit

Permalink
Support offical path /v1/chat/completions
Browse files Browse the repository at this point in the history
Fix #34
  • Loading branch information
ayaka14732 committed Mar 18, 2023
1 parent ea9fbae commit 16e9db8
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ app.use((err, req, res, next) => {
next();
});

app.options('/v1/', (req, res) => {
const handleOptions = (req, res) => {
res.setHeader('Access-Control-Max-Age', '1728000').set(corsHeaders).sendStatus(204);
});
};

app.post('/v1/', async (req, res) => {
const handlePost = async (req, res) => {
const contentType = req.headers['content-type'];
if (!contentType || contentType !== 'application/json') {
return res.status(415).set(corsHeaders).type('text/plain').send("Unsupported media type. Use 'application/json' content type");
Expand Down Expand Up @@ -87,7 +87,12 @@ app.post('/v1/', async (req, res) => {
} catch (error) {
res.status(500).set(corsHeaders).type('text/plain').send(error.message);
}
});
};

app.options('/v1/', handleOptions);
app.post('/v1/', handlePost);
app.options('/v1/chat/completions', handleOptions);
app.post('/v1/chat/completions', handlePost);

app.use('*', (req, res) => {
res.status(404).set(corsHeaders).type('text/plain').send('Not found');
Expand Down

0 comments on commit 16e9db8

Please sign in to comment.