Refactor.

This commit is contained in:
retoor 2025-02-24 14:43:29 +01:00
parent 1b377c9303
commit 1b3200c6da
5 changed files with 16 additions and 24 deletions

View File

@ -8,6 +8,6 @@
# MIT License # MIT License
if __name__ == '__main__': if __name__ == "__main__":
import ragent import ragent
ragent.main() ragent.main()

View File

@ -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: # 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 ragent
import json import json
@ -22,8 +23,8 @@ def main():
] ]
print(agent.communicate(message_batch)) print(agent.communicate(message_batch))
response = agent.communicate( response = agent.communicate(
"What is the apples divided by the oranges " "What are the apples divided by the oranges "
"and what is your name btw?" "and what is your name by the way?"
) )
print("Response:", response) print("Response:", response)
print("Transcript:") print("Transcript:")

View File

@ -1,10 +1,10 @@
# Written by retoor@molodetz.nl # 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 # MIT License
@ -33,8 +33,7 @@ import ragent as agent
def main(api_key=None): def main(api_key=None):
if api_key is None: if api_key is None:
api_key = agent.OPENAI_API_KEY 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("This is a demo of a conversation between Hermione Granger and Draco Malfoy from the Harry Potter world.\n")
print()
message_count = 0 message_count = 0

View File

@ -10,7 +10,7 @@
import ragent as agent import ragent as agent
def main(name="Katya", api_key=agent.OPENAI_API_KEY): 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: try:
while True: while True:
user_input = input("You: ") user_input = input("You: ")
@ -26,8 +26,8 @@ if __name__ == "__main__":
name = 'Katya' name = 'Katya'
print(f"This is a demo of a Replika with the name '{name}'") print(f"This is a demo of a Replika with the name '{name}'")
print(f"{name} is very social and engaging.") 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("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.") print("Ask her to repeat what it said before. It will repeat that.")
main() main()

View File

@ -30,11 +30,7 @@
from ragent import Agent, OPENAI_API_KEY from ragent import Agent, OPENAI_API_KEY
def echo(text: str) -> str:
def echo(text: str)->str:
"""
Gives echo of current text
"""
print("WHAHAHAHA") print("WHAHAHAHA")
return text return text
@ -43,21 +39,18 @@ class Tools:
def __init__(self): def __init__(self):
self.data = {} self.data = {}
def remember(self,key, value) -> None: def remember(self, key, value) -> None:
""" Store a value given by user in memory """
self.data[key] = value self.data[key] = value
print(f"XXXXXXXXX Remembering {key}:{value}") print(f"XXXXXXXXX Remembering {key}:{value}")
def recall(self,key: str) -> str: def recall(self, key: str) -> str:
""" Returns a value requested by user """
print(f"XXXXXXXX Recalling {key}") print(f"XXXXXXXX Recalling {key}")
return self.data.get(key) return self.data.get(key)
def main(api_key=None): def main(api_key=None):
if api_key is None: if api_key is None:
api_key = OPENAI_API_KEY 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()) agent.set_tools(Tools())
while True: while True:
user_input = input("> ") user_input = input("> ")
@ -66,6 +59,5 @@ def main(api_key=None):
response = agent.communicate(user_input) response = agent.communicate(user_input)
print(response) print(response)
if __name__ == '__main__': if __name__ == '__main__':
main() main()