# Written by retoor@molodetz.nl
# This script demonstrates an AI chatbot using the ReplikaAgent class from the ragent library. It allows interactive text-based communication with a Replika-like AI agent. The agent is initialized with a given name and API key, and it engages in conversation with users through standard input and output.
# External Import: ragent
# MIT License: This software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and non-infringement. In no event shall the authors or copyright holders be liable for any claim, damages, or other liability, whether in an action of contract, tort, or otherwise, arising from, out of, or in connection with the software or the use or other dealings in the software.
import ragent as agent
def main(name="Katya", api_key=agent.OPENAI_API_KEY):
replika = agent.ReplikaAgent(name=name, api_key=api_key)
try:
while True:
user_input = input("You: ")
if not user_input.strip():
continue
response = replika.communicate(user_input)
print(f"{name}: {response}")
except KeyboardInterrupt:
pass
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("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("Ask her to repeat what it said before. It will repeat that.")
main()