oflakne26 commited on
Commit
c81e2b1
1 Parent(s): 407b03e

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +2 -45
main.py CHANGED
@@ -87,48 +87,5 @@ async def generate_response(data: InputData) -> Any:
87
  return cleaned_response
88
 
89
  except Exception as e:
90
- print(f"Primary model {data.model} failed with error: {e}")
91
-
92
- # If the primary model fails, try fallback models
93
- for model in FALLBACK_MODELS:
94
- try:
95
- client = InferenceClient(model=model, token=HF_TOKEN)
96
- response = client.text_generation(inputs,
97
- temperature=1.0,
98
- max_new_tokens=1000,
99
- seed=seed)
100
-
101
- strict_response = str(response)
102
-
103
- repaired_response = repair_json(strict_response,
104
- return_objects=True)
105
-
106
- if isinstance(repaired_response, str):
107
- raise HTTPException(status_code=500, detail="Invalid response from model")
108
- else:
109
- cleaned_response = {}
110
- for key, value in repaired_response.items():
111
- cleaned_key = key.replace("###", "")
112
- cleaned_response[cleaned_key] = value
113
-
114
- for i, text in enumerate(cleaned_response["New response"]):
115
- if i <= 2:
116
- sentences = tokenizer.tokenize(text)
117
- if sentences:
118
- cleaned_response["New response"][i] = sentences[0]
119
- else:
120
- del cleaned_response["New response"][i]
121
- if cleaned_response.get("Sentence count"):
122
- if cleaned_response["Sentence count"] > 3:
123
- cleaned_response["Sentence count"] = 3
124
- else:
125
- cleaned_response["Sentence count"] = len(cleaned_response["New response"])
126
-
127
- data.history += str(cleaned_response)
128
-
129
- return cleaned_response
130
-
131
- except Exception as e:
132
- print(f"Model {model} failed with error: {e}")
133
-
134
- raise HTTPException(status_code=500, detail="All models failed to generate response")
 
87
  return cleaned_response
88
 
89
  except Exception as e:
90
+ print(f"Model {data.model} failed with error: {e}")
91
+ raise HTTPException(status_code=500, detail=f"Model {data.model} failed to generate response")