sema-tavily 0.1.0

Search the web and extract page content through the Tavily API with typed errors

API reference 4 exports

Exported declarations from this release. Parameter names and descriptions come directly from its source.

tavily/client

Source :19
(tavily/client . opts)
Build a Tavily API client map. Options: :api-key (default: TAVILY_API_KEY env var), :base-url (default "https://api.tavily.com"), :timeout in ms (default 60000). Errors if no key is found.
View source definition
(define (tavily/client . opts)
  "Build a Tavily API client map. Options: :api-key (default: TAVILY_API_KEY env var), :base-url (default \"https://api.tavily.com\"), :timeout in ms (default 60000). Errors if no key is found."
  (let* ((o (if (null? opts) {} (first opts)))
         (api-key (or (get o :api-key) (env "TAVILY_API_KEY"))))
    (when (nil? api-key)
      (error "tavily: no API key — pass {:api-key \"...\"} or set the TAVILY_API_KEY environment variable"))
    {:api-key api-key
     :base-url (string/chop-end (get o :base-url "https://api.tavily.com") "/")
     :timeout (get o :timeout 60000)}))

tavily/extract

Source :87
(tavily/extract client urls . opts)
Extract cleaned content from one or more page URLs. urls is a URL string or a list of URL strings. Returns a map with :results (a list of {:url :raw_content}) and :failed_results. opts is an optional map merged into the request body: :extract_depth (default "basic"), :format ("markdown"), :include_images (#f).
View source definition
(define (tavily/extract client urls . opts)
  "Extract cleaned content from one or more page URLs. urls is a URL string or a list of URL strings. Returns a map with :results (a list of {:url :raw_content}) and :failed_results. opts is an optional map merged into the request body: :extract_depth (default \"basic\"), :format (\"markdown\"), :include_images (#f)."
  (when (or (nil? urls)
            (and (string? urls) (string/empty? (string/trim urls)))
            (and (list? urls) (empty? urls)))
    (error "tavily: extract urls must be a URL string or a non-empty list of URL strings — pass e.g. \"https://example.com\""))
  (let ((o (if (null? opts) {} (first opts))))
    (tavily/request client "POST" "/extract" (assoc o :urls urls)))))

tavily/request

Source :59
(tavily/request client method path body)
Make a raw Tavily API request. method is "GET"/"POST"/..., path an API path ("/search"), body a map (JSON-encoded) or nil. Returns the decoded JSON body ({} when empty); raises on non-2xx with method, path, status, and the API's error message.
View source definition
(define (tavily/request client method path body)
  "Make a raw Tavily API request. method is \"GET\"/\"POST\"/..., path an API path (\"/search\"), body a map (JSON-encoded) or nil. Returns the decoded JSON body ({} when empty); raises on non-2xx with method, path, status, and the API's error message."
  (let* ((url (string-append (:base-url client) (string/ensure-start path "/")))
         (opts {:headers (client-headers client) :timeout (:timeout client)})
         (resp (if (nil? body)
                 (http/request method url opts)
                 (http/request method url opts body)))
         (status (:status resp)))
    (if (and (>= status 200) (< status 300))
      (decode-body (:body resp))
      (error (format "tavily: ~a ~a → ~a: ~a"
                     method path status (api-error-message (:body resp)))))))

tavily/search

Source :76
(tavily/search client query . opts)
Run a web search for a query string. Returns a map with :answer (when requested), :results (a list of {:title :url :content :score}), and :query. opts is an optional map merged into the request body: :search_depth (default "basic"), :max_results (default 5), :topic ("general"), :include_answer (#f), :include_raw_content (#f), :include_domains, :exclude_domains, :time_range.
View source definition
(define (tavily/search client query . opts)
  "Run a web search for a query string. Returns a map with :answer (when requested), :results (a list of {:title :url :content :score}), and :query. opts is an optional map merged into the request body: :search_depth (default \"basic\"), :max_results (default 5), :topic (\"general\"), :include_answer (#f), :include_raw_content (#f), :include_domains, :exclude_domains, :time_range."
  (when (or (nil? query) (not (string? query)) (string/empty? (string/trim query)))
    (error "tavily: search query must be a non-empty string — pass a query such as \"latest AI news\""))
  (let ((o (if (null? opts) {} (first opts))))
    (tavily/request client "POST" "/search" (assoc o :query query))))
About this reference

Generated with sema-reader 1.37.0 without executing package code. These are source declarations; dynamic exports, aliases, and runtime changes are not inferred.

Archive SHA-256 1d77c18aa0ac494026762b1efe01cea23adc7244370be77c689df6e3c5fcf262