Skip to content

Commit 7aba619

Browse files
committed
catch (HfHub)HTTPError in hf-dataset-llm-eval example
1 parent d0c22fc commit 7aba619

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

examples/llm_and_nlp/hf-dataset-llm-eval.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from huggingface_hub import InferenceClient
2+
from requests import HTTPError
23

34
from datachain import C, DataChain, DataModel
45

@@ -20,15 +21,18 @@ def eval_dialog(
2021
user_input: str,
2122
bot_response: str,
2223
) -> DialogEval:
23-
completion = client.chat_completion(
24-
messages=[
25-
{
26-
"role": "user",
27-
"content": f"{PROMPT}\n\nUser: {user_input}\nBot: {bot_response}",
28-
},
29-
],
30-
response_format={"type": "json", "value": DialogEval.model_json_schema()},
31-
)
24+
try:
25+
completion = client.chat_completion(
26+
messages=[
27+
{
28+
"role": "user",
29+
"content": f"{PROMPT}\n\nUser: {user_input}\nBot: {bot_response}",
30+
},
31+
],
32+
response_format={"type": "json", "value": DialogEval.model_json_schema()},
33+
)
34+
except HTTPError:
35+
return DialogEval(result="Error", reason="Huggingface API returned an error.")
3236

3337
message = completion.choices[0].message
3438
try:

0 commit comments

Comments
 (0)