From 1b3200c6da64747d702991c461843feb103435e5 Mon Sep 17 00:00:00 2001 From: retoor Date: Mon, 24 Feb 2025 14:43:29 +0100 Subject: [PATCH] Refactor. --- src/ragent/__main__.py | 2 +- src/ragent/demo_batch_messages.py | 5 +++-- src/ragent/demo_discuss.py | 7 +++---- src/ragent/demo_replika.py | 8 ++++---- src/ragent/demo_tools.py | 18 +++++------------- 5 files changed, 16 insertions(+), 24 deletions(-) diff --git a/src/ragent/__main__.py b/src/ragent/__main__.py index 8fc6597..4fe9314 100644 --- a/src/ragent/__main__.py +++ b/src/ragent/__main__.py @@ -8,6 +8,6 @@ # MIT License -if __name__ == '__main__': +if __name__ == "__main__": import ragent ragent.main() \ No newline at end of file diff --git a/src/ragent/demo_batch_messages.py b/src/ragent/demo_batch_messages.py index f71433f..40884a7 100644 --- a/src/ragent/demo_batch_messages.py +++ b/src/ragent/demo_batch_messages.py @@ -6,6 +6,7 @@ # MIT License: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + import ragent import json @@ -22,8 +23,8 @@ def main(): ] print(agent.communicate(message_batch)) response = agent.communicate( - "What is the apples divided by the oranges " - "and what is your name btw?" + "What are the apples divided by the oranges " + "and what is your name by the way?" ) print("Response:", response) print("Transcript:") diff --git a/src/ragent/demo_discuss.py b/src/ragent/demo_discuss.py index 009d283..d06d9f0 100644 --- a/src/ragent/demo_discuss.py +++ b/src/ragent/demo_discuss.py @@ -1,10 +1,10 @@ # Written by retoor@molodetz.nl -# This script simulates a conversation between Hermione Granger and Draco Malfoy from the Harry Potter world. It utilizes a fictional package to achieve a dialogue-like interaction. +# This script simulates a conversation between Hermione Granger and Draco Malfoy from the Harry Potter world using a fictional package to create a dialogue-like interaction. -# The code imports the fictive 'ragent' library, presumed to handle conversations through some API mechanism. +# The code imports the fictive 'ragent' library, which is presumed to handle conversations through some API mechanism. # MIT License @@ -33,8 +33,7 @@ import ragent as agent def main(api_key=None): if api_key is None: api_key = agent.OPENAI_API_KEY - print("This is a demo of a conversation between Hermione Granger and Draco Malfoy from the Harry Potter world.") - print() + print("This is a demo of a conversation between Hermione Granger and Draco Malfoy from the Harry Potter world.\n") message_count = 0 diff --git a/src/ragent/demo_replika.py b/src/ragent/demo_replika.py index b2fbfb4..4d3365e 100644 --- a/src/ragent/demo_replika.py +++ b/src/ragent/demo_replika.py @@ -10,7 +10,7 @@ import ragent as agent def main(name="Katya", api_key=agent.OPENAI_API_KEY): - replika = agent.ReplikaAgent(name=name, api_key=api_key,temperature=0.1) + replika = agent.ReplikaAgent(name=name, api_key=api_key, temperature=0.1) try: while True: user_input = input("You: ") @@ -26,8 +26,8 @@ if __name__ == "__main__": name = 'Katya' print(f"This is a demo of a Replika with the name '{name}'") print(f"{name} is very social and engaging.") - print("It's your AI companion but way cheaper than the real Replika!") + print("It's your AI companion but much cheaper than the real Replika!") print("Besides talking like Replika, it isn't a goldfish like Replika. It remembers everything you say.") - print("Give Replika two apples and ask how many apples it got. It will answer the right amount.") + print("Give Replika two apples and ask how many apples it got. It will answer the correct amount.") print("Ask her to repeat what it said before. It will repeat that.") - main() + main() \ No newline at end of file diff --git a/src/ragent/demo_tools.py b/src/ragent/demo_tools.py index d801590..e3754cb 100644 --- a/src/ragent/demo_tools.py +++ b/src/ragent/demo_tools.py @@ -30,11 +30,7 @@ from ragent import Agent, OPENAI_API_KEY - -def echo(text: str)->str: - """ - Gives echo of current text - """ +def echo(text: str) -> str: print("WHAHAHAHA") return text @@ -43,21 +39,18 @@ class Tools: def __init__(self): self.data = {} - def remember(self,key, value) -> None: - """ Store a value given by user in memory """ + def remember(self, key, value) -> None: self.data[key] = value print(f"XXXXXXXXX Remembering {key}:{value}") - def recall(self,key: str) -> str: - """ Returns a value requested by user """ + def recall(self, key: str) -> str: print(f"XXXXXXXX Recalling {key}") return self.data.get(key) - def main(api_key=None): if api_key is None: api_key = OPENAI_API_KEY - agent = Agent("You execute tools.","ragent_tools_Example",api_key=api_key,temperature=0.1) + agent = Agent("You execute tools.", "ragent_tools_Example", api_key=api_key, temperature=0.1) agent.set_tools(Tools()) while True: user_input = input("> ") @@ -66,6 +59,5 @@ def main(api_key=None): response = agent.communicate(user_input) print(response) - if __name__ == '__main__': - main() + main() \ No newline at end of file