Skip to content

Commit

Permalink
catch HfHubHTTPError in hf-dataset-llm-eval example
Browse files Browse the repository at this point in the history
  • Loading branch information
mattseddon committed Jan 21, 2025
1 parent d0c22fc commit a20da5b
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions examples/llm_and_nlp/hf-dataset-llm-eval.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from huggingface_hub import InferenceClient
from huggingface_hub import HfHubHTTPError, InferenceClient

from datachain import C, DataChain, DataModel

Expand All @@ -20,15 +20,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 HfHubHTTPError:
return DialogEval(result="Error", reason="Huggingface API returned an error.")

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

0 comments on commit a20da5b

Please sign in to comment.