Spaces:
Paused
Paused
Update api/index.js
Browse files- api/index.js +46 -11
api/index.js
CHANGED
|
@@ -91,14 +91,49 @@ const logger = (res, req) => {
|
|
| 91 |
console.log(req.method, res.status, req.url, Date.now() - req.start, 'ms');
|
| 92 |
};
|
| 93 |
const router = AutoRouter({
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
});
|
| 98 |
// Router路径
|
| 99 |
-
router.get('/', () => json({
|
| 100 |
-
|
| 101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
json({
|
| 103 |
object: 'list',
|
| 104 |
data: [
|
|
@@ -107,10 +142,10 @@ router.get(config.API_PREFIX + '/v1/models', () =>
|
|
| 107 |
{ id: "gpt-4-turbo", object: "model", owned_by: "pieces-os" },
|
| 108 |
{ id: "gpt-4", object: "model", owned_by: "pieces-os" },
|
| 109 |
{ id: "gpt-3.5-turbo", object: "model", owned_by: "pieces-os" },
|
| 110 |
-
{ id: "claude-3-sonnet
|
| 111 |
-
{ id: "claude-3-opus
|
| 112 |
-
{ id: "claude-3-haiku
|
| 113 |
-
{ id: "claude-3-5-sonnet
|
| 114 |
{ id: "gemini-1.5-flash", object: "model", owned_by: "pieces-os" },
|
| 115 |
{ id: "gemini-1.5-pro", object: "model", owned_by: "pieces-os" },
|
| 116 |
{ id: "chat-bison", object: "model", owned_by: "pieces-os" },
|
|
@@ -118,7 +153,7 @@ router.get(config.API_PREFIX + '/v1/models', () =>
|
|
| 118 |
],
|
| 119 |
})
|
| 120 |
);
|
| 121 |
-
router.post(config.API_PREFIX + '/v1/chat/completions', (req) => handleCompletion(req));
|
| 122 |
|
| 123 |
async function GrpcToPieces(inputModel,OriginModel,message, rules, stream, temperature, top_p) {
|
| 124 |
// 在非GPT类型的模型中,temperature和top_p是无效的
|
|
|
|
| 91 |
console.log(req.method, res.status, req.url, Date.now() - req.start, 'ms');
|
| 92 |
};
|
| 93 |
const router = AutoRouter({
|
| 94 |
+
before: [preflight], // 只保留 CORS preflight 检查
|
| 95 |
+
missing: () => error(404, '404 not found.'),
|
| 96 |
+
finally: [corsify, logger],
|
| 97 |
});
|
| 98 |
// Router路径
|
| 99 |
+
router.get('/', () => json({
|
| 100 |
+
service: "AI Chat Completion Proxy",
|
| 101 |
+
usage: {
|
| 102 |
+
endpoint: "/v1/chat/completions",
|
| 103 |
+
method: "POST",
|
| 104 |
+
headers: {
|
| 105 |
+
"Content-Type": "application/json",
|
| 106 |
+
"Authorization": "Bearer YOUR_API_KEY"
|
| 107 |
+
},
|
| 108 |
+
body: {
|
| 109 |
+
model: "One of: gpt-4o-mini, gpt-4o, gpt-4-turbo, gpt-4, gpt-3.5-turbo, claude-3-sonnet-20240229, claude-3-opus-20240229, claude-3-haiku-20240307, claude-3-5-sonnet-20240620, gemini-1.5-flash, gemini-1.5-pro, chat-bison, codechat-bison",
|
| 110 |
+
messages: [
|
| 111 |
+
{ role: "system", content: "You are a helpful assistant." },
|
| 112 |
+
{ role: "user", content: "Hello, who are you?" }
|
| 113 |
+
],
|
| 114 |
+
stream: false,
|
| 115 |
+
temperature: 0.7,
|
| 116 |
+
top_p: 1
|
| 117 |
+
}
|
| 118 |
+
},
|
| 119 |
+
availableModels: [
|
| 120 |
+
"gpt-4o-mini",
|
| 121 |
+
"gpt-4o",
|
| 122 |
+
"gpt-4-turbo",
|
| 123 |
+
"gpt-4",
|
| 124 |
+
"gpt-3.5-turbo",
|
| 125 |
+
"claude-3-sonnet-20240229",
|
| 126 |
+
"claude-3-opus-20240229",
|
| 127 |
+
"claude-3-haiku-20240307",
|
| 128 |
+
"claude-3-5-sonnet-20240620",
|
| 129 |
+
"gemini-1.5-flash",
|
| 130 |
+
"gemini-1.5-pro",
|
| 131 |
+
"chat-bison",
|
| 132 |
+
"codechat-bison"
|
| 133 |
+
],
|
| 134 |
+
note: "Replace YOUR_API_KEY with your actual API key."
|
| 135 |
+
}));
|
| 136 |
+
router.get(config.API_PREFIX + '/v1/models', withAuth, () =>
|
| 137 |
json({
|
| 138 |
object: 'list',
|
| 139 |
data: [
|
|
|
|
| 142 |
{ id: "gpt-4-turbo", object: "model", owned_by: "pieces-os" },
|
| 143 |
{ id: "gpt-4", object: "model", owned_by: "pieces-os" },
|
| 144 |
{ id: "gpt-3.5-turbo", object: "model", owned_by: "pieces-os" },
|
| 145 |
+
{ id: "claude-3-sonnet-20240229", object: "model", owned_by: "pieces-os" },
|
| 146 |
+
{ id: "claude-3-opus-20240229", object: "model", owned_by: "pieces-os" },
|
| 147 |
+
{ id: "claude-3-haiku-20240307", object: "model", owned_by: "pieces-os" },
|
| 148 |
+
{ id: "claude-3-5-sonnet-20240620", object: "model", owned_by: "pieces-os" },
|
| 149 |
{ id: "gemini-1.5-flash", object: "model", owned_by: "pieces-os" },
|
| 150 |
{ id: "gemini-1.5-pro", object: "model", owned_by: "pieces-os" },
|
| 151 |
{ id: "chat-bison", object: "model", owned_by: "pieces-os" },
|
|
|
|
| 153 |
],
|
| 154 |
})
|
| 155 |
);
|
| 156 |
+
router.post(config.API_PREFIX + '/v1/chat/completions', withAuth, (req) => handleCompletion(req));
|
| 157 |
|
| 158 |
async function GrpcToPieces(inputModel,OriginModel,message, rules, stream, temperature, top_p) {
|
| 159 |
// 在非GPT类型的模型中,temperature和top_p是无效的
|