forked from phoenix/litellm-mirror
fixes to embedding logging
This commit is contained in:
parent
2350865a47
commit
8d819daafa
1 changed files with 4 additions and 6 deletions
|
@ -676,9 +676,10 @@ def batch_completion(*args, **kwargs):
|
||||||
@timeout( # type: ignore
|
@timeout( # type: ignore
|
||||||
60
|
60
|
||||||
) ## set timeouts, in case calls hang (e.g. Azure) - default is 60s, override with `force_timeout`
|
) ## set timeouts, in case calls hang (e.g. Azure) - default is 60s, override with `force_timeout`
|
||||||
def embedding(model, input=[], azure=False, force_timeout=60, logger_fn=None):
|
def embedding(model, input=[], azure=False, force_timeout=60, litellm_call_id=None, logger_fn=None):
|
||||||
try:
|
try:
|
||||||
response = None
|
response = None
|
||||||
|
logging = Logging(model=model, messages=input, optional_params={}, litellm_params={"azure": azure, "force_timeout": force_timeout, "logger_fn": logger_fn, "litellm_call_id": litellm_call_id})
|
||||||
if azure == True:
|
if azure == True:
|
||||||
# azure configs
|
# azure configs
|
||||||
openai.api_type = "azure"
|
openai.api_type = "azure"
|
||||||
|
@ -686,7 +687,7 @@ def embedding(model, input=[], azure=False, force_timeout=60, logger_fn=None):
|
||||||
openai.api_version = get_secret("AZURE_API_VERSION")
|
openai.api_version = get_secret("AZURE_API_VERSION")
|
||||||
openai.api_key = get_secret("AZURE_API_KEY")
|
openai.api_key = get_secret("AZURE_API_KEY")
|
||||||
## LOGGING
|
## LOGGING
|
||||||
logging.pre_call(model=model, input=input, azure=azure, logger_fn=logger_fn)
|
logging.pre_call(input=input, api_key=openai.api_key, additional_args={"api_type": openai.api_type, "api_base": openai.api_base, "api_version": openai.api_version})
|
||||||
## EMBEDDING CALL
|
## EMBEDDING CALL
|
||||||
response = openai.Embedding.create(input=input, engine=model)
|
response = openai.Embedding.create(input=input, engine=model)
|
||||||
print_verbose(f"response_value: {str(response)[:50]}")
|
print_verbose(f"response_value: {str(response)[:50]}")
|
||||||
|
@ -696,19 +697,16 @@ def embedding(model, input=[], azure=False, force_timeout=60, logger_fn=None):
|
||||||
openai.api_version = None
|
openai.api_version = None
|
||||||
openai.api_key = get_secret("OPENAI_API_KEY")
|
openai.api_key = get_secret("OPENAI_API_KEY")
|
||||||
## LOGGING
|
## LOGGING
|
||||||
logging(model=model, input=input, azure=azure, logger_fn=logger_fn)
|
logging.pre_call(input=input, api_key=openai.api_key, additional_args={"api_type": openai.api_type, "api_base": openai.api_base, "api_version": openai.api_version})
|
||||||
## EMBEDDING CALL
|
## EMBEDDING CALL
|
||||||
response = openai.Embedding.create(input=input, model=model)
|
response = openai.Embedding.create(input=input, model=model)
|
||||||
print_verbose(f"response_value: {str(response)[:50]}")
|
print_verbose(f"response_value: {str(response)[:50]}")
|
||||||
else:
|
else:
|
||||||
logging(model=model, input=input, azure=azure, logger_fn=logger_fn)
|
|
||||||
args = locals()
|
args = locals()
|
||||||
raise ValueError(f"No valid embedding model args passed in - {args}")
|
raise ValueError(f"No valid embedding model args passed in - {args}")
|
||||||
|
|
||||||
return response
|
return response
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# log the original exception
|
|
||||||
logging(model=model, input=input, azure=azure, logger_fn=logger_fn, exception=e)
|
|
||||||
## Map to OpenAI Exception
|
## Map to OpenAI Exception
|
||||||
raise exception_type(model=model, original_exception=e, custom_llm_provider="azure" if azure==True else None)
|
raise exception_type(model=model, original_exception=e, custom_llm_provider="azure" if azure==True else None)
|
||||||
raise e
|
raise e
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue