Update main.py
Browse files
main.py
CHANGED
@@ -88,4 +88,25 @@ async def generate_response(data: InputData) -> Dict[str, Any]:
|
|
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")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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")
|
92 |
+
|
93 |
+
@app.post("/get-medieval-name/")
|
94 |
+
async def get_medieval_name() -> Dict[str, str]:
|
95 |
+
try:
|
96 |
+
file_path = "medieval_names.txt"
|
97 |
+
if not os.path.exists(file_path):
|
98 |
+
raise HTTPException(status_code=404, detail="File not found")
|
99 |
+
|
100 |
+
with open(file_path, "r") as file:
|
101 |
+
names = file.read().splitlines()
|
102 |
+
|
103 |
+
if not names:
|
104 |
+
raise HTTPException(status_code=404, detail="No names found in the file")
|
105 |
+
|
106 |
+
random_name = random.choice(names)
|
107 |
+
|
108 |
+
return {"name": random_name}
|
109 |
+
|
110 |
+
except Exception as e:
|
111 |
+
print(f"Error: {e}")
|
112 |
+
raise HTTPException(status_code=500, detail="An error occurred while processing the request")
|