-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Split `Experimental.RAGTools.build_index` into smaller functions to easier sharing with other packages (`get_chunks`, `get_embeddings`, `get_metadata`) - Added support for Cohere-based RAG re-ranking strategy (and introduced associated `COHERE_API_KEY` global variable and ENV variable)
- Loading branch information
Showing
16 changed files
with
598 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
""" | ||
cohere_api(; | ||
api_key::AbstractString, | ||
endpoint::String, | ||
url::AbstractString="https://api.cohere.ai/v1", | ||
http_kwargs::NamedTuple=NamedTuple(), | ||
kwargs...) | ||
Lightweight wrapper around the Cohere API. See https://cohere.com/docs for more details. | ||
# Arguments | ||
- `api_key`: Your Cohere API key. You can get one from https://dashboard.cohere.com/welcome/register (trial access is for free). | ||
- `endpoint`: The Cohere endpoint to call. | ||
- `url`: The base URL for the Cohere API. Default is `https://api.cohere.ai/v1`. | ||
- `http_kwargs`: Any additional keyword arguments to pass to `HTTP.post`. | ||
- `kwargs`: Any additional keyword arguments to pass to the Cohere API. | ||
""" | ||
function cohere_api(; | ||
api_key::AbstractString, | ||
endpoint::String, | ||
url::AbstractString = "https://api.cohere.ai/v1", | ||
http_kwargs::NamedTuple = NamedTuple(), | ||
kwargs...) | ||
@assert endpoint in ["chat", "generate", "embed", "rerank", "classify"] "Only 'chat', 'generate',`embed`,`rerank`,`classify` Cohere endpoints are supported." | ||
@assert !isempty(api_key) "Cohere `api_key` cannot be empty. Check `PT.COHERE_API_KEY` or pass it as a keyword argument." | ||
## | ||
input_body = Dict(kwargs...) | ||
|
||
# https://api.cohere.ai/v1/rerank | ||
api_url = string(url, "/", endpoint) | ||
resp = HTTP.post(api_url, | ||
PT.auth_header(api_key), | ||
JSON3.write(input_body); http_kwargs...) | ||
body = JSON3.read(resp.body) | ||
return (; response = body) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.