mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-08 03:08:45 +00:00
(feat) add ability to view POST requests from litellm.completion()
This commit is contained in:
parent
a7222f257c
commit
7c317b78eb
5 changed files with 23 additions and 9 deletions
|
|
@ -129,6 +129,7 @@ class AzureChatCompletion(BaseLLM):
|
|||
"headers": headers,
|
||||
"api_version": api_version,
|
||||
"api_base": api_base,
|
||||
"complete_input_dict": data,
|
||||
},
|
||||
)
|
||||
if acompletion is True:
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ def completion(
|
|||
logging_obj.pre_call(
|
||||
input=prompt,
|
||||
api_key=api_key,
|
||||
additional_args={"complete_input_dict": data},
|
||||
additional_args={"complete_input_dict": data, "headers": headers, "api_base": completion_url},
|
||||
)
|
||||
## COMPLETION CALL
|
||||
response = requests.post(
|
||||
|
|
|
|||
|
|
@ -202,7 +202,7 @@ class OpenAIChatCompletion(BaseLLM):
|
|||
logging_obj.pre_call(
|
||||
input=messages,
|
||||
api_key=api_key,
|
||||
additional_args={"headers": headers, "api_base": api_base, "acompletion": acompletion, "data": data},
|
||||
additional_args={"headers": headers, "api_base": api_base, "acompletion": acompletion, "complete_input_dict": data},
|
||||
)
|
||||
|
||||
try:
|
||||
|
|
@ -450,7 +450,7 @@ class OpenAITextCompletion(BaseLLM):
|
|||
logging_obj.pre_call(
|
||||
input=messages,
|
||||
api_key=api_key,
|
||||
additional_args={"headers": headers, "api_base": api_base, "data": data},
|
||||
additional_args={"headers": headers, "api_base": api_base, "complete_input_dict": data},
|
||||
)
|
||||
if acompletion == True:
|
||||
if optional_params.get("stream", False):
|
||||
|
|
|
|||
|
|
@ -126,10 +126,10 @@ def completion(
|
|||
|
||||
## LOGGING
|
||||
logging_obj.pre_call(
|
||||
input=prompt,
|
||||
api_key=api_key,
|
||||
additional_args={"complete_input_dict": data},
|
||||
)
|
||||
input=prompt,
|
||||
api_key=api_key,
|
||||
additional_args={"complete_input_dict": data, "headers": headers, "api_base": api_base},
|
||||
)
|
||||
## COMPLETION CALL
|
||||
if (
|
||||
"stream_tokens" in optional_params
|
||||
|
|
|
|||
|
|
@ -492,7 +492,6 @@ class Logging:
|
|||
|
||||
def pre_call(self, input, api_key, model=None, additional_args={}):
|
||||
# Log the exact input to the LLM API
|
||||
print_verbose(f"Logging Details Pre-API Call for call id {self.litellm_call_id}")
|
||||
litellm.error_logs['PRE_CALL'] = locals()
|
||||
try:
|
||||
# print_verbose(f"logging pre call for model: {self.model} with call type: {self.call_type}")
|
||||
|
|
@ -506,7 +505,21 @@ class Logging:
|
|||
self.model_call_details["model"] = model
|
||||
|
||||
# User Logging -> if you pass in a custom logging function
|
||||
print_verbose(f"MODEL CALL INPUT: {self.model_call_details}\n\n")
|
||||
headers = additional_args.get("headers", {})
|
||||
data = additional_args.get("complete_input_dict", {})
|
||||
api_base = additional_args.get("api_base", "")
|
||||
masked_headers = {k: v[:-5] + '*' * 5 if len(v) > 5 else v for k, v in headers.items()}
|
||||
formatted_headers = " ".join([f"-H '{k}: {v}'" for k, v in masked_headers.items()])
|
||||
curl_command = (
|
||||
"\n\nPOST Request Sent from LiteLLM:\ncurl -X POST \\"
|
||||
f" {api_base} \\\n"
|
||||
f" {formatted_headers} \\\n"
|
||||
f" -d '{json.dumps(data)}'\n"
|
||||
)
|
||||
if api_base == "":
|
||||
curl_command = self.model_call_details
|
||||
|
||||
print_verbose(f"\033[92m{curl_command}\033[0m\n")
|
||||
if self.logger_fn and callable(self.logger_fn):
|
||||
try:
|
||||
self.logger_fn(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue