You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.2 KiB
40 lines
1.2 KiB
from swarms import Conversation, AbstractLLM
|
|
|
|
|
|
# Run the language model in a loop for n iterations
|
|
def SimpleAgent(
|
|
llm: AbstractLLM = None, iters: int = 10, *args, **kwargs
|
|
):
|
|
"""Simple agent conversation
|
|
|
|
Args:
|
|
llm (_type_): _description_
|
|
iters (int, optional): _description_. Defaults to 10.
|
|
"""
|
|
try:
|
|
conv = Conversation(*args, **kwargs)
|
|
for i in range(iters):
|
|
user_input = input("User: ")
|
|
conv.add("user", user_input)
|
|
if user_input.lower() == "quit":
|
|
break
|
|
task = (
|
|
conv.return_history_as_string()
|
|
) # Get the conversation history
|
|
out = llm(task)
|
|
conv.add("assistant", out)
|
|
print(
|
|
f"Assistant: {out}",
|
|
)
|
|
conv.display_conversation()
|
|
conv.export_conversation("conversation.txt")
|
|
|
|
except Exception as error:
|
|
print(f"[ERROR][SimpleAgentConversation] {error}")
|
|
raise error
|
|
|
|
except KeyboardInterrupt:
|
|
print("[INFO][SimpleAgentConversation] Keyboard interrupt")
|
|
conv.export_conversation("conversation.txt")
|
|
raise KeyboardInterrupt
|