Skip to content

armgit / letta

Public Imported from GitHub
0

Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.

fix: patch bug in airo wrapper (#993)

Charles Packer6c660bea9dea
diff --git a/memgpt/local_llm/llm_chat_completion_wrappers/airoboros.py b/memgpt/local_llm/llm_chat_completion_wrappers/airoboros.py
index 609b2b9b1..bbcab1b95 100644
--- a/memgpt/local_llm/llm_chat_completion_wrappers/airoboros.py
+++ b/memgpt/local_llm/llm_chat_completion_wrappers/airoboros.py
@@ -124,7 +124,7 @@ class Airoboros21Wrapper(LLMChatCompletionWrapper):
# Last are the user/assistant messages
for message in messages[1:]:
- assert message["role"] in ["user", "assistant", "function"], message
+ assert message["role"] in ["user", "assistant", "function", "tool"], message
if message["role"] == "user":
if self.simplify_json_content:
@@ -139,7 +139,7 @@ class Airoboros21Wrapper(LLMChatCompletionWrapper):
# need to add the function call if there was one
if "function_call" in message and message["function_call"]:
prompt += f"\n{create_function_call(message['function_call'])}"
- elif message["role"] == "function":
+ elif message["role"] in ["function", "tool"]:
# TODO find a good way to add this
# prompt += f"\nASSISTANT: (function return) {message['content']}"
prompt += f"\nFUNCTION RETURN: {message['content']}"
@@ -336,7 +336,7 @@ class Airoboros21InnerMonologueWrapper(Airoboros21Wrapper):
# Last are the user/assistant messages
for message in messages[1:]:
- assert message["role"] in ["user", "assistant", "function"], message
+ assert message["role"] in ["user", "assistant", "function", "tool"], message
if message["role"] == "user":
# Support for AutoGen naming of agents
@@ -364,7 +364,7 @@ class Airoboros21InnerMonologueWrapper(Airoboros21Wrapper):
inner_thoughts = message["content"]
if "function_call" in message and message["function_call"]:
prompt += f"\n{create_function_call(message['function_call'], inner_thoughts=inner_thoughts)}"
- elif message["role"] == "function":
+ elif message["role"] in ["function", "tool"]:
# TODO find a good way to add this
# prompt += f"\nASSISTANT: (function return) {message['content']}"
prompt += f"\nFUNCTION RETURN: {message['content']}"
diff --git a/memgpt/local_llm/llm_chat_completion_wrappers/chatml.py b/memgpt/local_llm/llm_chat_completion_wrappers/chatml.py
index 9992b4bde..b7526628e 100644
--- a/memgpt/local_llm/llm_chat_completion_wrappers/chatml.py
+++ b/memgpt/local_llm/llm_chat_completion_wrappers/chatml.py
@@ -204,7 +204,7 @@ class ChatMLInnerMonologueWrapper(LLMChatCompletionWrapper):
# Last are the user/assistant messages
for message in messages[1:]:
- assert message["role"] in ["user", "assistant", "tool"], message
+ assert message["role"] in ["user", "assistant", "function", "tool"], message
if message["role"] == "user":
# Support for AutoGen naming of agents
@@ -227,7 +227,7 @@ class ChatMLInnerMonologueWrapper(LLMChatCompletionWrapper):
prompt += f"\n<|im_start|>{role_str}\n{msg_str.strip()}<|im_end|>"
- elif message["role"] == "tool":
+ elif message["role"] in ["tool", "function"]:
if self.allow_function_role:
role_str = message["role"]
msg_str = self._compile_function_response(message)
diff --git a/memgpt/local_llm/llm_chat_completion_wrappers/dolphin.py b/memgpt/local_llm/llm_chat_completion_wrappers/dolphin.py
index 69c9f0b66..6edb78086 100644
--- a/memgpt/local_llm/llm_chat_completion_wrappers/dolphin.py
+++ b/memgpt/local_llm/llm_chat_completion_wrappers/dolphin.py
@@ -151,7 +151,7 @@ class Dolphin21MistralWrapper(LLMChatCompletionWrapper):
# Last are the user/assistant messages
for message in messages[1:]:
- assert message["role"] in ["user", "assistant", "function"], message
+ assert message["role"] in ["user", "assistant", "function", "tool"], message
if message["role"] == "user":
if self.simplify_json_content:
@@ -172,7 +172,7 @@ class Dolphin21MistralWrapper(LLMChatCompletionWrapper):
if "function_call" in message and message["function_call"]:
prompt += f"\n{create_function_call(message['function_call'])}"
prompt += f"{IM_END_TOKEN}"
- elif message["role"] == "function":
+ elif message["role"] in ["function", "tool"]:
# TODO find a good way to add this
# prompt += f"\nASSISTANT: (function return) {message['content']}"
prompt += f"\n{IM_START_TOKEN}assistant"
diff --git a/memgpt/local_llm/llm_chat_completion_wrappers/simple_summary_wrapper.py b/memgpt/local_llm/llm_chat_completion_wrappers/simple_summary_wrapper.py
index b0cebea07..82fcf8020 100644
--- a/memgpt/local_llm/llm_chat_completion_wrappers/simple_summary_wrapper.py
+++ b/memgpt/local_llm/llm_chat_completion_wrappers/simple_summary_wrapper.py
@@ -94,7 +94,7 @@ class SimpleSummaryWrapper(LLMChatCompletionWrapper):
# Last are the user/assistant messages
for message in messages[1:]:
- assert message["role"] in ["user", "assistant", "function"], message
+ assert message["role"] in ["user", "assistant", "function", "tool"], message
if message["role"] == "user":
if self.simplify_json_content:
@@ -109,7 +109,7 @@ class SimpleSummaryWrapper(LLMChatCompletionWrapper):
# need to add the function call if there was one
if message["function_call"]:
prompt += f"\n{create_function_call(message['function_call'])}"
- elif message["role"] == "function":
+ elif message["role"] in ["function", "tool"]:
# TODO find a good way to add this
# prompt += f"\nASSISTANT: (function return) {message['content']}"
prompt += f"\nFUNCTION RETURN: {message['content']}"
diff --git a/memgpt/local_llm/llm_chat_completion_wrappers/zephyr.py b/memgpt/local_llm/llm_chat_completion_wrappers/zephyr.py
index fe5853466..a003d50da 100644
--- a/memgpt/local_llm/llm_chat_completion_wrappers/zephyr.py
+++ b/memgpt/local_llm/llm_chat_completion_wrappers/zephyr.py
@@ -82,7 +82,7 @@ class ZephyrMistralWrapper(LLMChatCompletionWrapper):
return json.dumps(airo_func_call, indent=2, ensure_ascii=JSON_ENSURE_ASCII)
for message in messages[1:]:
- assert message["role"] in ["user", "assistant", "function"], message
+ assert message["role"] in ["user", "assistant", "function", "tool"], message
if message["role"] == "user":
if self.simplify_json_content:
@@ -103,7 +103,7 @@ class ZephyrMistralWrapper(LLMChatCompletionWrapper):
if "function_call" in message and message["function_call"]:
prompt += f"\n{create_function_call(message['function_call'])}"
prompt += f"{IM_END_TOKEN}"
- elif message["role"] == "function":
+ elif message["role"] in ["function", "tool"]:
# TODO find a good way to add this
# prompt += f"\nASSISTANT: (function return) {message['content']}"
prompt += f"\n<|assistant|>"
@@ -252,7 +252,7 @@ class ZephyrMistralInnerMonologueWrapper(ZephyrMistralWrapper):
# Last are the user/assistant messages
for message in messages[1:]:
- assert message["role"] in ["user", "assistant", "function"], message
+ assert message["role"] in ["user", "assistant", "function", "tool"], message
if message["role"] == "user":
if self.simplify_json_content:
@@ -268,7 +268,7 @@ class ZephyrMistralInnerMonologueWrapper(ZephyrMistralWrapper):
inner_thoughts = message["content"]
if "function_call" in message and message["function_call"]:
prompt += f"\n{create_function_call(message['function_call'], inner_thoughts=inner_thoughts)}"
- elif message["role"] == "function":
+ elif message["role"] in ["function", "tool"]:
# TODO find a good way to add this
# prompt += f"\nASSISTANT: (function return) {message['content']}"
prompt += f"\nFUNCTION RETURN: {message['content']}"