Update api/index.js
Browse files- api/index.js +40 -4
api/index.js
CHANGED
@@ -70,11 +70,46 @@ const router = AutoRouter({
|
|
70 |
finally: [corsify, logger],
|
71 |
});
|
72 |
|
73 |
-
//
|
74 |
-
router.get('/', () => json({
|
75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
|
77 |
-
//
|
78 |
router.get(config.API_PREFIX + '/v1/models', withAuth, () =>
|
79 |
json({
|
80 |
object: 'list',
|
@@ -96,6 +131,7 @@ router.get(config.API_PREFIX + '/v1/models', withAuth, () =>
|
|
96 |
})
|
97 |
);
|
98 |
|
|
|
99 |
router.post(config.API_PREFIX + '/v1/chat/completions', withAuth, (req) => handleCompletion(req));
|
100 |
|
101 |
async function GrpcToPieces(models, message, rules, stream, temperature, top_p) {
|
|
|
70 |
finally: [corsify, logger],
|
71 |
});
|
72 |
|
73 |
+
// 根路由
|
74 |
+
router.get('/', () => json({
|
75 |
+
service: "AI Chat Completion Proxy",
|
76 |
+
usage: {
|
77 |
+
endpoint: "/v1/chat/completions",
|
78 |
+
method: "POST",
|
79 |
+
headers: {
|
80 |
+
"Content-Type": "application/json",
|
81 |
+
"Authorization": "Bearer YOUR_API_KEY"
|
82 |
+
},
|
83 |
+
body: {
|
84 |
+
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",
|
85 |
+
messages: [
|
86 |
+
{ role: "system", content: "You are a helpful assistant." },
|
87 |
+
{ role: "user", content: "Hello, who are you?" }
|
88 |
+
],
|
89 |
+
stream: false,
|
90 |
+
temperature: 0.7,
|
91 |
+
top_p: 1
|
92 |
+
}
|
93 |
+
},
|
94 |
+
availableModels: [
|
95 |
+
"gpt-4o-mini",
|
96 |
+
"gpt-4o",
|
97 |
+
"gpt-4-turbo",
|
98 |
+
"gpt-4",
|
99 |
+
"gpt-3.5-turbo",
|
100 |
+
"claude-3-sonnet@20240229",
|
101 |
+
"claude-3-opus@20240229",
|
102 |
+
"claude-3-haiku@20240307",
|
103 |
+
"claude-3-5-sonnet@20240620",
|
104 |
+
"gemini-1.5-flash",
|
105 |
+
"gemini-1.5-pro",
|
106 |
+
"chat-bison",
|
107 |
+
"codechat-bison"
|
108 |
+
],
|
109 |
+
note: "Replace YOUR_API_KEY with your actual API key."
|
110 |
+
}));
|
111 |
|
112 |
+
// models 路由
|
113 |
router.get(config.API_PREFIX + '/v1/models', withAuth, () =>
|
114 |
json({
|
115 |
object: 'list',
|
|
|
131 |
})
|
132 |
);
|
133 |
|
134 |
+
// chat 路由
|
135 |
router.post(config.API_PREFIX + '/v1/chat/completions', withAuth, (req) => handleCompletion(req));
|
136 |
|
137 |
async function GrpcToPieces(models, message, rules, stream, temperature, top_p) {
|