Enhance your OpenAI chat completetions with a simple Exa wrapper that handles search, chunking and prompting.
Install the Exa and OpenAI python libraries
Instantiate Clients
OPENAI_API_KEY
and EXA_API_KEY
with your actual keys.Wrap the OpenAI client
Exa.wrap
method takes your existing OpenAI client and wraps it with Exa-powered RAG capabilities.Call the wrapped client
Example output
End-to-end code example
Example with multiple questions
chat.completions.create()
method allows you to fine-tune the following parameters.
use_exa
specifies whether to include Exa results for a given request:
auto
Exa will intelligently determine whether to include resultsrequired
Exa results will always be includednone
Exa results will never be includednum_results
specifies how many search results Exa should retrieve (defaults to 3 results).
result_max_len
specifies the maximum length of each Exa result (defaults to 2048 characters).
exa.search()
function accepts. You can find a list of all the parameters here.