Skip to content

Commit

Permalink
fix(llama): send as reply
Browse files Browse the repository at this point in the history
  • Loading branch information
sdip15fa committed Feb 16, 2024
1 parent 96fbc05 commit 987d190
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions commands/llama.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,29 @@ const execute = async (client: Client, msg: Message, args: string[]) => {
);
const authHeader = `Basic ${encodedCredentials}`;

// Call Llama model with the obtained text
const response = await axios.get<{ response: string }>(config.cf_worker.url, {
params: {
...(!messages?.length && { prompt: text }),
...(messages?.length && {
messages: encodeURIComponent(JSON.stringify(messages)),
}),
},
headers: {
Authorization: authHeader,
},
});

try {
// Call Llama model with the obtained text
const response = await axios.get<{ response: string }>(
config.cf_worker.url,
{
params: {
...(!messages?.length && { prompt: text }),
...(messages?.length && {
messages: encodeURIComponent(JSON.stringify(messages)),
}),
},
headers: {
Authorization: authHeader,
},
},
);

// Send the response back to the user
await client.sendMessage(chatId, `Llama: ${response.data.response}`);
try {
await msg.reply(chatId, `Llama: ${response.data.response}`);
} catch {
await client.sendMessage(chatId, `Llama: ${response.data.response}`);
}
} catch {
await client.sendMessage(chatId, "LLaMA generation failed.");
}
Expand Down

0 comments on commit 987d190

Please sign in to comment.