mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-27 03:34:10 +00:00
with prompt layer test
This commit is contained in:
parent
7d99e09a4a
commit
b2e72e52e4
3 changed files with 63 additions and 15 deletions
|
@ -1,5 +1,5 @@
|
|||
#### What this does ####
|
||||
# On success, logs events to Helicone
|
||||
# On success, logs events to Promptlayer
|
||||
import dotenv, os
|
||||
import requests
|
||||
import requests
|
||||
|
@ -7,32 +7,34 @@ import requests
|
|||
dotenv.load_dotenv() # Loading env variables using dotenv
|
||||
import traceback
|
||||
|
||||
class PromptLayer:
|
||||
class PromptLayerLogger:
|
||||
# Class variables or attributes
|
||||
def __init__(self):
|
||||
# Instance variables
|
||||
self.key = os.getenv("PROMPTLAYER_API_KEY")
|
||||
|
||||
def log_event(self, model, response_obj, start_time, end_time, print_verbose):
|
||||
def log_event(self, kwargs, response_obj, start_time, end_time, print_verbose):
|
||||
# Method definition
|
||||
try:
|
||||
print_verbose(
|
||||
f"Prompt Layer Logging - Enters logging function for model {model}"
|
||||
f"Prompt Layer Logging - Enters logging function for model {kwargs}"
|
||||
)
|
||||
|
||||
request_response = requests.post(
|
||||
"https://api.promptlayer.com/rest/track-request",
|
||||
"https://api.promptlayer.com/rest/track-request",
|
||||
json={
|
||||
"function_name": "openai.Completion.create",
|
||||
"kwargs": {"engine": "text-ada-001", "prompt": "My name is"},
|
||||
"function_name": "openai.ChatCompletion.create",
|
||||
"kwargs": kwargs,
|
||||
"tags": ["hello", "world"],
|
||||
"request_response": response_obj,
|
||||
"request_start_time": start_time,
|
||||
"request_end_time": end_time,
|
||||
"prompt_id": "<PROMPT ID>",
|
||||
"prompt_input_variables": "<Dictionary of variables for prompt>",
|
||||
"prompt_version":1,
|
||||
"api_key": self.key
|
||||
"request_response": dict(response_obj), # TODO: Check if we need a dict
|
||||
"request_start_time": int(start_time.timestamp()),
|
||||
"request_end_time": int(end_time.timestamp()),
|
||||
"api_key": self.key,
|
||||
# Optional params for PromptLayer
|
||||
# "prompt_id": "<PROMPT ID>",
|
||||
# "prompt_input_variables": "<Dictionary of variables for prompt>",
|
||||
# "prompt_version":1,
|
||||
|
||||
},
|
||||
)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue