Skip to content

Commit 2749a2a

Browse files
committed
fix logging -- logging results will be printed to console for debugging purposes
1 parent 951a2d7 commit 2749a2a

File tree

3 files changed

+35
-11
lines changed

3 files changed

+35
-11
lines changed

py-src/data_formulator/agents/agent_code_explanation.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ def run(self, input_tables, code):
8383
###### the part that calls open_ai
8484
response = self.client.get_completion(messages = messages)
8585

86-
logger.info('\n=== explanation output ===>\n')
87-
logger.info(response.choices[0].message.content)
86+
logger.info(f"=== explanation output ===>\n{response.choices[0].message.content}\n")
8887

8988
return response.choices[0].message.content

py-src/data_formulator/agents/agent_data_transform_v2.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Licensed under the MIT License.
33

44
import json
5+
import sys
56

67
from data_formulator.agents.agent_utils import extract_json_objects, generate_data_summary, extract_code_from_gpt_response
78
import data_formulator.py_sandbox as py_sandbox
@@ -10,6 +11,7 @@
1011

1112
import logging
1213

14+
# Replace/update the logger configuration
1315
logger = logging.getLogger(__name__)
1416

1517
SYSTEM_PROMPT = '''You are a data scientist to help user to transform data that will be used for visualization.
@@ -207,8 +209,8 @@ def process_gpt_response(self, input_tables, messages, response):
207209

208210
candidates = []
209211
for choice in response.choices:
210-
print("\n=== Data transformation result ===>\n")
211-
print(choice.message.content + "\n")
212+
logger.info("=== Data transformation result ===>")
213+
logger.info(choice.message.content + "\n")
212214

213215
json_blocks = extract_json_objects(choice.message.content + "\n")
214216
if len(json_blocks) > 0:
@@ -218,8 +220,8 @@ def process_gpt_response(self, input_tables, messages, response):
218220

219221
code_blocks = extract_code_from_gpt_response(choice.message.content + "\n", "python")
220222

221-
print("\n=== Code blocks ===>\n")
222-
print(code_blocks)
223+
logger.info("=== Code blocks ===>")
224+
logger.info(code_blocks)
223225

224226
if len(code_blocks) > 0:
225227
code_str = code_blocks[-1]
@@ -246,8 +248,8 @@ def process_gpt_response(self, input_tables, messages, response):
246248
result['refined_goal'] = refined_goal
247249
candidates.append(result)
248250

249-
print("\n=== Candidates ===>\n")
250-
print(candidates)
251+
logger.info("=== Candidates ===>")
252+
logger.info(candidates)
251253

252254
return candidates
253255

py-src/data_formulator/app.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
from flask_cors import CORS
2222

23+
import logging
24+
2325
import json
2426
import time
2527
from pathlib import Path
@@ -41,16 +43,37 @@
4143

4244
APP_ROOT = Path(os.path.join(Path(__file__).parent)).absolute()
4345

46+
import os
47+
48+
app = Flask(__name__, static_url_path='', static_folder=os.path.join(APP_ROOT, "dist"))
49+
CORS(app)
50+
4451
print(APP_ROOT)
4552

4653
# Load the single environment file
4754
load_dotenv(os.path.join(APP_ROOT, "..", "..", 'api-keys.env'))
4855
load_dotenv(os.path.join(APP_ROOT, 'api-keys.env'))
4956

50-
import os
57+
# Configure root logger for general application logging
58+
logging.basicConfig(
59+
level=logging.INFO,
60+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
61+
handlers=[logging.StreamHandler(sys.stdout)]
62+
)
63+
64+
# Get logger for this module
65+
logger = logging.getLogger(__name__)
66+
67+
# Configure Flask app logger to use the same settings
68+
app.logger.handlers = []
69+
for handler in logging.getLogger().handlers:
70+
app.logger.addHandler(handler)
71+
72+
# Example usage:
73+
logger.info("Application level log") # General application logging
74+
app.logger.info("Flask specific log") # Web request related logging
75+
5176

52-
app = Flask(__name__, static_url_path='', static_folder=os.path.join(APP_ROOT, "dist"))
53-
CORS(app)
5477

5578
def get_client(model_config):
5679
for key in model_config:

0 commit comments

Comments
 (0)