09-llm-chat.agi 984 B

123456789101112131415161718192021222324252627
  1. /*---
  2. title: Ask a language model
  3. group: Services
  4. summary: llm.chat and llm.request with replies set in the LLM window.
  5. setup: {"mocks":{"llm":{"mode":"rules","reply":"I am a mock model. You asked: {{prompt}}","rules":[{"match":"Summarize","reply":"The notes say filelib sees user:/ and that scripts only change files when they run."}]}}}
  6. ---*/
  7. requirelib("filelib");
  8. requirelib("llm");
  9. var notes = filelib.readFile("user:/Documents/notes.md");
  10. // llm.chat sends one prompt and returns the reply text.
  11. var summary = llm.chat("Summarize these notes in one sentence:\n" + notes);
  12. // llm.request takes the full message list and returns the
  13. // chat.completion object, as the OpenAI API does.
  14. var full = llm.request([
  15. { role: "system", content: "You answer in one short sentence." },
  16. { role: "user", content: "What is the playground for?" }
  17. ]);
  18. sendJSONResp({
  19. summary: summary,
  20. answer: full.choices[0].message.content,
  21. model: full.model,
  22. usage: llm.usage()
  23. });