Myself
Myself is a Rust library for building conversational agents powered by OpenAI's language model. It provides a simple Agent abstraction to manage interactions and memory, making it easy to create natural language interfaces for various applications.
⚠️ Warning
Please note that Myself is currently under development and is not yet suitable for production use. While you are welcome to try it out and provide feedback, we caution that it may have an incomplete implementation and may not function as intended. Our top priorities at this time are to improve the documentation and complete the list of features.
Features
- Simple Agent abstraction.
- Manage interactions and memory.
- Support SQLite database.
- Support GPT-3 OpenAI's language model.
- Support other SQL databases (e.g. PostgreSQL and MySQL).
- Support other language models (we plan to add support for other open source large language models).
- Improve documentation, add more examples.
Installation
Add the following to your Cargo.toml file:
[]
= "0.1.0"
Or use cargo:
Example Usage
You need to set the OPENAI_API_KEY environment variable to your OpenAI API key. You can get one here.
use dotenv;
use AgentBuilder;
async
You can run the other examples in the examples directory. Only clone the repository and run one of minimal, complex, graphql or neural-linux examples:
How it works
The main idea behind Myself is to provide a simple abstraction for building conversational agents. The Agent abstraction manages interactions and memory, making it easy to create natural language interfaces for various applications.
An Agent is a individual that can interact with the world. It has a name, a personality (a.k.a. constitution), and a memory. The name is used to address the agent, the personality is used to generate responses, and the memory is used to keep track of the context of the conversation.
In myself the Agent abstraction is implemented by the Agent struct. The Agent struct is responsible for managing interactions and memory. It is also responsible for generating responses using the OpenAI language model. The Agent struct is initialized with a AgentBuilder struct, which is used to configure the agent.
For example, if you want to create an agent named Bob, you can do the following:
use AgentBuilder;
async
For example, you can set the constitution and the default user name of the agent:
use AgentBuilder;
async
In the example above, we set the name of the agent to Linux Server, the default user name is User, the constitution to a string that describes the personality of the agent, and the default memory size to 50.
The Agent provides a methods to interact in different instances. For example, you can init (create) a new interaction with the agent:
use AgentBuilder;
async
And you can interact with it using the interact method:
use AgentBuilder;
async
In the example above, we create a new interaction with the agent, and then we interact with it using the interact method. The interact method takes the interaction id and the message as arguments, and returns a response.
The Agent also provides a method to interact with the default interaction:
use AgentBuilder;
async
The Interaction structure have the following form:
The user_name field is used to address the user in the conversation. The long_term_memory field is used to store the constitution of the the agent for this interaction. The short_term_memory field is used to store the last messages of the conversation in a buffer represented by a string. The short_term_memory_size field is used to set the size of the buffer measured as the number of lines (separated by '\n') in the dynamic_memory.