File tree Expand file tree Collapse file tree 1 file changed +13
-9
lines changed Expand file tree Collapse file tree 1 file changed +13
-9
lines changed Original file line number Diff line number Diff line change 1
1
from huggingface_hub import InferenceClient
2
+ from requests import HTTPError
2
3
3
4
from datachain import C , DataChain , DataModel
4
5
@@ -20,15 +21,18 @@ def eval_dialog(
20
21
user_input : str ,
21
22
bot_response : str ,
22
23
) -> DialogEval :
23
- completion = client .chat_completion (
24
- messages = [
25
- {
26
- "role" : "user" ,
27
- "content" : f"{ PROMPT } \n \n User: { user_input } \n Bot: { 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 \n User: { user_input } \n Bot: { 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." )
32
36
33
37
message = completion .choices [0 ].message
34
38
try :
You can’t perform that action at this time.
0 commit comments