mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 18:54:30 +00:00
fix install error
This commit is contained in:
parent
cf5c3c61db
commit
6ec91227cd
2 changed files with 30 additions and 7 deletions
|
@ -7,10 +7,10 @@ sys.path.insert(0, os.path.abspath('../..')) # Adds the parent directory to the
|
||||||
import pytest
|
import pytest
|
||||||
import litellm
|
import litellm
|
||||||
from litellm import embedding, completion
|
from litellm import embedding, completion
|
||||||
from infisical import InfisicalClient
|
# from infisical import InfisicalClient
|
||||||
|
|
||||||
# litellm.set_verbose = True
|
# litellm.set_verbose = True
|
||||||
litellm.secret_manager_client = InfisicalClient(token=os.environ["INFISICAL_TOKEN"])
|
# litellm.secret_manager_client = InfisicalClient(token=os.environ["INFISICAL_TOKEN"])
|
||||||
|
|
||||||
user_message = "Hello, whats the weather in San Francisco??"
|
user_message = "Hello, whats the weather in San Francisco??"
|
||||||
messages = [{ "content": user_message,"role": "user"}]
|
messages = [{ "content": user_message,"role": "user"}]
|
||||||
|
@ -26,6 +26,7 @@ def test_completion_claude():
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
pytest.fail(f"Error occurred: {e}")
|
pytest.fail(f"Error occurred: {e}")
|
||||||
|
|
||||||
|
test_completion_claude()
|
||||||
def test_completion_claude_stream():
|
def test_completion_claude_stream():
|
||||||
try:
|
try:
|
||||||
messages = [
|
messages = [
|
||||||
|
@ -39,6 +40,7 @@ def test_completion_claude_stream():
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
pytest.fail(f"Error occurred: {e}")
|
pytest.fail(f"Error occurred: {e}")
|
||||||
|
|
||||||
|
test_completion_claude_stream()
|
||||||
def test_completion_hf_api():
|
def test_completion_hf_api():
|
||||||
try:
|
try:
|
||||||
user_message = "write some code to find the sum of two numbers"
|
user_message = "write some code to find the sum of two numbers"
|
||||||
|
|
|
@ -5,6 +5,8 @@ import litellm, openai
|
||||||
import random, uuid, requests
|
import random, uuid, requests
|
||||||
import datetime, time
|
import datetime, time
|
||||||
import tiktoken
|
import tiktoken
|
||||||
|
import pkg_resources
|
||||||
|
from pkg_resources import DistributionNotFound, VersionConflict
|
||||||
encoding = tiktoken.get_encoding("cl100k_base")
|
encoding = tiktoken.get_encoding("cl100k_base")
|
||||||
from .integrations.helicone import HeliconeLogger
|
from .integrations.helicone import HeliconeLogger
|
||||||
from .integrations.aispend import AISpendLogger
|
from .integrations.aispend import AISpendLogger
|
||||||
|
@ -36,13 +38,32 @@ def print_verbose(print_statement):
|
||||||
####### Package Import Handler ###################
|
####### Package Import Handler ###################
|
||||||
import importlib
|
import importlib
|
||||||
import subprocess
|
import subprocess
|
||||||
def install_and_import(package):
|
def install_and_import(package: str):
|
||||||
try:
|
try:
|
||||||
importlib.import_module(package)
|
# Import the module
|
||||||
except ImportError:
|
module = importlib.import_module(package)
|
||||||
|
|
||||||
|
# Get the package's information
|
||||||
|
dist = pkg_resources.get_distribution(package)
|
||||||
|
required = [req for req in pkg_resources.get_distribution(package).requires()]
|
||||||
|
|
||||||
|
# Check if there are dependencies
|
||||||
|
if required:
|
||||||
|
for req in required:
|
||||||
|
install_and_import(req.project_name)
|
||||||
|
else:
|
||||||
|
print(f"{package} has been successfully installed with no dependencies.")
|
||||||
|
|
||||||
|
except (DistributionNotFound, ImportError):
|
||||||
print(f"{package} is not installed. Installing...")
|
print(f"{package} is not installed. Installing...")
|
||||||
subprocess.call([sys.executable, '-m', 'pip', 'install', package])
|
subprocess.call([sys.executable, "-m", "pip", "install", package])
|
||||||
|
globals()[package] = importlib.import_module(package)
|
||||||
|
except VersionConflict as vc:
|
||||||
|
print(f"Detected version conflict for {package}. Upgrading...")
|
||||||
|
subprocess.call([sys.executable, "-m", "pip", "install", "--upgrade", package])
|
||||||
|
globals()[package] = importlib.import_module(package)
|
||||||
finally:
|
finally:
|
||||||
|
if package not in globals().keys():
|
||||||
globals()[package] = importlib.import_module(package)
|
globals()[package] = importlib.import_module(package)
|
||||||
##################################################
|
##################################################
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue