You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.4 KiB

11 months ago
  1. // You must execute this example from within the example folder.
  2. const AIbitat = require("../index.js");
  3. const { cli } = require("../plugins/cli.js");
  4. const { NodeHtmlMarkdown } = require("node-html-markdown");
  5. require("dotenv").config({ path: `../../../../.env.development` });
  6. const Agent = {
  7. HUMAN: "🧑",
  8. AI: "🤖",
  9. };
  10. const aibitat = new AIbitat({
  11. provider: "openai",
  12. model: "gpt-4o",
  13. })
  14. .use(cli.plugin())
  15. .function({
  16. name: "aibitat-documentations",
  17. description: "The documentation about aibitat AI project.",
  18. parameters: {
  19. type: "object",
  20. properties: {},
  21. },
  22. handler: async () => {
  23. return await fetch(
  24. "https://raw.githubusercontent.com/wladiston/aibitat/main/README.md"
  25. )
  26. .then((res) => res.text())
  27. .then((html) => NodeHtmlMarkdown.translate(html))
  28. .catch((e) => {
  29. console.error(e.message);
  30. return "FAILED TO FETCH";
  31. });
  32. },
  33. })
  34. .agent(Agent.HUMAN, {
  35. interrupt: "ALWAYS",
  36. role: "You are a human assistant.",
  37. })
  38. .agent(Agent.AI, {
  39. functions: ["aibitat-documentations"],
  40. });
  41. async function main() {
  42. if (!process.env.OPEN_AI_KEY)
  43. throw new Error(
  44. "This example requires a valid OPEN_AI_KEY in the env.development file"
  45. );
  46. await aibitat.start({
  47. from: Agent.HUMAN,
  48. to: Agent.AI,
  49. content: `Please, talk about the documentation of AIbitat.`,
  50. });
  51. }
  52. main();