mirror of
https://github.com/tiennm99/litellm.git
synced 2026-08-07 02:25:34 +00:00
(fix) pydantic errors with response.time
This commit is contained in:
@@ -180,7 +180,7 @@ def completion(
|
||||
encoding.encode(model_response["choices"][0]["message"].get("content"))
|
||||
)
|
||||
|
||||
model_response["created"] = time.time()
|
||||
model_response["created"] = int(time.time())
|
||||
model_response["model"] = model
|
||||
model_response["usage"] = {
|
||||
"prompt_tokens": prompt_tokens,
|
||||
|
||||
@@ -263,7 +263,7 @@ def completion(
|
||||
encoding.encode(model_response["choices"][0]["message"]["content"])
|
||||
)
|
||||
|
||||
model_response["created"] = time.time()
|
||||
model_response["created"] = int(time.time())
|
||||
model_response["model"] = model
|
||||
usage = Usage(
|
||||
prompt_tokens=prompt_tokens,
|
||||
|
||||
@@ -172,7 +172,7 @@ def completion(
|
||||
encoding.encode(model_response["choices"][0]["message"].get("content", ""))
|
||||
) ##[TODO] use the anthropic tokenizer here
|
||||
|
||||
model_response["created"] = time.time()
|
||||
model_response["created"] = int(time.time())
|
||||
model_response["model"] = model
|
||||
usage = Usage(
|
||||
prompt_tokens=prompt_tokens,
|
||||
|
||||
@@ -134,7 +134,7 @@ def completion(
|
||||
encoding.encode(model_response["choices"][0]["message"]["content"])
|
||||
)
|
||||
|
||||
model_response["created"] = time.time()
|
||||
model_response["created"] = int(time.time())
|
||||
model_response["model"] = model
|
||||
usage = Usage(
|
||||
prompt_tokens=prompt_tokens,
|
||||
|
||||
@@ -464,7 +464,7 @@ def completion(
|
||||
encoding.encode(model_response["choices"][0]["message"].get("content", ""))
|
||||
)
|
||||
|
||||
model_response["created"] = time.time()
|
||||
model_response["created"] = int(time.time())
|
||||
model_response["model"] = model
|
||||
usage = Usage(
|
||||
prompt_tokens=prompt_tokens,
|
||||
|
||||
@@ -184,7 +184,7 @@ def completion(
|
||||
encoding.encode(model_response["choices"][0]["message"].get("content", ""))
|
||||
)
|
||||
|
||||
model_response["created"] = time.time()
|
||||
model_response["created"] = int(time.time())
|
||||
model_response["model"] = model
|
||||
usage = Usage(
|
||||
prompt_tokens=prompt_tokens,
|
||||
|
||||
@@ -224,7 +224,7 @@ class Huggingface(BaseLLM):
|
||||
else:
|
||||
completion_tokens = 0
|
||||
|
||||
model_response["created"] = time.time()
|
||||
model_response["created"] = int(time.time())
|
||||
model_response["model"] = model
|
||||
usage = Usage(
|
||||
prompt_tokens=prompt_tokens,
|
||||
|
||||
@@ -143,7 +143,7 @@ def completion(
|
||||
encoding.encode(model_response["choices"][0]["message"].get("content", ""))
|
||||
)
|
||||
|
||||
model_response["created"] = time.time()
|
||||
model_response["created"] = int(time.time())
|
||||
model_response["model"] = model
|
||||
usage = Usage(
|
||||
prompt_tokens=prompt_tokens,
|
||||
|
||||
@@ -169,7 +169,7 @@ def completion(
|
||||
prompt_tokens = completion_response["nb_input_tokens"]
|
||||
completion_tokens = completion_response["nb_generated_tokens"]
|
||||
|
||||
model_response["created"] = time.time()
|
||||
model_response["created"] = int(time.time())
|
||||
model_response["model"] = model
|
||||
usage = Usage(
|
||||
prompt_tokens=prompt_tokens,
|
||||
|
||||
@@ -109,7 +109,7 @@ def completion(
|
||||
encoding.encode(model_response["choices"][0]["message"]["content"])
|
||||
)
|
||||
|
||||
model_response["created"] = time.time()
|
||||
model_response["created"] = int(time.time())
|
||||
model_response["model"] = model
|
||||
usage = Usage(
|
||||
prompt_tokens=prompt_tokens,
|
||||
|
||||
@@ -162,7 +162,7 @@ def completion(
|
||||
encoding.encode(model_response["choices"][0]["message"].get("content", ""))
|
||||
)
|
||||
|
||||
model_response["created"] = time.time()
|
||||
model_response["created"] = int(time.time())
|
||||
model_response["model"] = "palm/" + model
|
||||
usage = Usage(
|
||||
prompt_tokens=prompt_tokens,
|
||||
|
||||
@@ -174,7 +174,7 @@ def completion(
|
||||
encoding.encode(model_response["choices"][0]["message"].get("content"))
|
||||
)
|
||||
|
||||
model_response["created"] = time.time()
|
||||
model_response["created"] = int(time.time())
|
||||
model_response["model"] = model
|
||||
usage = Usage(
|
||||
prompt_tokens=prompt_tokens,
|
||||
|
||||
@@ -229,7 +229,7 @@ def completion(
|
||||
## Step1: Start Prediction: gets a prediction url
|
||||
## Step2: Poll prediction url for response
|
||||
## Step2: is handled with and without streaming
|
||||
model_response["created"] = time.time() # for pricing this must remain right before calling api
|
||||
model_response["created"] = int(time.time()) # for pricing this must remain right before calling api
|
||||
prediction_url = start_prediction(version_id, input_data, api_key, api_base, logging_obj=logging_obj, print_verbose=print_verbose)
|
||||
print_verbose(prediction_url)
|
||||
|
||||
|
||||
@@ -170,7 +170,7 @@ def completion(
|
||||
encoding.encode(model_response["choices"][0]["message"].get("content", ""))
|
||||
)
|
||||
|
||||
model_response["created"] = time.time()
|
||||
model_response["created"] = int(time.time())
|
||||
model_response["model"] = model
|
||||
usage = Usage(
|
||||
prompt_tokens=prompt_tokens,
|
||||
|
||||
@@ -183,7 +183,7 @@ def completion(
|
||||
)
|
||||
if "finish_reason" in completion_response["output"]["choices"][0]:
|
||||
model_response.choices[0].finish_reason = completion_response["output"]["choices"][0]["finish_reason"]
|
||||
model_response["created"] = time.time()
|
||||
model_response["created"] = int(time.time())
|
||||
model_response["model"] = model
|
||||
usage = Usage(
|
||||
prompt_tokens=prompt_tokens,
|
||||
|
||||
@@ -144,7 +144,7 @@ def completion(
|
||||
"content"
|
||||
] = str(completion_response)
|
||||
model_response["choices"][0]["message"]["content"] = str(completion_response)
|
||||
model_response["created"] = time.time()
|
||||
model_response["created"] = int(time.time())
|
||||
model_response["model"] = model
|
||||
## CALCULATING USAGE
|
||||
prompt_tokens = len(
|
||||
|
||||
@@ -90,7 +90,7 @@ def completion(
|
||||
prompt_tokens = len(outputs[0].prompt_token_ids)
|
||||
completion_tokens = len(outputs[0].outputs[0].token_ids)
|
||||
|
||||
model_response["created"] = time.time()
|
||||
model_response["created"] = int(time.time())
|
||||
model_response["model"] = model
|
||||
usage = Usage(
|
||||
prompt_tokens=prompt_tokens,
|
||||
@@ -173,7 +173,7 @@ def batch_completions(
|
||||
prompt_tokens = len(output.prompt_token_ids)
|
||||
completion_tokens = len(output.outputs[0].token_ids)
|
||||
|
||||
model_response["created"] = time.time()
|
||||
model_response["created"] = int(time.time())
|
||||
model_response["model"] = model
|
||||
usage = Usage(
|
||||
prompt_tokens=prompt_tokens,
|
||||
|
||||
+4
-4
@@ -228,7 +228,7 @@ def mock_completion(model: str, messages: List, stream: Optional[bool] = False,
|
||||
return response
|
||||
|
||||
model_response["choices"][0]["message"]["content"] = mock_response
|
||||
model_response["created"] = time.time()
|
||||
model_response["created"] = int(time.time())
|
||||
model_response["model"] = model
|
||||
return model_response
|
||||
|
||||
@@ -388,7 +388,7 @@ def completion(
|
||||
api_base = "https://proxy.litellm.ai"
|
||||
custom_llm_provider = "openai"
|
||||
api_key = model_api_key
|
||||
|
||||
|
||||
# check if user passed in any of the OpenAI optional params
|
||||
optional_params = get_optional_params(
|
||||
functions=functions,
|
||||
@@ -1245,7 +1245,7 @@ def completion(
|
||||
|
||||
## RESPONSE OBJECT
|
||||
model_response["choices"][0]["message"]["content"] = response_string
|
||||
model_response["created"] = time.time()
|
||||
model_response["created"] = int(time.time())
|
||||
model_response["model"] = "ollama/" + model
|
||||
prompt_tokens = len(encoding.encode(prompt)) # type: ignore
|
||||
completion_tokens = len(encoding.encode(response_string))
|
||||
@@ -1371,7 +1371,7 @@ def completion(
|
||||
string_response = response_json['data'][0]['output'][0]
|
||||
## RESPONSE OBJECT
|
||||
model_response["choices"][0]["message"]["content"] = string_response
|
||||
model_response["created"] = time.time()
|
||||
model_response["created"] = int(time.time())
|
||||
model_response["model"] = model
|
||||
response = model_response
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user