diff --git a/.env.example b/.env.example new file mode 100644 index 000000000..7889a204c --- /dev/null +++ b/.env.example @@ -0,0 +1,5 @@ +OPENAI_API_KEY = "" +COHERE_API_KEY = "" +OPENROUTER_API_KEY = "" +OR_SITE_URL = "" +OR_APP_NAME = "LiteLLM Example app" \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..2eea525d8 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env \ No newline at end of file diff --git a/build/lib/litellm/main.py b/build/lib/litellm/main.py index cbefea5a9..053d796e1 100644 --- a/build/lib/litellm/main.py +++ b/build/lib/litellm/main.py @@ -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' @@ -34,6 +49,32 @@ def completion(model, messages, azure=False): engine=model, messages = messages ) + elif "replicate" in model: + prompt = " ".join([message["content"] for message in messages]) + output = replicate.run( + model, + input={ + "prompt": prompt, + }) + print(f"output: {output}") + response = "" + for item in output: + print(f"item: {item}") + response += item + new_response = { + "choices": [ + { + "finish_reason": "stop", + "index": 0, + "message": { + "content": response, + "role": "assistant" + } + } + ] + } + print(f"new response: {new_response}") + response = new_response elif model in cohere_models: cohere_key = os.environ.get("COHERE_API_KEY") co = cohere.Client(cohere_key) @@ -76,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 @@ -99,5 +156,4 @@ def embedding(model, input=[], azure=False): ############################################# -############################################# - +############################################# \ No newline at end of file diff --git a/completion_test.py b/completion_test.py index 4c552ab67..5bb31928b 100644 --- a/completion_test.py +++ b/completion_test.py @@ -1,4 +1,4 @@ -from main import completion +from litellm.main import completion import os ## Configs for Models ## @@ -8,23 +8,27 @@ import os messages = [{ "content": "Hello, how are you?","role": "user"}] -# openai call -response = completion(model="gpt-3.5-turbo", messages=messages) -print("\nOpenAI call") -print(response) +# # openai call +# response = completion(model="gpt-3.5-turbo", messages=messages) +# print("\nOpenAI call") +# print(response) -# azure openai call -response = completion("chatgpt-test", messages, azure=True) -print("\nAzure call") -print(response) +# # azure openai call +# response = completion("chatgpt-test", messages, azure=True) +# print("\nAzure call") +# print(response) -# text davinci openai call -response = completion("text-davinci-003", messages) -print("\nDavinci call") -print(response) +# # text davinci openai call +# response = completion("text-davinci-003", messages) +# print("\nDavinci call") +# print(response) -# cohere call -response = completion("command-nightly", messages) -print("\nCohere call") -print(response) +# # cohere call +# response = completion("command-nightly", messages) +# print("\nCohere call") +# print(response) +# openrouter call +response = completion("google/palm-2-codechat-bison", messages) +print("\OpenRouter call") +print(response) \ No newline at end of file diff --git a/litellm/__pycache__/__init__.cpython-311.pyc b/litellm/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 000000000..9e55d25fc Binary files /dev/null and b/litellm/__pycache__/__init__.cpython-311.pyc differ diff --git a/litellm/__pycache__/main.cpython-311.pyc b/litellm/__pycache__/main.cpython-311.pyc new file mode 100644 index 000000000..042ecd40d Binary files /dev/null and b/litellm/__pycache__/main.cpython-311.pyc differ diff --git a/litellm/main.py b/litellm/main.py index 5f325f259..14de0b02e 100644 --- a/litellm/main.py +++ b/litellm/main.py @@ -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 diff --git a/testos.py b/testos.py new file mode 100644 index 000000000..e69de29bb