mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 10:44:24 +00:00
Added openrouter.ai support
This commit is contained in:
parent
2463dc234b
commit
00c2384a2d
8 changed files with 118 additions and 21 deletions
|
@ -1,4 +1,7 @@
|
|||
import os, openai, cohere
|
||||
import os, openai, cohere, dotenv
|
||||
|
||||
# Loading env variables using dotenv
|
||||
dotenv.load_dotenv()
|
||||
|
||||
####### COMPLETION MODELS ###################
|
||||
open_ai_chat_completion_models = [
|
||||
|
@ -13,6 +16,18 @@ cohere_models = [
|
|||
'command-nightly',
|
||||
]
|
||||
|
||||
openrouter_models = [
|
||||
'google/palm-2-codechat-bison',
|
||||
'google/palm-2-chat-bison',
|
||||
'openai/gpt-3.5-turbo',
|
||||
'openai/gpt-3.5-turbo-16k',
|
||||
'openai/gpt-4-32k',
|
||||
'anthropic/claude-2',
|
||||
'anthropic/claude-instant-v1',
|
||||
'meta-llama/llama-2-13b-chat',
|
||||
'meta-llama/llama-2-70b-chat'
|
||||
]
|
||||
|
||||
####### EMBEDDING MODELS ###################
|
||||
open_ai_embedding_models = [
|
||||
'text-embedding-ada-002'
|
||||
|
@ -102,6 +117,22 @@ def completion(model, messages, azure=False):
|
|||
model=model,
|
||||
prompt = prompt
|
||||
)
|
||||
|
||||
elif model in openrouter_models:
|
||||
openai.api_base = "https://openrouter.ai/api/v1"
|
||||
openai.api_key = os.environ.get("OPENROUTER_API_KEY")
|
||||
|
||||
prompt = " ".join([message["content"] for message in messages])
|
||||
|
||||
response = openai.ChatCompletion.create(
|
||||
model=model,
|
||||
messages=messages,
|
||||
headers={
|
||||
"HTTP-Referer": os.environ.get("OR_SITE_URL"), # To identify your app
|
||||
"X-Title": os.environ.get("OR_APP_NAME")
|
||||
},
|
||||
)
|
||||
reply = response.choices[0].message
|
||||
return response
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue