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