Update server.js
Browse files
server.js
CHANGED
|
@@ -70,7 +70,28 @@ async function deepseek(sessionId, prompt, r1 = true) {
|
|
| 70 |
}
|
| 71 |
|
| 72 |
async function qwen(sessionId, prompt, selModel = 0) {
|
| 73 |
-
const model = ["@cf/qwen/qwen1.5-0.5b-chat", "@cf/qwen/qwen1.5-1.8b-chat", "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
const sessionFile = getSessionFile(sessionId, 'qwen');
|
| 75 |
let history = [];
|
| 76 |
if (fs.existsSync(sessionFile)) {
|
|
@@ -106,12 +127,13 @@ app.all('/', (_, res) => {
|
|
| 106 |
status['memoryUsage'] =
|
| 107 |
`${utils.formatSize(totalmem - freemem)} / ${utils.formatSize(totalmem)}`
|
| 108 |
res.json({
|
| 109 |
-
ai: [{ 'google': [ 'gemini-1.5-pro' ] }, {'deepseek-ai': [ 'deepseek-r1-distill-qwen-32b', 'deepseek-math-7b-instruct' ]}, {'qwen': ['qwen1.5-0.5b-chat', 'qwen1.5-1.8b-chat', 'qwen1.5-14b-chat-awq', 'qwen1.5-7b-chat-awq']}],
|
| 110 |
uptime: new Date(process.uptime() * 1000).toUTCString().split(' ')[4],
|
| 111 |
status
|
| 112 |
})
|
| 113 |
})
|
| 114 |
|
|
|
|
| 115 |
app.get('/google/gemini-1.5-pro', async (req, res) => {
|
| 116 |
try {
|
| 117 |
const { question, sessionId } = req.query;
|
|
@@ -123,6 +145,39 @@ app.get('/google/gemini-1.5-pro', async (req, res) => {
|
|
| 123 |
}
|
| 124 |
});
|
| 125 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
/* DeepSeek-AI */
|
| 127 |
app.get('/deepseek-ai/deepseek-r1-distill-qwen-32b', async (req, res) => {
|
| 128 |
try {
|
|
@@ -139,7 +194,7 @@ app.get('/depseek-ai/deepseek-math-7b-instruct', async (req, res) => {
|
|
| 139 |
try {
|
| 140 |
const { question, sessionId } = req.query;
|
| 141 |
if (!question || !sessionId) return res.status(400).json({ error: 'Missing parameters' });
|
| 142 |
-
const reply = await
|
| 143 |
res.json({ reply });
|
| 144 |
} catch (error) {
|
| 145 |
res.status(500).json({ error: error.response?.data || error.message });
|
|
|
|
| 70 |
}
|
| 71 |
|
| 72 |
async function qwen(sessionId, prompt, selModel = 0) {
|
| 73 |
+
const model = ["@cf/qwen/qwen1.5-0.5b-chat", "@cf/qwen/qwen1.5-1.8b-chat", "@cf/qwen/qwen1.5-14b-chat-awq", "@cf/qwen/qwen1.5-7b-chat-awq"]
|
| 74 |
+
const sessionFile = getSessionFile(sessionId, 'qwen');
|
| 75 |
+
let history = [];
|
| 76 |
+
if (fs.existsSync(sessionFile)) {
|
| 77 |
+
history = JSON.parse(fs.readFileSync(sessionFile, 'utf8'));
|
| 78 |
+
}
|
| 79 |
+
history.push({ role: 'user', content: prompt });
|
| 80 |
+
|
| 81 |
+
let { data } = await axios.post("https://ai.clauodflare.workers.dev/chat", {
|
| 82 |
+
"model": model[selModel],
|
| 83 |
+
"messages": history
|
| 84 |
+
}).catch(e => e.response);
|
| 85 |
+
|
| 86 |
+
if (!data.success) throw new Error(JSON.stringify(data, null, 2));
|
| 87 |
+
let response = data.data.response
|
| 88 |
+
history.push({ role: 'assistant', content: response });
|
| 89 |
+
fs.writeFileSync(sessionFile, JSON.stringify(history));
|
| 90 |
+
return response;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
async function google(sessionId, prompt, selModel = 0) {
|
| 94 |
+
const model = ["@cf/google/gemma-7b-it", "@cf/google/gemma-7b-it-lora", "@cf/google/gemma-2b-it-lora"]
|
| 95 |
const sessionFile = getSessionFile(sessionId, 'qwen');
|
| 96 |
let history = [];
|
| 97 |
if (fs.existsSync(sessionFile)) {
|
|
|
|
| 127 |
status['memoryUsage'] =
|
| 128 |
`${utils.formatSize(totalmem - freemem)} / ${utils.formatSize(totalmem)}`
|
| 129 |
res.json({
|
| 130 |
+
ai: [{ 'google': [ 'gemini-1.5-pro', 'gemma-7b-it', 'gemma-7b-it-lora', 'gemma-2b-it-lora'] }, {'deepseek-ai': [ 'deepseek-r1-distill-qwen-32b', 'deepseek-math-7b-instruct' ]}, {'qwen': ['qwen1.5-0.5b-chat', 'qwen1.5-1.8b-chat', 'qwen1.5-14b-chat-awq', 'qwen1.5-7b-chat-awq']}],
|
| 131 |
uptime: new Date(process.uptime() * 1000).toUTCString().split(' ')[4],
|
| 132 |
status
|
| 133 |
})
|
| 134 |
})
|
| 135 |
|
| 136 |
+
/* Google */
|
| 137 |
app.get('/google/gemini-1.5-pro', async (req, res) => {
|
| 138 |
try {
|
| 139 |
const { question, sessionId } = req.query;
|
|
|
|
| 145 |
}
|
| 146 |
});
|
| 147 |
|
| 148 |
+
app.get('/google/gemma-7b-it', async (req, res) => {
|
| 149 |
+
try {
|
| 150 |
+
const { question, sessionId } = req.query;
|
| 151 |
+
if (!question || !sessionId) return res.status(400).json({ error: 'Missing parameters' });
|
| 152 |
+
const reply = await google(sessionId, question);
|
| 153 |
+
res.json({ reply });
|
| 154 |
+
} catch (error) {
|
| 155 |
+
res.status(500).json({ error: error.response?.data || error.message });
|
| 156 |
+
}
|
| 157 |
+
});
|
| 158 |
+
|
| 159 |
+
app.get('/google/gemma-7b-it-lora', async (req, res) => {
|
| 160 |
+
try {
|
| 161 |
+
const { question, sessionId } = req.query;
|
| 162 |
+
if (!question || !sessionId) return res.status(400).json({ error: 'Missing parameters' });
|
| 163 |
+
const reply = await gemini(sessionId, question, 1);
|
| 164 |
+
res.json({ reply });
|
| 165 |
+
} catch (error) {
|
| 166 |
+
res.status(500).json({ error: error.response?.data || error.message });
|
| 167 |
+
}
|
| 168 |
+
});
|
| 169 |
+
|
| 170 |
+
app.get('/google/gemma-2b-it-lora', async (req, res) => {
|
| 171 |
+
try {
|
| 172 |
+
const { question, sessionId } = req.query;
|
| 173 |
+
if (!question || !sessionId) return res.status(400).json({ error: 'Missing parameters' });
|
| 174 |
+
const reply = await gemini(sessionId, question, 2);
|
| 175 |
+
res.json({ reply });
|
| 176 |
+
} catch (error) {
|
| 177 |
+
res.status(500).json({ error: error.response?.data || error.message });
|
| 178 |
+
}
|
| 179 |
+
});
|
| 180 |
+
|
| 181 |
/* DeepSeek-AI */
|
| 182 |
app.get('/deepseek-ai/deepseek-r1-distill-qwen-32b', async (req, res) => {
|
| 183 |
try {
|
|
|
|
| 194 |
try {
|
| 195 |
const { question, sessionId } = req.query;
|
| 196 |
if (!question || !sessionId) return res.status(400).json({ error: 'Missing parameters' });
|
| 197 |
+
const reply = await deepseek(sessionId, question, false);
|
| 198 |
res.json({ reply });
|
| 199 |
} catch (error) {
|
| 200 |
res.status(500).json({ error: error.response?.data || error.message });
|