Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LiteLLM - support for Sambanova, Vertex AI, Gemini, Anthropic, Bedrock (100+LLMs) #548

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 5 additions & 16 deletions agents/ten_packages/extension/openai_chatgpt_python/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from dataclasses import dataclass
import random
import requests
from openai import AsyncOpenAI, AsyncAzureOpenAI
import litellm
from openai.types.chat.chat_completion import ChatCompletion

from ten.async_ten_env import AsyncTenEnv
Expand Down Expand Up @@ -46,17 +46,6 @@ class OpenAIChatGPT:
def __init__(self, ten_env: AsyncTenEnv, config: OpenAIChatGPTConfig):
self.config = config
ten_env.log_info(f"OpenAIChatGPT initialized with config: {config.api_key}")
if self.config.vendor == "azure":
self.client = AsyncAzureOpenAI(
api_key=config.api_key,
api_version=self.config.azure_api_version,
azure_endpoint=config.azure_endpoint,
)
ten_env.log_info(
f"Using Azure OpenAI with endpoint: {config.azure_endpoint}, api_version: {config.azure_api_version}"
)
else:
self.client = AsyncOpenAI(api_key=config.api_key, base_url=config.base_url)
self.session = requests.Session()
if config.proxy_url:
proxies = {
Expand All @@ -69,7 +58,7 @@ def __init__(self, ten_env: AsyncTenEnv, config: OpenAIChatGPTConfig):

async def get_chat_completions(self, messages, tools=None) -> ChatCompletion:
req = {
"model": self.config.model,
"model": f"{self.config.vendor}/{self.config.model}",
"messages": [
{
"role": "system",
Expand All @@ -87,15 +76,15 @@ async def get_chat_completions(self, messages, tools=None) -> ChatCompletion:
}

try:
response = await self.client.chat.completions.create(**req)
response = await litellm.acompletion(**req)
except Exception as e:
raise RuntimeError(f"CreateChatCompletion failed, err: {e}") from e

return response

async def get_chat_completions_stream(self, messages, tools=None, listener=None):
req = {
"model": self.config.model,
"model": f"{self.config.vendor}/{self.config.model}",
"messages": [
{
"role": "system",
Expand All @@ -114,7 +103,7 @@ async def get_chat_completions_stream(self, messages, tools=None, listener=None)
}

try:
response = await self.client.chat.completions.create(**req)
response = await litellm.acompletion(**req)
except Exception as e:
raise RuntimeError(f"CreateChatCompletionStream failed, err: {e}") from e

Expand Down