mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-28 04:04:31 +00:00
test(test_api_key_param.py): cleanup
This commit is contained in:
parent
6eb7205aba
commit
9641cd0602
1 changed files with 43 additions and 43 deletions
|
@ -1,53 +1,53 @@
|
||||||
#### What this tests ####
|
# #### What this tests ####
|
||||||
# This tests the ability to set api key's via the params instead of as environment variables
|
# # This tests the ability to set api key's via the params instead of as environment variables
|
||||||
|
|
||||||
import sys, os
|
# import sys, os
|
||||||
import traceback
|
# import traceback
|
||||||
|
|
||||||
sys.path.insert(
|
# sys.path.insert(
|
||||||
0, os.path.abspath("../..")
|
# 0, os.path.abspath("../..")
|
||||||
) # Adds the parent directory to the system path
|
# ) # Adds the parent directory to the system path
|
||||||
import litellm
|
# import litellm
|
||||||
from litellm import embedding, completion
|
# from litellm import embedding, completion
|
||||||
|
|
||||||
litellm.set_verbose = False
|
# litellm.set_verbose = False
|
||||||
|
|
||||||
|
|
||||||
def logger_fn(model_call_object: dict):
|
# def logger_fn(model_call_object: dict):
|
||||||
print(f"model call details: {model_call_object}")
|
# print(f"model call details: {model_call_object}")
|
||||||
|
|
||||||
|
|
||||||
user_message = "Hello, how are you?"
|
# user_message = "Hello, how are you?"
|
||||||
messages = [{"content": user_message, "role": "user"}]
|
# messages = [{"content": user_message, "role": "user"}]
|
||||||
|
|
||||||
## Test 1: Setting key dynamically
|
# ## Test 1: Setting key dynamically
|
||||||
temp_key = os.environ.get("ANTHROPIC_API_KEY", "")
|
# temp_key = os.environ.get("ANTHROPIC_API_KEY", "")
|
||||||
os.environ["ANTHROPIC_API_KEY"] = "bad-key"
|
# os.environ["ANTHROPIC_API_KEY"] = "bad-key"
|
||||||
# test on openai completion call
|
# # test on openai completion call
|
||||||
try:
|
# try:
|
||||||
response = completion(
|
# response = completion(
|
||||||
model="claude-instant-1",
|
# model="claude-instant-1",
|
||||||
messages=messages,
|
# messages=messages,
|
||||||
logger_fn=logger_fn,
|
# logger_fn=logger_fn,
|
||||||
api_key=temp_key,
|
# api_key=temp_key,
|
||||||
)
|
# )
|
||||||
print(f"response: {response}")
|
# print(f"response: {response}")
|
||||||
except:
|
# except:
|
||||||
print(f"error occurred: {traceback.format_exc()}")
|
# print(f"error occurred: {traceback.format_exc()}")
|
||||||
pass
|
# pass
|
||||||
os.environ["ANTHROPIC_API_KEY"] = temp_key
|
# os.environ["ANTHROPIC_API_KEY"] = temp_key
|
||||||
|
|
||||||
|
|
||||||
## Test 2: Setting key via __init__ params
|
# ## Test 2: Setting key via __init__ params
|
||||||
litellm.anthropic_key = os.environ.get("ANTHROPIC_API_KEY", "")
|
# litellm.anthropic_key = os.environ.get("ANTHROPIC_API_KEY", "")
|
||||||
os.environ.pop("ANTHROPIC_API_KEY")
|
# os.environ.pop("ANTHROPIC_API_KEY")
|
||||||
# test on openai completion call
|
# # test on openai completion call
|
||||||
try:
|
# try:
|
||||||
response = completion(
|
# response = completion(
|
||||||
model="claude-instant-1", messages=messages, logger_fn=logger_fn
|
# model="claude-instant-1", messages=messages, logger_fn=logger_fn
|
||||||
)
|
# )
|
||||||
print(f"response: {response}")
|
# print(f"response: {response}")
|
||||||
except:
|
# except:
|
||||||
print(f"error occurred: {traceback.format_exc()}")
|
# print(f"error occurred: {traceback.format_exc()}")
|
||||||
pass
|
# pass
|
||||||
os.environ["ANTHROPIC_API_KEY"] = temp_key
|
# os.environ["ANTHROPIC_API_KEY"] = temp_key
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue