forked from phoenix/litellm-mirror
now a py package
This commit is contained in:
parent
e037318344
commit
2eff53e177
12 changed files with 147 additions and 0 deletions
BIN
dist/litellm-0.1.0-py3-none-any.whl
vendored
Normal file
BIN
dist/litellm-0.1.0-py3-none-any.whl
vendored
Normal file
Binary file not shown.
BIN
dist/litellm-0.1.0.tar.gz
vendored
Normal file
BIN
dist/litellm-0.1.0.tar.gz
vendored
Normal file
Binary file not shown.
12
litellm.egg-info/PKG-INFO
Normal file
12
litellm.egg-info/PKG-INFO
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
Metadata-Version: 2.1
|
||||||
|
Name: litellm
|
||||||
|
Version: 0.1.0
|
||||||
|
Summary: Library to easily interface with LLM API providers
|
||||||
|
Home-page: UNKNOWN
|
||||||
|
Author: Ishaan Jaffer
|
||||||
|
License: UNKNOWN
|
||||||
|
Platform: UNKNOWN
|
||||||
|
License-File: LICENSE
|
||||||
|
|
||||||
|
UNKNOWN
|
||||||
|
|
10
litellm.egg-info/SOURCES.txt
Normal file
10
litellm.egg-info/SOURCES.txt
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
LICENSE
|
||||||
|
README.md
|
||||||
|
setup.py
|
||||||
|
litellm/__init__.py
|
||||||
|
litellm/main.py
|
||||||
|
litellm.egg-info/PKG-INFO
|
||||||
|
litellm.egg-info/SOURCES.txt
|
||||||
|
litellm.egg-info/dependency_links.txt
|
||||||
|
litellm.egg-info/requires.txt
|
||||||
|
litellm.egg-info/top_level.txt
|
1
litellm.egg-info/dependency_links.txt
Normal file
1
litellm.egg-info/dependency_links.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
3
litellm.egg-info/requires.txt
Normal file
3
litellm.egg-info/requires.txt
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
openai
|
||||||
|
cohere
|
||||||
|
os
|
1
litellm.egg-info/top_level.txt
Normal file
1
litellm.egg-info/top_level.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
litellm
|
1
litellm/__init__.py
Normal file
1
litellm/__init__.py
Normal file
|
@ -0,0 +1 @@
|
||||||
|
from .main import * # Import all the symbols from main.py
|
103
litellm/main.py
Normal file
103
litellm/main.py
Normal file
|
@ -0,0 +1,103 @@
|
||||||
|
import os, openai, cohere
|
||||||
|
|
||||||
|
####### COMPLETION MODELS ###################
|
||||||
|
open_ai_chat_completion_models = [
|
||||||
|
'gpt-3.5-turbo',
|
||||||
|
'gpt-4'
|
||||||
|
]
|
||||||
|
open_ai_text_completion_models = [
|
||||||
|
'text-davinci-003'
|
||||||
|
]
|
||||||
|
|
||||||
|
cohere_models = [
|
||||||
|
'command-nightly',
|
||||||
|
]
|
||||||
|
|
||||||
|
####### EMBEDDING MODELS ###################
|
||||||
|
open_ai_embedding_models = [
|
||||||
|
'text-embedding-ada-002'
|
||||||
|
]
|
||||||
|
|
||||||
|
#############################################
|
||||||
|
|
||||||
|
|
||||||
|
####### COMPLETION ENDPOINTS ################
|
||||||
|
#############################################
|
||||||
|
def completion(model, messages, azure=False):
|
||||||
|
if azure == True:
|
||||||
|
# azure configs
|
||||||
|
openai.api_type = "azure"
|
||||||
|
openai.api_base = os.environ.get("AZURE_API_BASE")
|
||||||
|
openai.api_version = os.environ.get("AZURE_API_VERSION")
|
||||||
|
openai.api_key = os.environ.get("AZURE_API_KEY")
|
||||||
|
response = openai.ChatCompletion.create(
|
||||||
|
engine=model,
|
||||||
|
messages = messages
|
||||||
|
)
|
||||||
|
elif model in cohere_models:
|
||||||
|
cohere_key = os.environ.get("COHERE_API_KEY")
|
||||||
|
co = cohere.Client(cohere_key)
|
||||||
|
prompt = " ".join([message["content"] for message in messages])
|
||||||
|
response = co.generate(
|
||||||
|
model=model,
|
||||||
|
prompt = prompt
|
||||||
|
)
|
||||||
|
new_response = {
|
||||||
|
"choices": [
|
||||||
|
{
|
||||||
|
"finish_reason": "stop",
|
||||||
|
"index": 0,
|
||||||
|
"message": {
|
||||||
|
"content": response[0],
|
||||||
|
"role": "assistant"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
response = new_response
|
||||||
|
|
||||||
|
elif model in open_ai_chat_completion_models:
|
||||||
|
openai.api_type = "openai"
|
||||||
|
openai.api_base = "https://api.openai.com/v1"
|
||||||
|
openai.api_version = None
|
||||||
|
openai.api_key = os.environ.get("OPENAI_API_KEY")
|
||||||
|
response = openai.ChatCompletion.create(
|
||||||
|
model=model,
|
||||||
|
messages = messages
|
||||||
|
)
|
||||||
|
elif model in open_ai_text_completion_models:
|
||||||
|
openai.api_type = "openai"
|
||||||
|
openai.api_base = "https://api.openai.com/v1"
|
||||||
|
openai.api_version = None
|
||||||
|
openai.api_key = os.environ.get("OPENAI_API_KEY")
|
||||||
|
prompt = " ".join([message["content"] for message in messages])
|
||||||
|
response = openai.Completion.create(
|
||||||
|
model=model,
|
||||||
|
prompt = prompt
|
||||||
|
)
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### EMBEDDING ENDPOINTS ####################
|
||||||
|
def embedding(model, input=[], azure=False):
|
||||||
|
if azure == True:
|
||||||
|
# azure configs
|
||||||
|
openai.api_type = "azure"
|
||||||
|
openai.api_base = os.environ.get("AZURE_API_BASE")
|
||||||
|
openai.api_version = os.environ.get("AZURE_API_VERSION")
|
||||||
|
openai.api_key = os.environ.get("AZURE_API_KEY")
|
||||||
|
response = openai.Embedding.create(input=input, engine=model)
|
||||||
|
elif model in open_ai_embedding_models:
|
||||||
|
openai.api_type = "openai"
|
||||||
|
openai.api_base = "https://api.openai.com/v1"
|
||||||
|
openai.api_version = None
|
||||||
|
openai.api_key = os.environ.get("OPENAI_API_KEY")
|
||||||
|
response = openai.Embedding.create(input=input, model=model)
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
#############################################
|
||||||
|
#############################################
|
||||||
|
|
16
setup.py
Normal file
16
setup.py
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
from setuptools import setup, find_packages
|
||||||
|
|
||||||
|
setup(
|
||||||
|
name='litellm',
|
||||||
|
version='0.1.00',
|
||||||
|
description='Library to easily interface with LLM API providers',
|
||||||
|
author='Ishaan Jaffer',
|
||||||
|
packages=[
|
||||||
|
'litellm'
|
||||||
|
],
|
||||||
|
install_requires=[
|
||||||
|
'openai',
|
||||||
|
'cohere',
|
||||||
|
'os'
|
||||||
|
],
|
||||||
|
)
|
Loading…
Add table
Add a link
Reference in a new issue