tool.types.ts 1.1 KB

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