Update cai.js
Browse files
cai.js
CHANGED
|
@@ -59,38 +59,38 @@ setInterval(cleanExpiredSessions, 10 * 60 * 1000);
|
|
| 59 |
|
| 60 |
app.use(express.json());
|
| 61 |
|
| 62 |
-
app.post('/
|
| 63 |
-
const { token,
|
| 64 |
|
| 65 |
try {
|
| 66 |
const session = token ? await getSession(token) : await createSession(DEFAULT_TOKEN);
|
| 67 |
-
const chat = await session.characterAI.createOrContinueChat(characterId,
|
| 68 |
-
const response = await chat.sendAndAwaitResponse(
|
| 69 |
-
res.json({
|
| 70 |
} catch (error) {
|
| 71 |
res.status(500).json({ error: error.message });
|
| 72 |
}
|
| 73 |
});
|
| 74 |
|
| 75 |
-
app.get('/search', async (req, res) => {
|
| 76 |
const { name, token } = req.query;
|
| 77 |
|
| 78 |
try {
|
| 79 |
const session = token ? await getSession(token) : await createSession(DEFAULT_TOKEN);
|
| 80 |
const characters = await session.characterAI.searchCharacters(name);
|
| 81 |
-
res.json({ characters });
|
| 82 |
} catch (error) {
|
| 83 |
res.status(500).json({ error: error.message });
|
| 84 |
}
|
| 85 |
});
|
| 86 |
|
| 87 |
-
app.get('/
|
| 88 |
const { characterId, token } = req.query;
|
| 89 |
|
| 90 |
try {
|
| 91 |
const session = token ? await getSession(token) : await createSession(DEFAULT_TOKEN);
|
| 92 |
const characterInfo = await session.characterAI.fetchCharacterInfo(characterId);
|
| 93 |
-
res.json({ characterInfo });
|
| 94 |
} catch (error) {
|
| 95 |
res.status(500).json({ error: error.message });
|
| 96 |
}
|
|
|
|
| 59 |
|
| 60 |
app.use(express.json());
|
| 61 |
|
| 62 |
+
app.post('/api', async (req, res) => {
|
| 63 |
+
const { token, text, characterId, sessionId } = req.body;
|
| 64 |
|
| 65 |
try {
|
| 66 |
const session = token ? await getSession(token) : await createSession(DEFAULT_TOKEN);
|
| 67 |
+
const chat = await session.characterAI.createOrContinueChat(characterId, sessionId || null);
|
| 68 |
+
const response = await chat.sendAndAwaitResponse(text, true);
|
| 69 |
+
res.json({ result: response });
|
| 70 |
} catch (error) {
|
| 71 |
res.status(500).json({ error: error.message });
|
| 72 |
}
|
| 73 |
});
|
| 74 |
|
| 75 |
+
app.get('/api/chara/search', async (req, res) => {
|
| 76 |
const { name, token } = req.query;
|
| 77 |
|
| 78 |
try {
|
| 79 |
const session = token ? await getSession(token) : await createSession(DEFAULT_TOKEN);
|
| 80 |
const characters = await session.characterAI.searchCharacters(name);
|
| 81 |
+
res.json({ result: characters });
|
| 82 |
} catch (error) {
|
| 83 |
res.status(500).json({ error: error.message });
|
| 84 |
}
|
| 85 |
});
|
| 86 |
|
| 87 |
+
app.get('/api/chara/info', async (req, res) => {
|
| 88 |
const { characterId, token } = req.query;
|
| 89 |
|
| 90 |
try {
|
| 91 |
const session = token ? await getSession(token) : await createSession(DEFAULT_TOKEN);
|
| 92 |
const characterInfo = await session.characterAI.fetchCharacterInfo(characterId);
|
| 93 |
+
res.json({ result: characterInfo });
|
| 94 |
} catch (error) {
|
| 95 |
res.status(500).json({ error: error.message });
|
| 96 |
}
|