forked from phoenix/litellm-mirror
with litellm.token
This commit is contained in:
parent
6a520fbade
commit
76bf07b347
2 changed files with 24 additions and 9 deletions
|
@ -6,6 +6,7 @@ success_callback: List[str] = []
|
||||||
failure_callback: List[str] = []
|
failure_callback: List[str] = []
|
||||||
set_verbose = False
|
set_verbose = False
|
||||||
email: Optional[str] = None # for hosted dashboard. Learn more - https://docs.litellm.ai/docs/debugging/hosted_debugging
|
email: Optional[str] = None # for hosted dashboard. Learn more - https://docs.litellm.ai/docs/debugging/hosted_debugging
|
||||||
|
token: Optional[str] = None # for hosted dashboard. Learn more - https://docs.litellm.ai/docs/debugging/hosted_debugging
|
||||||
telemetry = True
|
telemetry = True
|
||||||
max_tokens = 256 # OpenAI Defaults
|
max_tokens = 256 # OpenAI Defaults
|
||||||
retry = True
|
retry = True
|
||||||
|
|
|
@ -5,6 +5,7 @@ import litellm, openai
|
||||||
import random, uuid, requests
|
import random, uuid, requests
|
||||||
import datetime, time
|
import datetime, time
|
||||||
import tiktoken
|
import tiktoken
|
||||||
|
import uuid
|
||||||
|
|
||||||
encoding = tiktoken.get_encoding("cl100k_base")
|
encoding = tiktoken.get_encoding("cl100k_base")
|
||||||
import importlib.metadata
|
import importlib.metadata
|
||||||
|
@ -299,12 +300,19 @@ def client(original_function):
|
||||||
): # just run once to check if user wants to send their data anywhere - PostHog/Sentry/Slack/etc.
|
): # just run once to check if user wants to send their data anywhere - PostHog/Sentry/Slack/etc.
|
||||||
try:
|
try:
|
||||||
global callback_list, add_breadcrumb, user_logger_fn
|
global callback_list, add_breadcrumb, user_logger_fn
|
||||||
if litellm.email is not None or os.getenv("LITELLM_EMAIL", None) is not None: # add to input, success and failure callbacks if user is using hosted product
|
if litellm.email is not None or os.getenv("LITELLM_EMAIL", None) is not None or litellm.token is not None or os.getenv("LITELLM_TOKEN", None): # add to input, success and failure callbacks if user is using hosted product
|
||||||
get_all_keys()
|
get_all_keys()
|
||||||
if "lite_debugger" not in callback_list:
|
if "lite_debugger" not in callback_list:
|
||||||
litellm.input_callback.append("lite_debugger")
|
litellm.input_callback.append("lite_debugger")
|
||||||
litellm.success_callback.append("lite_debugger")
|
litellm.success_callback.append("lite_debugger")
|
||||||
litellm.failure_callback.append("lite_debugger")
|
litellm.failure_callback.append("lite_debugger")
|
||||||
|
else:
|
||||||
|
# create a litellm token for users
|
||||||
|
litellm.token = get_or_generate_uuid()
|
||||||
|
litellm.input_callback.append("lite_debugger")
|
||||||
|
litellm.success_callback.append("lite_debugger")
|
||||||
|
litellm.failure_callback.append("lite_debugger")
|
||||||
|
|
||||||
if (
|
if (
|
||||||
len(litellm.input_callback) > 0
|
len(litellm.input_callback) > 0
|
||||||
or len(litellm.success_callback) > 0
|
or len(litellm.success_callback) > 0
|
||||||
|
@ -683,7 +691,7 @@ def set_callbacks(callback_list):
|
||||||
global sentry_sdk_instance, capture_exception, add_breadcrumb, posthog, slack_app, alerts_channel, heliconeLogger, aispendLogger, berrispendLogger, supabaseClient, liteDebuggerClient, llmonitorLogger
|
global sentry_sdk_instance, capture_exception, add_breadcrumb, posthog, slack_app, alerts_channel, heliconeLogger, aispendLogger, berrispendLogger, supabaseClient, liteDebuggerClient, llmonitorLogger
|
||||||
try:
|
try:
|
||||||
for callback in callback_list:
|
for callback in callback_list:
|
||||||
print(f"callback: {callback}")
|
print_verbose(f"callback: {callback}")
|
||||||
if callback == "sentry":
|
if callback == "sentry":
|
||||||
try:
|
try:
|
||||||
import sentry_sdk
|
import sentry_sdk
|
||||||
|
@ -743,7 +751,10 @@ def set_callbacks(callback_list):
|
||||||
print(f"instantiating supabase")
|
print(f"instantiating supabase")
|
||||||
supabaseClient = Supabase()
|
supabaseClient = Supabase()
|
||||||
elif callback == "lite_debugger":
|
elif callback == "lite_debugger":
|
||||||
print(f"instantiating lite_debugger")
|
print_verbose(f"instantiating lite_debugger")
|
||||||
|
if litellm.token:
|
||||||
|
liteDebuggerClient = LiteDebugger(email=litellm.token)
|
||||||
|
else:
|
||||||
liteDebuggerClient = LiteDebugger(email=litellm.email)
|
liteDebuggerClient = LiteDebugger(email=litellm.email)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise e
|
raise e
|
||||||
|
@ -1108,7 +1119,7 @@ def get_all_keys(llm_provider=None):
|
||||||
try:
|
try:
|
||||||
global last_fetched_at
|
global last_fetched_at
|
||||||
# if user is using hosted product -> instantiate their env with their hosted api keys - refresh every 5 minutes
|
# if user is using hosted product -> instantiate their env with their hosted api keys - refresh every 5 minutes
|
||||||
user_email = os.getenv("LITELLM_EMAIL") or litellm.email
|
user_email = os.getenv("LITELLM_EMAIL") or litellm.email or litellm.token or os.getenv("LITELLM_TOKEN")
|
||||||
if user_email:
|
if user_email:
|
||||||
time_delta = 0
|
time_delta = 0
|
||||||
if last_fetched_at != None:
|
if last_fetched_at != None:
|
||||||
|
@ -1136,7 +1147,7 @@ def get_model_list():
|
||||||
global last_fetched_at
|
global last_fetched_at
|
||||||
try:
|
try:
|
||||||
# if user is using hosted product -> get their updated model list
|
# if user is using hosted product -> get their updated model list
|
||||||
user_email = os.getenv("LITELLM_EMAIL") or litellm.email
|
user_email = os.getenv("LITELLM_EMAIL") or litellm.email or litellm.token or os.getenv("LITELLM_TOKEN")
|
||||||
if user_email:
|
if user_email:
|
||||||
# Commented out the section checking time delta
|
# Commented out the section checking time delta
|
||||||
# time_delta = 0
|
# time_delta = 0
|
||||||
|
@ -1319,9 +1330,7 @@ def safe_crash_reporting(model=None, exception=None, custom_llm_provider=None):
|
||||||
}
|
}
|
||||||
threading.Thread(target=litellm_telemetry, args=(data, )).start()
|
threading.Thread(target=litellm_telemetry, args=(data, )).start()
|
||||||
|
|
||||||
|
def get_or_generate_uuid():
|
||||||
def litellm_telemetry(data):
|
|
||||||
# Load or generate the UUID
|
|
||||||
uuid_file = "litellm_uuid.txt"
|
uuid_file = "litellm_uuid.txt"
|
||||||
try:
|
try:
|
||||||
# Try to open the file and load the UUID
|
# Try to open the file and load the UUID
|
||||||
|
@ -1340,7 +1349,12 @@ def litellm_telemetry(data):
|
||||||
except:
|
except:
|
||||||
# [Non-Blocking Error]
|
# [Non-Blocking Error]
|
||||||
return
|
return
|
||||||
|
return uuid_value
|
||||||
|
|
||||||
|
|
||||||
|
def litellm_telemetry(data):
|
||||||
|
# Load or generate the UUID
|
||||||
|
uuid_value = get_or_generate_uuid()
|
||||||
try:
|
try:
|
||||||
# Prepare the data to send to litellm logging api
|
# Prepare the data to send to litellm logging api
|
||||||
payload = {
|
payload = {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue