Using Secrets
This guide shows how to use TypeScript, a 3rd party search service, and secrets to create a script that augments documents with information from the web.
The goal is to create a script that will augment an existing document with information gathered from the web.
Tavily Search
Tavily is a search service optimized for LLMs that provides a REST API.
The REST API can be invoked using JavaScript fetch and requires an API key.
The script uses the TAVILY_API_KEY
which will have to be declare in the script using this function.
We define a function tavilySearch
in TypeScript that wraps the fetch
call and we add type annotations to provide
a nice editing experience.
The full source looks like this:
Question -> Search -> Augment
The script is split into 3 phases:
- run a prompt to generate a question based on the document content
- use Tavily to generate an answer to the question
- run a prompt to augment the document with the answer
The secret TAVILY_API_KEY
needed by Tavily is declared in the script
function call.
Also make sure to add it to your .env
file.
The tavilySearch
function is imported using a dynamic import.
The full source looks like this: