Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update api version from v0 to v1 #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require("dotenv").config();
// Secrets
const MENDABLE_KEY = process.env["MENDABLE_API_KEY"];
const DISCORD_TOKEN = process.env["DISCORD_TOKEN"];
const BOT_ID = process.env["BOT_ID"]; //
const BOT_ID = process.env["BOT_ID"]; //

const client = new Client({
intents: [
Expand All @@ -18,9 +18,8 @@ const client = new Client({
const historyMap = new Map();
const threadToChannelMap = new Map();


async function createConversation() {
const url = "https://api.mendable.ai/v0/newConversation";
const url = "https://api.mendable.ai/v1/newConversation";

const data = {
api_key: `${MENDABLE_KEY}`,
Expand All @@ -39,7 +38,7 @@ async function createConversation() {
}

async function getAnswerAndSources(question, history = []) {
const url = "https://api.mendable.ai/v0/mendableChat";
const url = "https://api.mendable.ai/v1/mendableChat";
let conversation_id = null;
if (history.length === 0) {
conversation_id = await createConversation();
Expand Down Expand Up @@ -130,9 +129,7 @@ client.on("messageCreate", async (message) => {
historyMap.set(threadId, history); // Use thread ID to store history instead of channel ID

if (message.channel.isThread()) {
await message.reply(
`${message.author}\n\n${answer}`
);
await message.reply(`${message.author}\n\n${answer}`);
if (sources) {
await message.reply(`Sources:\n${sources}`);
}
Expand Down