tool.types.ts 1.0 KB

1234567891011121314151617181920212223242526272829
  1. import { Effect, Schema } from "effect"
  2. import { LLM } from "../src"
  3. import * as OpenAIChat from "../src/protocols/openai-chat"
  4. import { tool } from "../src/tool"
  5. const request = LLM.request({
  6. model: OpenAIChat.model({ id: "gpt-4o-mini", apiKey: "fixture" }),
  7. prompt: "Use the tool.",
  8. })
  9. const executable = tool({
  10. description: "Get weather.",
  11. parameters: Schema.Struct({ city: Schema.String }),
  12. success: Schema.Struct({ forecast: Schema.String }),
  13. execute: (input) => Effect.succeed({ forecast: input.city }),
  14. })
  15. const schemaOnly = tool({
  16. description: "Get weather.",
  17. parameters: Schema.Struct({ city: Schema.String }),
  18. success: Schema.Struct({ forecast: Schema.String }),
  19. })
  20. LLM.stream({ request, tools: { executable } })
  21. LLM.generate({ request, tools: { executable }, stopWhen: LLM.stepCountIs(2) })
  22. LLM.stream({ request, tools: { schemaOnly }, toolExecution: "none" })
  23. // @ts-expect-error Handler-less tools can only be passed with toolExecution: "none".
  24. LLM.stream({ request, tools: { schemaOnly } })