-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathresponse_analyzer.py
31 lines (24 loc) · 1.45 KB
/
response_analyzer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import json
class ResponseAnalyzer:
def __init__(self, structured_response_generator):
self.structured_response_generator = structured_response_generator
def analyze_thoughts(self, initial_prompt, all_thoughts, output_schema):
analysis_prompt = f"""Analyze the following thoughts on the initial prompt: '{initial_prompt}'
Thoughts:
{self._format_thoughts(all_thoughts)}
Provide a comprehensive analysis of these thoughts, highlighting key trends, insights, and potential implications.
Your response should follow the specified output format and ensure proper JSON formatting."""
messages = [
{"role": "system", "content": "You are an AI assistant specialized in analyzing and synthesizing complex ideas. Ensure your output follows the specified JSON format and uses proper JSON formatting."},
{"role": "user", "content": analysis_prompt}
]
analysis = self.structured_response_generator.generate(messages, output_schema)
analysis['type'] = 'analysis'
return analysis
def _format_thoughts(self, thoughts):
formatted_thoughts = ""
for i, thought in enumerate(thoughts, 1):
formatted_thoughts += f"Thought {i} ({thought['type']}):\n"
formatted_thoughts += f"Content: {thought['content'][:200]}...\n"
formatted_thoughts += f"Key Points: {', '.join(thought['key_points'])}\n\n"
return formatted_thoughts