Skip to content

Commit

Permalink
catch (HfHub)HTTPError in hf-dataset-llm-eval example
Browse files Browse the repository at this point in the history
  • Loading branch information
mattseddon committed Jan 24, 2025
1 parent 740be82 commit ea88557
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions examples/llm_and_nlp/hf-dataset-llm-eval.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from huggingface_hub import InferenceClient
from requests import HTTPError

from datachain import C, DataChain, DataModel

Expand All @@ -20,15 +21,18 @@ def eval_dialog(
user_input: str,
bot_response: str,
) -> DialogEval:
completion = client.chat_completion(
messages=[
{
"role": "user",
"content": f"{PROMPT}\n\nUser: {user_input}\nBot: {bot_response}",
},
],
response_format={"type": "json", "value": DialogEval.model_json_schema()},
)
try:
completion = client.chat_completion(
messages=[
{
"role": "user",
"content": f"{PROMPT}\n\nUser: {user_input}\nBot: {bot_response}",
},
],
response_format={"type": "json", "value": DialogEval.model_json_schema()},
)
except HTTPError:
return DialogEval(result="Error", reason="Huggingface API returned an error.")

message = completion.choices[0].message
try:
Expand Down

0 comments on commit ea88557

Please sign in to comment.