@@ -118,7 +118,7 @@ def connect_gpt_oai_1(self, messages, **kwargs):
118118
119119 return response
120120
121- def update_history (self , role , content , encoded_image = None , replace = False ):
121+ def update_history (self , role , content , encoded_image = None , replace = False ):
122122 if role == "system" :
123123 if len (self .history ) > 0 :
124124 self .history [0 ]["content" ] = content
@@ -132,35 +132,26 @@ def update_history(self, role, content, encoded_image=None, replace=False):
132132 self .history .append ({"role" : role , "content" : content })
133133 num_AI_messages = (len (self .context_window ) - 1 ) // 2
134134 if num_AI_messages == self .keep_last_n_messages :
135- print ("doing active forgetting" )
135+ print ("doing active forgetting" )
136136 # we forget the oldest AI message and corresponding answer
137137 self .context_window .pop (1 )
138138 self .context_window .pop (1 )
139139 new_message = {"role" : role , "content" : content }
140140 else :
141- if encoded_image is None :
142- self .history .append ({"role" : role , "content" : content })
143- num_AI_messages = (len (self .context_window ) - 1 ) // 2
144- if num_AI_messages == self .keep_last_n_messages :
145- print ("doing active forgetting" )
146- # we forget the oldest AI message and corresponding answer
147- self .context_window .pop (1 )
148- self .context_window .pop (1 )
149- self .context_window .append ({"role" : role , "content" : content })
150- else :
151- message = {
152- "role" : "user" ,
153- "content" : [
154- {"type" : "text" , "text" : content },
155- {
156- "type" : "image_url" ,
157- "image_url" : {
158- "url" : f"data:image/png;base64,{ encoded_image } "
159- },
160- },
161- ],
141+ new_message = {"role" : "user" , "content" : [
142+ {"type" : "text" , "text" : "" },
143+ {"type" : "image_url" , "image_url" : {
144+ "url" : f"data:image/jpeg;base64,{ encoded_image } " }
162145 }
163- self .context_window .append (message )
146+ ]}
147+
148+ self .history .append (new_message )
149+
150+ if replace == True :
151+ if len (self .context_window ) == 2 :
152+ self .context_window [1 ] = new_message
153+ else :
154+ self .context_window .append (new_message )
164155
165156 def clean_context_window (self ):
166157 while len (self .context_window ) > 1 :
@@ -288,66 +279,6 @@ def update_system_prompt(self, sandbox):
288279 # update both history and context window
289280 self .update_history ("system" , self .system_prompt )
290281
291-
292- class MutationLLM (LLM ):
293- def __init__ (self , config ):
294- super ().__init__ (config )
295-
296- def update_system_prompt (self , sandbox ):
297- from amadeusgpt .system_prompts .mutation import _get_system_prompt
298-
299- self .system_prompt = _get_system_prompt (sandbox )
300- # update both history and context window
301- self .update_history ("system" , self .system_prompt )
302-
303- def speak (self , sandbox ):
304- # TODO maybe we don't need to keep the history
305- """
306- Speak to the chat channel
307- """
308- # query = "Please start. Make sure you provide one task program a time. Thanks a million!"
309- query = "Please start. Thanks a million!"
310- self .update_system_prompt (sandbox )
311- self .update_history ("user" , query , replace = True )
312- response = self .connect_gpt (self .context_window , max_tokens = 4000 )
313- text = response .choices [0 ].message .content .strip ()
314- sandbox .chat_channel .chain_of_thought .append (response )
315- return text
316-
317-
318- class BreedLLM (LLM ):
319- def __init__ (self , config ):
320- super ().__init__ (config )
321-
322- def update_system_prompt (self , sandbox ):
323- from amadeusgpt .system_prompts .breed import _get_system_prompt
324-
325- behavior1_docs , behavior2_docs , composition_type = sandbox .get_breed_info ()
326-
327- self .system_prompt = _get_system_prompt (
328- behavior1_docs , behavior2_docs , composition_type
329- )
330-
331- # update both history and context window
332-
333- self .update_history ("system" , self .system_prompt )
334-
335- def speak (self , sandbox ):
336- # TODO maybe we don't need to keep the history
337- """
338- Speak to the chat channel
339- """
340- query = "Now write the template function. Make sure your answer is concise and don't mention anything about filtering such as smooth_window or min_window\n "
341- self .update_system_prompt (sandbox )
342- self .update_history ("user" , query , replace = True )
343-
344- response = self .connect_gpt (self .context_window , max_tokens = 400 )
345- text = response .choices [0 ].message .content .strip ()
346- sandbox .chat_channel .chain_of_thought .append (response )
347-
348- return text
349-
350-
351282class DiagnosisLLM (LLM ):
352283 """
353284 Resource management for testing and error handling
0 commit comments