up
This commit is contained in:
parent
34f233ab60
commit
69edc5201b
6 changed files with 129 additions and 1 deletions
1
devops/.gitignore
vendored
Normal file
1
devops/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
venv
|
46
devops/app.py
Normal file
46
devops/app.py
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
from datetime import datetime, timezone
|
||||||
|
from typing import Dict, List
|
||||||
|
from uuid import uuid4
|
||||||
|
|
||||||
|
from fastapi import FastAPI
|
||||||
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
|
||||||
|
app = FastAPI(title="Feedback API", version="1.0.0")
|
||||||
|
|
||||||
|
|
||||||
|
class FeedbackRequest(BaseModel):
|
||||||
|
feedback: str
|
||||||
|
|
||||||
|
|
||||||
|
class FeedbackEntry(BaseModel):
|
||||||
|
id: str
|
||||||
|
feedback: str
|
||||||
|
timestamp: str
|
||||||
|
|
||||||
|
|
||||||
|
# Stockage en mémoire: conversationID -> liste des feedbacks
|
||||||
|
in_memory_store: Dict[str, List[FeedbackEntry]] = {}
|
||||||
|
|
||||||
|
|
||||||
|
@app.post("/api/v1/{conversationID}/feedback")
|
||||||
|
def submit_feedback(conversationID: str, payload: FeedbackRequest):
|
||||||
|
feedback_id = f"fb-{uuid4()}"
|
||||||
|
ts = datetime.now(timezone.utc).isoformat()
|
||||||
|
|
||||||
|
entry = FeedbackEntry(id=feedback_id, feedback=payload.feedback, timestamp=ts)
|
||||||
|
conversation_feedbacks = in_memory_store.setdefault(conversationID, [])
|
||||||
|
conversation_feedbacks.append(entry)
|
||||||
|
|
||||||
|
return {
|
||||||
|
"message": "Feedback submitted successfully",
|
||||||
|
"feedbackId": feedback_id,
|
||||||
|
"totalFeedbacks": len(conversation_feedbacks),
|
||||||
|
"timestamp": ts,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
import uvicorn
|
||||||
|
|
||||||
|
uvicorn.run(app, host="0.0.0.0", port=8000)
|
|
@ -6,7 +6,7 @@ WORKDIR /app
|
||||||
|
|
||||||
|
|
||||||
# Définir une variable d'environnement pour le chemin de la librairie Angular
|
# Définir une variable d'environnement pour le chemin de la librairie Angular
|
||||||
ENV LIB_PATH=../ma-webapp-angular
|
ENV LIB_PATH=../sae-csc
|
||||||
|
|
||||||
# Copier les fichiers package.json et package-lock.json de la librairie
|
# Copier les fichiers package.json et package-lock.json de la librairie
|
||||||
COPY ${LIB_PATH}/package*.json ./
|
COPY ${LIB_PATH}/package*.json ./
|
||||||
|
|
70
devops/index.html
Normal file
70
devops/index.html
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="fr">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Test API Feedback</title>
|
||||||
|
<style>
|
||||||
|
body { font-family: Arial, sans-serif; margin: 2em; }
|
||||||
|
#response { margin-top: 1em; padding: 1em; border: 1px solid #ccc; background: #f9f9f9; }
|
||||||
|
label, input, textarea { display: block; margin-bottom: 0.5em; }
|
||||||
|
button { padding: 0.5em 1em; }
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Envoyer un feedback à l'API</h1>
|
||||||
|
<form id="feedbackForm">
|
||||||
|
<label for="baseUrl">Base URL de l'API :</label>
|
||||||
|
<input type="url" id="baseUrl" name="baseUrl" required value="http://localhost:8501">
|
||||||
|
|
||||||
|
<label for="conversationID">Conversation ID :</label>
|
||||||
|
<input type="text" id="conversationID" name="conversationID" required value="test-conv">
|
||||||
|
|
||||||
|
<label for="feedback">Votre feedback :</label>
|
||||||
|
<textarea id="feedback" name="feedback" rows="4" required></textarea>
|
||||||
|
|
||||||
|
<button type="submit">Envoyer le feedback</button>
|
||||||
|
</form>
|
||||||
|
<div id="response"></div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
// Initialiser et persister la base URL dans localStorage
|
||||||
|
(function initBaseUrl() {
|
||||||
|
const baseUrlInput = document.getElementById('baseUrl');
|
||||||
|
const saved = localStorage.getItem('apiBaseUrl') || 'http://localhost:8501';
|
||||||
|
baseUrlInput.value = saved;
|
||||||
|
baseUrlInput.addEventListener('input', function () {
|
||||||
|
localStorage.setItem('apiBaseUrl', baseUrlInput.value);
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
|
||||||
|
document.getElementById('feedbackForm').addEventListener('submit', async function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
const baseUrl = (document.getElementById('baseUrl').value || 'http://localhost:8501').replace(/\/+$/, '');
|
||||||
|
const conversationID = document.getElementById('conversationID').value;
|
||||||
|
const feedback = document.getElementById('feedback').value;
|
||||||
|
const responseDiv = document.getElementById('response');
|
||||||
|
responseDiv.textContent = "Envoi en cours...";
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await fetch(`${baseUrl}/api/v1/${encodeURIComponent(conversationID)}/feedback`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ feedback })
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!res.ok) {
|
||||||
|
const errText = await res.text();
|
||||||
|
responseDiv.textContent = `Erreur: ${res.status} - ${errText}`;
|
||||||
|
} else {
|
||||||
|
const data = await res.json();
|
||||||
|
responseDiv.textContent = "Réponse de l'API :\n" + JSON.stringify(data, null, 2);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
responseDiv.textContent = "Erreur lors de la requête : " + err;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
8
devops/openapi.json
Normal file
8
devops/openapi.json
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"openapi": "3.0.3",
|
||||||
|
"info": {
|
||||||
|
"title": "Streamlit API",
|
||||||
|
"version": "0.1.0"
|
||||||
|
},
|
||||||
|
"paths": {}
|
||||||
|
}
|
3
devops/requirements.txt
Normal file
3
devops/requirements.txt
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
streamlit
|
||||||
|
fastapi
|
||||||
|
uvicorn
|
Loading…
Add table
Add a link
Reference in a new issue