diff --git a/docs/my-website/docs/assistants.md b/docs/my-website/docs/assistants.md new file mode 100644 index 000000000..b7441ef53 --- /dev/null +++ b/docs/my-website/docs/assistants.md @@ -0,0 +1,183 @@ +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + +# Assistants API + +Covers Threads, Messages, Assistants. + +LiteLLM currently covers: +- Get Assistants +- Create Thread +- Get Thread +- Add Messages +- Get Messages +- Run Thread + +## Quick Start + +Call an existing Assistant. + +- Get the Assistant + +- Create a Thread when a user starts a conversation. + +- Add Messages to the Thread as the user asks questions. + +- Run the Assistant on the Thread to generate a response by calling the model and the tools. + + + + +**Get the Assistant** + +```python +from litellm import get_assistants, aget_assistants +import os + +os.environ["OPENAI_API_KEY"] = "sk-.." + +assistants = get_assistants(custom_llm_provider="openai") + +### ASYNC USAGE ### +# assistants = await aget_assistants(custom_llm_provider="openai") +``` + +**Create a Thread** + +```python +from litellm import create_thread, acreate_thread +import os + +os.environ["OPENAI_API_KEY"] = "sk-.." + +new_thread = create_thread( + custom_llm_provider="openai", + messages=[{"role": "user", "content": "Hey, how's it going?"}], # type: ignore + ) + +### ASYNC USAGE ### +# new_thread = await acreate_thread(custom_llm_provider="openai",messages=[{"role": "user", "content": "Hey, how's it going?"}]) +``` + +**Add Messages to the Thread** + +```python +from litellm import create_thread, get_thread, aget_thread, add_message, a_add_message +import os + +os.environ["OPENAI_API_KEY"] = "sk-.." + +## CREATE A THREAD +_new_thread = create_thread( + custom_llm_provider="openai", + messages=[{"role": "user", "content": "Hey, how's it going?"}], # type: ignore + ) + +## OR retrieve existing thread +received_thread = get_thread( + custom_llm_provider="openai", + thread_id=_new_thread.id, + ) + +### ASYNC USAGE ### +# received_thread = await aget_thread(custom_llm_provider="openai", thread_id=_new_thread.id,) + +## ADD MESSAGE TO THREAD +message = {"role": "user", "content": "Hey, how's it going?"} +added_message = add_message( + thread_id=_new_thread.id, custom_llm_provider="openai", **message + ) + +### ASYNC USAGE ### +# added_message = await a_add_message(thread_id=_new_thread.id, custom_llm_provider="openai", **message) +``` + +**Run the Assistant on the Thread** + +```python +from litellm import get_assistants, create_thread, add_message, run_thread, arun_thread +import os + +os.environ["OPENAI_API_KEY"] = "sk-.." +assistants = get_assistants(custom_llm_provider="openai") + +## get the first assistant ### +assistant_id = assistants.data[0].id + +## GET A THREAD +_new_thread = create_thread( + custom_llm_provider="openai", + messages=[{"role": "user", "content": "Hey, how's it going?"}], # type: ignore + ) + +## ADD MESSAGE +message = {"role": "user", "content": "Hey, how's it going?"} +added_message = add_message( + thread_id=_new_thread.id, custom_llm_provider="openai", **message + ) + +## 🚨 RUN THREAD +response = run_thread( + custom_llm_provider="openai", thread_id=thread_id, assistant_id=assistant_id + ) + +### ASYNC USAGE ### +# response = await arun_thread(custom_llm_provider="openai", thread_id=thread_id, assistant_id=assistant_id) + +print(f"run_thread: {run_thread}") +``` + + + +```bash +$ export OPENAI_API_KEY="sk-..." + +$ litellm + +# RUNNING on http://0.0.0.0:4000 +``` + +**Get the Assistant** + +```bash +curl "http://0.0.0.0:4000/v1/assistants?order=desc&limit=20" \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer sk-1234" \ +``` + +**Create a Thread** + +```bash +curl http://0.0.0.0:4000/v1/threads \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer sk-1234" \ + -d '' +``` + +**Add Messages to the Thread** + +```bash +curl http://0.0.0.0:4000/v1/threads/{thread_id}/messages \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer sk-1234" \ + -d '{ + "role": "user", + "content": "How does AI work? Explain it in simple terms." + }' +``` + +**Run the Assistant on the Thread** + +```bash +curl http://0.0.0.0:4000/v1/threads/thread_abc123/runs \ + -H "Authorization: Bearer sk-1234" \ + -H "Content-Type: application/json" \ + -d '{ + "assistant_id": "asst_abc123" + }' +``` + + + + +## [👉 Proxy API Reference](https://litellm-api.up.railway.app/#/assistants) diff --git a/docs/my-website/docs/text_to_speech.md b/docs/my-website/docs/text_to_speech.md new file mode 100644 index 000000000..f4adf15eb --- /dev/null +++ b/docs/my-website/docs/text_to_speech.md @@ -0,0 +1,87 @@ +# Text to Speech + +## Quick Start + +```python +from pathlib import Path +from litellm import speech +import os + +os.environ["OPENAI_API_KEY"] = "sk-.." + +speech_file_path = Path(__file__).parent / "speech.mp3" +response = speech( + model="openai/tts-1", + voice="alloy", + input="the quick brown fox jumped over the lazy dogs", + api_base=None, + api_key=None, + organization=None, + project=None, + max_retries=1, + timeout=600, + client=None, + optional_params={}, + ) +response.stream_to_file(speech_file_path) +``` + +## Async Usage + +```python +from litellm import aspeech +from pathlib import Path +import os, asyncio + +os.environ["OPENAI_API_KEY"] = "sk-.." + +async def test_async_speech(): + speech_file_path = Path(__file__).parent / "speech.mp3" + response = await litellm.aspeech( + model="openai/tts-1", + voice="alloy", + input="the quick brown fox jumped over the lazy dogs", + api_base=None, + api_key=None, + organization=None, + project=None, + max_retries=1, + timeout=600, + client=None, + optional_params={}, + ) + response.stream_to_file(speech_file_path) + +asyncio.run(test_async_speech()) +``` + +## Proxy Usage + +LiteLLM provides an openai-compatible `/audio/speech` endpoint for Text-to-speech calls. + +```bash +curl http://0.0.0.0:4000/v1/audio/speech \ + -H "Authorization: Bearer sk-1234" \ + -H "Content-Type: application/json" \ + -d '{ + "model": "tts-1", + "input": "The quick brown fox jumped over the lazy dog.", + "voice": "alloy" + }' \ + --output speech.mp3 +``` + +**Setup** + +```bash +- model_name: tts + litellm_params: + model: openai/tts-1 + api_key: os.environ/OPENAI_API_KEY +``` + +```bash +litellm --config /path/to/config.yaml + +# RUNNING on http://0.0.0.0:4000 +``` \ No newline at end of file diff --git a/docs/my-website/sidebars.js b/docs/my-website/sidebars.js index d5c6f8bc2..1c7805f42 100644 --- a/docs/my-website/sidebars.js +++ b/docs/my-website/sidebars.js @@ -100,13 +100,15 @@ const sidebars = { }, { type: "category", - label: "Embedding(), Moderation(), Image Generation(), Audio Transcriptions()", + label: "Embedding(), Image Generation(), Assistants(), Moderation(), Audio Transcriptions(), TTS()", items: [ "embedding/supported_embedding", "embedding/async_embedding", "embedding/moderation", "image_generation", - "audio_transcription" + "audio_transcription", + "text_to_speech", + "assistants" ], }, { diff --git a/litellm/main.py b/litellm/main.py index ad14ec92b..4083695c4 100644 --- a/litellm/main.py +++ b/litellm/main.py @@ -4120,7 +4120,7 @@ def transcription( or litellm.api_key or litellm.azure_key or get_secret("AZURE_API_KEY") - ) + ) # type: ignore response = azure_chat_completions.audio_transcriptions( model=model, diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index 3d0b4b587..4d02f4524 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -5337,6 +5337,11 @@ async def get_assistants( fastapi_response: Response, user_api_key_dict: UserAPIKeyAuth = Depends(user_api_key_auth), ): + """ + Returns a list of assistants. + + API Reference docs - https://platform.openai.com/docs/api-reference/assistants/listAssistants + """ global proxy_logging_obj data: Dict = {} try: @@ -5463,6 +5468,11 @@ async def create_threads( fastapi_response: Response, user_api_key_dict: UserAPIKeyAuth = Depends(user_api_key_auth), ): + """ + Create a thread. + + API Reference - https://platform.openai.com/docs/api-reference/threads/createThread + """ global proxy_logging_obj data: Dict = {} try: @@ -5590,6 +5600,11 @@ async def get_thread( fastapi_response: Response, user_api_key_dict: UserAPIKeyAuth = Depends(user_api_key_auth), ): + """ + Retrieves a thread. + + API Reference - https://platform.openai.com/docs/api-reference/threads/getThread + """ global proxy_logging_obj data: Dict = {} try: @@ -5714,6 +5729,11 @@ async def add_messages( fastapi_response: Response, user_api_key_dict: UserAPIKeyAuth = Depends(user_api_key_auth), ): + """ + Create a message. + + API Reference - https://platform.openai.com/docs/api-reference/messages/createMessage + """ global proxy_logging_obj data: Dict = {} try: @@ -5841,6 +5861,11 @@ async def get_messages( fastapi_response: Response, user_api_key_dict: UserAPIKeyAuth = Depends(user_api_key_auth), ): + """ + Returns a list of messages for a given thread. + + API Reference - https://platform.openai.com/docs/api-reference/messages/listMessages + """ global proxy_logging_obj data: Dict = {} try: @@ -5964,6 +5989,11 @@ async def run_thread( fastapi_response: Response, user_api_key_dict: UserAPIKeyAuth = Depends(user_api_key_auth), ): + """ + Create a run. + + API Reference: https://platform.openai.com/docs/api-reference/runs/createRun + """ global proxy_logging_obj data: Dict = {} try: