Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -27,9 +27,9 @@ app = FastAPI()
|
|
| 27 |
app.add_middleware(
|
| 28 |
CORSMiddleware,
|
| 29 |
allow_origins=["*"],
|
| 30 |
-
allow_methods=["POST", "GET", "PUT", "DELETE", "OPTIONS"],
|
| 31 |
allow_headers=["*"],
|
| 32 |
-
allow_credentials=True,
|
| 33 |
)
|
| 34 |
|
| 35 |
# Chemins des fichiers
|
|
@@ -171,6 +171,15 @@ async def summarize_document(request: SummaryRequest):
|
|
| 171 |
with open(file_path, "r", encoding="utf-8") as f:
|
| 172 |
text = f.read()
|
| 173 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
summary = client.summarization(
|
| 175 |
text=text,
|
| 176 |
model=MODELS["summary"],
|
|
@@ -218,22 +227,21 @@ async def answer_question(request: QARequest):
|
|
| 218 |
with open(file_path, "r", encoding="utf-8") as f:
|
| 219 |
context = f.read()
|
| 220 |
|
| 221 |
-
|
| 222 |
-
prompt = f"""<|begin_of_text|><|start_header_id|>user<|end_header_id|>
|
| 223 |
Vous êtes un assistant IA qui répond à des questions en français.
|
|
|
|
| 224 |
Contexte: {context[:3000]}
|
| 225 |
Question: {request.question}
|
| 226 |
-
|
| 227 |
-
|
| 228 |
|
| 229 |
-
|
| 230 |
-
response = client.text_generation(
|
| 231 |
-
prompt,
|
| 232 |
model=MODELS["qa"],
|
| 233 |
-
|
|
|
|
| 234 |
)
|
| 235 |
|
| 236 |
-
return {"answer": response}
|
| 237 |
except Exception as e:
|
| 238 |
logger.error(f"QA error: {e}")
|
| 239 |
raise HTTPException(500, f"Erreur de réponse: {str(e)}")
|
|
|
|
| 27 |
app.add_middleware(
|
| 28 |
CORSMiddleware,
|
| 29 |
allow_origins=["*"],
|
| 30 |
+
allow_methods=["POST", "GET", "PUT", "DELETE", "OPTIONS"], # Méthodes explicites
|
| 31 |
allow_headers=["*"],
|
| 32 |
+
allow_credentials=True, # Permettre les credentials si nécessaire
|
| 33 |
)
|
| 34 |
|
| 35 |
# Chemins des fichiers
|
|
|
|
| 171 |
with open(file_path, "r", encoding="utf-8") as f:
|
| 172 |
text = f.read()
|
| 173 |
|
| 174 |
+
prompt = f"""
|
| 175 |
+
Résumez ce document de manière concise en français.
|
| 176 |
+
Concentrez-vous sur les points principaux.
|
| 177 |
+
Le résumé doit faire environ {request.max_length} mots.
|
| 178 |
+
|
| 179 |
+
Document:
|
| 180 |
+
{text[:5000]}... [truncated]
|
| 181 |
+
"""
|
| 182 |
+
|
| 183 |
summary = client.summarization(
|
| 184 |
text=text,
|
| 185 |
model=MODELS["summary"],
|
|
|
|
| 227 |
with open(file_path, "r", encoding="utf-8") as f:
|
| 228 |
context = f.read()
|
| 229 |
|
| 230 |
+
prompt = f"""
|
|
|
|
| 231 |
Vous êtes un assistant IA qui répond à des questions en français.
|
| 232 |
+
Répondez de manière précise et concise.
|
| 233 |
Contexte: {context[:3000]}
|
| 234 |
Question: {request.question}
|
| 235 |
+
Réponse:
|
| 236 |
+
"""
|
| 237 |
|
| 238 |
+
response = client.chat_completion(
|
|
|
|
|
|
|
| 239 |
model=MODELS["qa"],
|
| 240 |
+
messages=[{"role": "user", "content": prompt}],
|
| 241 |
+
max_tokens=500
|
| 242 |
)
|
| 243 |
|
| 244 |
+
return {"answer": response.choices[0].message.content}
|
| 245 |
except Exception as e:
|
| 246 |
logger.error(f"QA error: {e}")
|
| 247 |
raise HTTPException(500, f"Erreur de réponse: {str(e)}")
|