Skip to content

API Reference

Learn more about the API reference for embedded function calling.

runWithTools

This wrapper method enables you to do embedded function calling. You pass it the AI binding, model, inputs (messages array and tools array), and optional configurations.

  • ai Ai required
    • The AI binding, such as env.AI.
  • model BaseAiTextGenerationModels required
    • The ID of the model that supports function calling. For example, @hf/nousresearch/hermes-2-pro-mistral-7b.
  • input object required
    • messages RoleScopedChatInput[] required
    • tools AiTextGenerationToolInputWithFunction[] required
  • config object optional
    • streamFinalResponse boolean (default: false) optional
    • maxRecursiveToolRuns number (default: 0) optional
    • strictValidation boolean (default: false) optional
    • verbose boolean (default: false) optional
    • trimFunction function optional - For the trimFunction, you can pass it autoTrimTools, which is another helper method we've devised to automatically choose the correct tools (using an LLM) before sending it off for inference. This means that your final inference call will have fewer input tokens.

createToolsFromOpenAPISpec

This method lets you automatically create tool schemas based on OpenAPI specs, so you don't have to manually write or hardcode the tool schemas. You can pass the OpenAPI spec for any API in JSON or YAML format.

createToolsFromOpenAPISpec has a config input that allows you to perform overrides if you need to provide headers like Authentication or User-Agent.

  • spec string required
    • The OpenAPI specification in either JSON or YAML format, or a URL to a remote OpenAPI specification.
  • config Config optional - Configuration options for the createToolsFromOpenAPISpec function
    • overrides ConfigRule[] required
    • matchPatterns RegExp[] optional
    • options object optional
      • verbose boolean (default: false) optional

Was this helpful?