From 12693e94f1c1da8203db4b4a32c8a9eed980b38f Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Tue, 27 Aug 2024 18:14:40 -0700 Subject: [PATCH] docs add tg ai rerank docs --- docs/my-website/docs/providers/togetherai.md | 84 +++++++++++++++++--- 1 file changed, 74 insertions(+), 10 deletions(-) diff --git a/docs/my-website/docs/providers/togetherai.md b/docs/my-website/docs/providers/togetherai.md index e069ea69dda..584efd91ab6 100644 --- a/docs/my-website/docs/providers/togetherai.md +++ b/docs/my-website/docs/providers/togetherai.md @@ -1,3 +1,6 @@ +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + # Together AI LiteLLM supports all models on Together AI. @@ -204,21 +207,82 @@ print(response) } ``` -## Advanced Usage -Instead of using the `custom_llm_provider` arg to specify which provider you're using (e.g. together ai), you can just pass the provider name as part of the model name, and LiteLLM will parse it out. +## Rerank -Expected format: `/` +### Usage -e.g. completion(model="together_ai/togethercomputer/Llama-2-7B-32K-Instruct", ...) + + + + ```python -from litellm import completion +from litellm import rerank +import os -# set env variable -os.environ["TOGETHERAI_API_KEY"] = "" +os.environ["TOGETHERAI_API_KEY"] = "sk-.." -messages = [{"role": "user", "content": "Write me a poem about the blue sky"}] +query = "What is the capital of the United States?" +documents = [ + "Carson City is the capital city of the American state of Nevada.", + "The Commonwealth of the Northern Mariana Islands is a group of islands in the Pacific Ocean. Its capital is Saipan.", + "Washington, D.C. is the capital of the United States.", + "Capital punishment has existed in the United States since before it was a country.", +] -completion(model="together_ai/togethercomputer/Llama-2-7B-32K-Instruct", messages=messages) -``` \ No newline at end of file +response = rerank( + model="together_ai/rerank-english-v3.0", + query=query, + documents=documents, + top_n=3, +) +print(response) +``` + + + + +LiteLLM provides an cohere api compatible `/rerank` endpoint for Rerank calls. + +**Setup** + +Add this to your litellm proxy config.yaml + +```yaml +model_list: + - model_name: Salesforce/Llama-Rank-V1 + litellm_params: + model: together_ai/Salesforce/Llama-Rank-V1 + api_key: os.environ/TOGETHERAI_API_KEY +``` + +Start litellm + +```bash +litellm --config /path/to/config.yaml + +# RUNNING on http://0.0.0.0:4000 +``` + +Test request + +```bash +curl http://0.0.0.0:4000/rerank \ + -H "Authorization: Bearer sk-1234" \ + -H "Content-Type: application/json" \ + -d '{ + "model": "Salesforce/Llama-Rank-V1", + "query": "What is the capital of the United States?", + "documents": [ + "Carson City is the capital city of the American state of Nevada.", + "The Commonwealth of the Northern Mariana Islands is a group of islands in the Pacific Ocean. Its capital is Saipan.", + "Washington, D.C. is the capital of the United States.", + "Capital punishment has existed in the United States since before it was a country." + ], + "top_n": 3 + }' +``` + + + \ No newline at end of file