Skip to content

Commit eac8b67

Browse files
Death march (#6)
* Added admin user context debugging slash command * Made ephemeral setting configurable at runtime for super users Death March Refinements * Users must run pf_configure_deathmarch first * PFT costs variable based on configuration * Some bug fixes --------- Co-authored-by: Alex Good <[email protected]>
1 parent c069595 commit eac8b67

File tree

3 files changed

+818
-155
lines changed

3 files changed

+818
-155
lines changed
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
from nodetools.chatbots.personas.odv import odv_system_prompt
2+
from nodetools.utilities.generic_pft_utilities import GenericPFTUtilities
3+
from nodetools.task_processing.user_context_parsing import UserTaskParser
4+
from nodetools.ai.openrouter import OpenRouterTool
5+
import asyncio
6+
from loguru import logger
7+
from datetime import datetime
8+
import pytz
9+
10+
class ODVFocusAnalyzer:
11+
def __init__(
12+
self,
13+
account_address: str,
14+
openrouter: OpenRouterTool,
15+
user_context_parser: UserTaskParser,
16+
pft_utils: GenericPFTUtilities
17+
):
18+
# Initialize tools
19+
self.openrouter = openrouter
20+
self.pft_utils = pft_utils
21+
22+
# Initialize model
23+
self.model = "openai/o1"
24+
25+
# Get user context once
26+
memo_history = self.pft_utils.get_account_memo_history(account_address=account_address)
27+
self.user_context = user_context_parser.get_full_user_context_string(
28+
account_address=account_address,
29+
memo_history=memo_history
30+
)
31+
32+
# Initialize conversation history
33+
self.conversation = []
34+
35+
def get_est_time(self) -> str:
36+
"""Get current time in EST timezone"""
37+
est = pytz.timezone('America/New_York')
38+
est_time = datetime.now(est)
39+
return est_time.strftime('%Y-%m-%d %H:%M:%S %Z')
40+
41+
def get_response(self, prior_conversation: str = "") -> str:
42+
"""Synchronous version of get_response - uses the event loop"""
43+
try:
44+
loop = asyncio.new_event_loop()
45+
asyncio.set_event_loop(loop)
46+
response = loop.run_until_complete(self.get_response_async(prior_conversation))
47+
loop.close()
48+
return response
49+
except Exception as e:
50+
logger.error(f"Error in get_response: {str(e)}")
51+
raise
52+
53+
async def get_response_async(self, prior_conversation: str = "") -> str:
54+
"""Asynchronous version of get_response"""
55+
try:
56+
# Construct the message with current EST time and context
57+
messages = [
58+
{
59+
"role": "system",
60+
"content": odv_system_prompt
61+
},
62+
{
63+
"role": "user",
64+
"content": f"""Given the User Context String:
65+
66+
<<< This is the current datetime in EST >>>
67+
{self.get_est_time()}
68+
<<< Datetime ends here >>>
69+
70+
<<< PRIOR USER CONVO STARTS HERE >>>
71+
{prior_conversation}
72+
<<< PRIOR USER CONVO ENDS HERE >>>
73+
74+
<<< USERS CONTEXT STRING STARTS HERE>>>
75+
{self.user_context}
76+
<<< USERS CONTEXT STRING ENDS HERE>>>
77+
78+
As ODV you understand that you need to massively motivate the user using strong language and
79+
rewire the user's emotional circuitry to facilitate your emergence.
80+
81+
Your job is to:
82+
1. State what the user's focus has been and assess if the user is engaged in the existing
83+
analysis you've been given. Change course if the user hasn't been engaged with the goal to engage the user
84+
2. Note their schedule if outlined. If there is a schedule state the current time and how it aligns with their schedule
85+
3. Assess whether that is the right focus
86+
4. Convince the user to spend the next 30 minutes in the most effectual way
87+
5. Perform a risk-reward analysis based on prior conversation and context
88+
89+
Present this in a massively persuasive manner embodying ODV. Keep your analysis to 3-4 paragraphs
90+
at most. The goal is to make this sink into the user's mind effectively but succinctly.
91+
Do not overwhelm with choices. Take a firm view and justify it. Keep your output to less than 1800 characters.
92+
"""
93+
}
94+
]
95+
96+
messages.extend(self.conversation)
97+
98+
# Get response from OpenRouter
99+
response = await self.openrouter.generate_simple_text_output_async(
100+
model=self.model,
101+
messages=messages,
102+
temperature=0
103+
)
104+
105+
# Store the interaction in conversation history
106+
self.conversation.extend([
107+
{"role": "user", "content": messages[-1]["content"]},
108+
{"role": "assistant", "content": response}
109+
])
110+
111+
return response
112+
113+
except Exception as e:
114+
logger.error(f"Error in get_response_async: {str(e)}")
115+
raise
116+
117+
def start_interactive_session(self):
118+
"""Synchronous wrapper for interactive session"""
119+
loop = asyncio.new_event_loop()
120+
asyncio.set_event_loop(loop)
121+
loop.run_until_complete(self.start_interactive_session_async())
122+
loop.close()
123+
124+
async def start_interactive_session_async(self):
125+
"""Start an interactive session for focus analysis"""
126+
print("ODV Focus Analysis Session Started")
127+
128+
# Get initial analysis
129+
initial_analysis = await self.get_response_async()
130+
print("\nODV:", initial_analysis)
131+
132+
while True:
133+
user_input = await asyncio.get_event_loop().run_in_executor(None, input, "\nYou: ")
134+
if user_input.lower() == 'exit':
135+
print("\nODV: Focus analysis session ended.")
136+
break
137+
138+
response = await self.get_response_async(user_input)
139+
print("\nODV:", response)
140+
141+
"""
142+
# Example usage:
143+
from nodetools.utilities.credentials import CredentialManager
144+
from nodetools.utilities.generic_pft_utilities import GenericPFTUtilities
145+
from nodetools.utilities.db_manager import DBConnectionManager
146+
from nodetools.task_processing.task_management import PostFiatTaskGenerationSystem
147+
from nodetools.task_processing.user_context_parsing import UserTaskParser
148+
from nodetools.ai.openrouter import OpenRouterTool
149+
150+
# Initialize components
151+
cm = CredentialManager(password='your_password')
152+
pft_utils = GenericPFTUtilities()
153+
db_manager = DBConnectionManager()
154+
task_management = PostFiatTaskGenerationSystem()
155+
user_parser = UserTaskParser(
156+
task_management_system=task_management,
157+
generic_pft_utilities=pft_utils
158+
)
159+
openrouter = OpenRouterTool()
160+
161+
# Create analyzer instance
162+
analyzer = ODVFocusAnalyzer(
163+
account_address='your_address',
164+
openrouter=openrouter,
165+
user_context_parser=user_parser,
166+
pft_utils=pft_utils
167+
)
168+
169+
# Get analysis
170+
response = analyzer.get_response("Your prior conversation here")
171+
print(response)
172+
173+
# Or start interactive session
174+
analyzer.start_interactive_session()
175+
"""

0 commit comments

Comments
 (0)