Spaces:
Running
Running
Commit
•
f351557
1
Parent(s):
b37141a
Added basic logging functionality (#1)
Browse files- Added basic logging functionality (b869eb36a811b6cdd369d7f4ee62081538715c30)
Co-authored-by: SYED ZAID BIN haris <SyedZaid-Bin-Haris@users.noreply.huggingface.co>
app.py
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
import logging
|
2 |
-
|
3 |
import gradio as gr
|
4 |
from dotenv import load_dotenv
|
5 |
-
|
6 |
from agents.accountability_agent import AccountabilityAgent
|
7 |
from agents.outline_agent import OutlineAgent
|
8 |
from agents.research_agent import ResearchAgent
|
@@ -19,27 +19,62 @@ thinking_ladder_agent = ThinkingLadderAgent()
|
|
19 |
synthesis_agent = SynthesisAgent()
|
20 |
accountability_agent = AccountabilityAgent()
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
def main(query: str) -> tuple[str, str, float]:
|
|
|
|
|
24 |
logging.info(f"Received query: {query}")
|
|
|
25 |
|
26 |
main_title, themes, metrics_a = outline_agent.run(query)
|
27 |
logging.info(f"OutlineAgent output - Main Title: {main_title}, Themes: {themes}, Metrics: {metrics_a}")
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
29 |
sources, metrics_b = research_agent.run(themes)
|
30 |
logging.info(f"ResearchAgent output - Sources: {sources}, Metrics: {metrics_b}")
|
|
|
|
|
|
|
|
|
31 |
|
32 |
classified_sources, metrics_c = thinking_ladder_agent.run(themes, sources)
|
33 |
logging.info(f"ThinkingLadderAgent output - Classified Sources: {classified_sources}, Metrics: {metrics_c}")
|
|
|
|
|
|
|
|
|
34 |
|
35 |
synthesis, metrics_d = synthesis_agent.run(main_title, themes, classified_sources)
|
36 |
logging.info(f"SynthesisAgent output - Synthesis: {synthesis}, Metrics: {metrics_d}")
|
|
|
|
|
|
|
|
|
37 |
|
38 |
accountability, metrics_e = accountability_agent.run(query, synthesis)
|
39 |
logging.info(f"AccountabilityAgent output - Accountability: {accountability}, Metrics: {metrics_e}")
|
|
|
|
|
|
|
|
|
40 |
|
41 |
cost = sum(list(map(lambda metrics: metrics["cost"], [metrics_a, metrics_b, metrics_c, metrics_d, metrics_e])))
|
42 |
logging.info(f"Total Cost: {cost}")
|
|
|
|
|
|
|
|
|
43 |
|
44 |
return synthesis, accountability, cost
|
45 |
|
|
|
1 |
import logging
|
2 |
+
import json
|
3 |
import gradio as gr
|
4 |
from dotenv import load_dotenv
|
5 |
+
from datetime import datetime
|
6 |
from agents.accountability_agent import AccountabilityAgent
|
7 |
from agents.outline_agent import OutlineAgent
|
8 |
from agents.research_agent import ResearchAgent
|
|
|
19 |
synthesis_agent = SynthesisAgent()
|
20 |
accountability_agent = AccountabilityAgent()
|
21 |
|
22 |
+
logs = []
|
23 |
+
|
24 |
+
def save_logs_to_json(logs):
|
25 |
+
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
26 |
+
filename = f'logs_{timestamp}.json'
|
27 |
+
with open(filename, 'w') as f:
|
28 |
+
json.dump(logs, f, indent=4)
|
29 |
|
30 |
def main(query: str) -> tuple[str, str, float]:
|
31 |
+
log_entry = {}
|
32 |
+
|
33 |
logging.info(f"Received query: {query}")
|
34 |
+
log_entry['query'] = query
|
35 |
|
36 |
main_title, themes, metrics_a = outline_agent.run(query)
|
37 |
logging.info(f"OutlineAgent output - Main Title: {main_title}, Themes: {themes}, Metrics: {metrics_a}")
|
38 |
+
log_entry['outline_agent'] = {
|
39 |
+
'main_title': main_title,
|
40 |
+
'themes': themes,
|
41 |
+
'metrics': metrics_a
|
42 |
+
}
|
43 |
+
|
44 |
sources, metrics_b = research_agent.run(themes)
|
45 |
logging.info(f"ResearchAgent output - Sources: {sources}, Metrics: {metrics_b}")
|
46 |
+
log_entry['research_agent'] = {
|
47 |
+
'sources': sources,
|
48 |
+
'metrics': metrics_b
|
49 |
+
}
|
50 |
|
51 |
classified_sources, metrics_c = thinking_ladder_agent.run(themes, sources)
|
52 |
logging.info(f"ThinkingLadderAgent output - Classified Sources: {classified_sources}, Metrics: {metrics_c}")
|
53 |
+
log_entry['thinking_ladder_agent'] = {
|
54 |
+
'classified_sources': classified_sources,
|
55 |
+
'metrics': metrics_c
|
56 |
+
}
|
57 |
|
58 |
synthesis, metrics_d = synthesis_agent.run(main_title, themes, classified_sources)
|
59 |
logging.info(f"SynthesisAgent output - Synthesis: {synthesis}, Metrics: {metrics_d}")
|
60 |
+
log_entry['synthesis_agent'] = {
|
61 |
+
'synthesis': synthesis,
|
62 |
+
'metrics': metrics_d
|
63 |
+
}
|
64 |
|
65 |
accountability, metrics_e = accountability_agent.run(query, synthesis)
|
66 |
logging.info(f"AccountabilityAgent output - Accountability: {accountability}, Metrics: {metrics_e}")
|
67 |
+
log_entry['accountability_agent'] = {
|
68 |
+
'accountability': accountability,
|
69 |
+
'metrics': metrics_e
|
70 |
+
}
|
71 |
|
72 |
cost = sum(list(map(lambda metrics: metrics["cost"], [metrics_a, metrics_b, metrics_c, metrics_d, metrics_e])))
|
73 |
logging.info(f"Total Cost: {cost}")
|
74 |
+
log_entry['total_cost'] = cost
|
75 |
+
|
76 |
+
logs.append(log_entry)
|
77 |
+
save_logs_to_json(logs)
|
78 |
|
79 |
return synthesis, accountability, cost
|
80 |
|