diff --git a/examples/llm_and_nlp/hf-dataset-llm-eval.py b/examples/llm_and_nlp/hf-dataset-llm-eval.py index 8b5ce3e5f..460dac5a1 100644 --- a/examples/llm_and_nlp/hf-dataset-llm-eval.py +++ b/examples/llm_and_nlp/hf-dataset-llm-eval.py @@ -1,4 +1,4 @@ -from huggingface_hub import InferenceClient +from huggingface_hub import HfHubHTTPError, InferenceClient from datachain import C, DataChain, DataModel @@ -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: