Spaces:
Runtime error
Runtime error
implement logging
Browse files
main.py
CHANGED
|
@@ -11,6 +11,10 @@ from pydantic import BaseModel
|
|
| 11 |
from slowapi import Limiter, _rate_limit_exceeded_handler
|
| 12 |
from slowapi.errors import RateLimitExceeded
|
| 13 |
from slowapi.util import get_remote_address
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
# Initialize the limiter
|
| 16 |
limiter = Limiter(key_func=get_remote_address)
|
|
@@ -75,6 +79,7 @@ async def stream(request: Request, item: Validation):
|
|
| 75 |
Returns:
|
| 76 |
dict: A dictionary containing the generated story content and the timestamp of generation.
|
| 77 |
"""
|
|
|
|
| 78 |
prompt = "<|user|>\nA bedtime tiny story for the children<\/s>\n<|assistant|>\n"
|
| 79 |
story_content = llm(prompt)
|
| 80 |
story_dict = {
|
|
@@ -82,6 +87,7 @@ async def stream(request: Request, item: Validation):
|
|
| 82 |
"generated_at": datetime.datetime.utcnow()
|
| 83 |
}
|
| 84 |
result = await db.stories.insert_one(story_dict)
|
|
|
|
| 85 |
return {"_id": str(result.inserted_id), "story_content": story_content}
|
| 86 |
|
| 87 |
|
|
@@ -113,8 +119,10 @@ async def create_feedback(feedback: Feedback):
|
|
| 113 |
Returns:
|
| 114 |
- dict: A dictionary containing the ID of the inserted feedback.
|
| 115 |
"""
|
|
|
|
| 116 |
feedback_dict = feedback.dict()
|
| 117 |
feedback_dict["feedback_at"] = datetime.datetime.utcnow()
|
| 118 |
feedback_dict["story_id"] = ObjectId(feedback.story_id)
|
| 119 |
result = await db.feedback.insert_one(feedback_dict)
|
|
|
|
| 120 |
return {"_id": str(result.inserted_id)}
|
|
|
|
| 11 |
from slowapi import Limiter, _rate_limit_exceeded_handler
|
| 12 |
from slowapi.errors import RateLimitExceeded
|
| 13 |
from slowapi.util import get_remote_address
|
| 14 |
+
import logging
|
| 15 |
+
|
| 16 |
+
# Configure logging
|
| 17 |
+
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
| 18 |
|
| 19 |
# Initialize the limiter
|
| 20 |
limiter = Limiter(key_func=get_remote_address)
|
|
|
|
| 79 |
Returns:
|
| 80 |
dict: A dictionary containing the generated story content and the timestamp of generation.
|
| 81 |
"""
|
| 82 |
+
logging.info('Generating story')
|
| 83 |
prompt = "<|user|>\nA bedtime tiny story for the children<\/s>\n<|assistant|>\n"
|
| 84 |
story_content = llm(prompt)
|
| 85 |
story_dict = {
|
|
|
|
| 87 |
"generated_at": datetime.datetime.utcnow()
|
| 88 |
}
|
| 89 |
result = await db.stories.insert_one(story_dict)
|
| 90 |
+
logging.info(f'Story generated with id {result.inserted_id}')
|
| 91 |
return {"_id": str(result.inserted_id), "story_content": story_content}
|
| 92 |
|
| 93 |
|
|
|
|
| 119 |
Returns:
|
| 120 |
- dict: A dictionary containing the ID of the inserted feedback.
|
| 121 |
"""
|
| 122 |
+
logging.info('Receiving feedback')
|
| 123 |
feedback_dict = feedback.dict()
|
| 124 |
feedback_dict["feedback_at"] = datetime.datetime.utcnow()
|
| 125 |
feedback_dict["story_id"] = ObjectId(feedback.story_id)
|
| 126 |
result = await db.feedback.insert_one(feedback_dict)
|
| 127 |
+
logging.info(f'Feedback received with id {result.inserted_id}')
|
| 128 |
return {"_id": str(result.inserted_id)}
|