Skip to content

Commit

Permalink
add logging support
Browse files Browse the repository at this point in the history
  • Loading branch information
gferioli committed Sep 17, 2024
1 parent d3df53d commit 0a670b1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
9 changes: 7 additions & 2 deletions Server/app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from flask import Flask
from flask_cors import CORS
import logging

from configs.config import Config
from configs.routes import Routes
Expand Down Expand Up @@ -29,7 +30,7 @@ def build_game(app, telemetry):
"userResponsePrompt": app.config["userResponsePrompt"],
}

return CareerGame(game_prompts, message_history, open_ai, telemetry)
return CareerGame(game_prompts=game_prompts, message_history=message_history, open_ai=open_ai, telemetry=telemetry, logger=app.logger)


if __name__ == '__main__':
Expand All @@ -39,4 +40,8 @@ def build_game(app, telemetry):
Routes.register_game_routes(app, career_game, telemetry)
Routes.register_system_routes(app, telemetry)

app.run(port=8080, host="0.0.0.0")
logging.basicConfig(level=logging.DEBUG, # Change this to logging.INFO for production
format='%(asctime)s %(levelname)s: %(message)s',
datefmt='%Y-%m-%d %H:%M:%S')

app.run(port=8080, host="0.0.0.0",debug=True)
14 changes: 11 additions & 3 deletions Server/modules/career_game.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,40 @@
from uuid import uuid4
from time import time
import logging


class CareerGame:
def __init__(self, game_prompts, message_history, open_ai, telemetry):
def __init__(self, game_prompts, message_history, open_ai, telemetry,logger):
self.game_prompts = game_prompts
self.message_history = message_history
self.open_ai = open_ai
self.telemetry = telemetry
self.logger = logger

def update_prompts(self, game_prompts):
self.logger.debug("Updating game prompts to: {}".format(game_prompts))
self.game_prompts = game_prompts

def get_current_prompts(self):
return self.game_prompts

def start_game(self, career_choice):
self.logger.debug("Starting new game with career choice: {}".format(career_choice))
conversation_id = str(uuid4())
self.telemetry.info("NewGameStarted", {
self.telemetry.debug("NewGameStarted", {
"conversationId": conversation_id
})
self.message_history.append_system_message(
conversation_id, self.game_prompts["preGamePrompt"])
self.message_history.append_user_message(
conversation_id, self.game_prompts["userResponsePrompt"].format(career_choice))

self.logger.debug("message history: {}".format(self.message_history))

return self.__process_game__(conversation_id)

def continue_game(self, conversation_id, user_choice):
self.logger.debug("Continuing game with user choice: {}".format(user_choice))
self.message_history.append_user_message(
conversation_id, self.game_prompts["userResponsePrompt"].format(user_choice))

Expand All @@ -38,6 +45,7 @@ def end_game(self, conversation_id):

def __process_game__(self, conversation_id):
messages = self.message_history.get_messages(conversation_id)
self.logger.debug("Processing game with messages: {}".format(messages))
response = None

while response is None:
Expand All @@ -47,7 +55,7 @@ def __process_game__(self, conversation_id):

return open_ai_response
except Exception as e:
self.telemetry.info("RetryingOpenAIChat", {
self.telemetry.debug("RetryingOpenAIChat", {
"conversationId": conversation_id,
"error": str(e)
})
Expand Down

0 comments on commit 0a670b1

Please sign in to comment.