anything-llm/server/utils/agents/aibitat/example/beginner-chat.js
Timothy Carambat a5bb77f97a
Agent support for @agent default agent inside workspace chat (#1093)
V1 of agent support via built-in `@agent` that can be invoked alongside normal workspace RAG chat.
2024-04-16 10:50:10 -07:00

57 lines
1.4 KiB
JavaScript

// You must execute this example from within the example folder.
const AIbitat = require("../index.js");
const { cli } = require("../plugins/cli.js");
const { NodeHtmlMarkdown } = require("node-html-markdown");
require("dotenv").config({ path: `../../../../.env.development` });
const Agent = {
HUMAN: "🧑",
AI: "🤖",
};
const aibitat = new AIbitat({
provider: "openai",
model: "gpt-3.5-turbo",
})
.use(cli.plugin())
.function({
name: "aibitat-documentations",
description: "The documentation about aibitat AI project.",
parameters: {
type: "object",
properties: {},
},
handler: async () => {
return await fetch(
"https://raw.githubusercontent.com/wladiston/aibitat/main/README.md"
)
.then((res) => res.text())
.then((html) => NodeHtmlMarkdown.translate(html))
.catch((e) => {
console.error(e.message);
return "FAILED TO FETCH";
});
},
})
.agent(Agent.HUMAN, {
interrupt: "ALWAYS",
role: "You are a human assistant.",
})
.agent(Agent.AI, {
functions: ["aibitat-documentations"],
});
async function main() {
if (!process.env.OPEN_AI_KEY)
throw new Error(
"This example requires a valid OPEN_AI_KEY in the env.development file"
);
await aibitat.start({
from: Agent.HUMAN,
to: Agent.AI,
content: `Please, talk about the documentation of AIbitat.`,
});
}
main();