@gpt-mind/core
v0.1.0
Published
The core classes of the GPT Mind library
Downloads
1
Readme
GPT Mind Core
The Mind library is a JavaScript library for building conversational agents that can generate responses based on a set of pre-defined rules. It allows you to define a state map, bindings between agents, and a set of agents that can generate responses based on input statements.
Installation
You can install the Mind library using npm:
npm install @gpt-mind/core
Usage
To use the Mind library, you need to create an instance of the Mind class and pass it a configuration object. The configuration object should have the following properties:
- stateMap: An object representing the current state of the conversation.
- bindings: An object mapping agents to other agents that they are bound to.
- agents: An object containing the definitions of the agents.
- start: An object representing the initial state of the conversation.
- sources: An object mapping agents to functions that generate responses based on the current state of the conversation.
Here is an example of how to use the Mind library:
import { Mind } from 'mind-library';
imoport OpenAI from 'openai-api';
const openAI = new OpenAI('sk-...');
function complete(query, options) {
return openAI.complete({
engine: 'davinci',
prompt: query,
maxTokens: 100,
temperature: 0.9,
topP: 1,
presencePenalty: 0,
frequencyPenalty: 0,
bestOf: 1,
n: 1,
stream: false,
stop: ['\n', '###'],
...options
});
}
const config = {
stateMap: {},
bindings: {
"input": ["agent1"],
"agent1": ['agent2'],
"agent2": ['agent3'],
"agent3": ['output', 'agent4'],
"agent4": ["internal"],
"internal": ['canVisualize', 'think'],
"canVisualize": ["visualize"],
"visualize": ["internal"],
"output": []
},
agents: {
"agent1": "generate a description of the statement \"{{input}}\"",
"agent2": "generate a response to the statement \"{{agent1}}\"",
"agent3": "generate a response given statements \"{{agent1}}\"\nand statements \"{{agent2}}\"",
"agent4": "generate a response free of social mind to the statement \"{{agent1,agent2}}\"",
"canVisualize": "is there visualizable imagery in the statement \"{{agent1,agent2}}\"",
"visualize": "generate a detailed description of the imagery in the statement \"{{agent1,agent2}}\"",
},
start: {},
sources: {
"agent1": (agent, query, options) => complete(query, options),
"agent2": (agent, query, options) => complete(query, options),
"agent3": (agent, query, options) => complete(query, options),
"agent4": (agent, query, options) => complete(query, options),
"canVisualize": (agent, query, options) => complete(query, options),
"visualize": (agent, query, options) => Automatic111.txt2img(query, "", { steps: 20 }),
"think": (agent, query, options) => complete(query, options),
}
};
const mind = new Mind(config);
mind.on('output', (event, output) => {
console.log(output);
});
mind.input('agent1', 'Hello');
In this example, we create an instance of the Mind class with a configuration object that defines a set of agents that can generate responses based on input statements. We then register an event listener for the output event, which is triggered when an agent generates a response. Finally, we call the input method of the mind instance to start the conversation with the agent1 agent.
API
Mind(config: Object)
The Mind class constructor takes a configuration object as an argument. The configuration object should have the following properties:
stateMap
: An object representing the current state of the conversation.
bindings
: An object mapping agents to other agents that they are bound to.
agents
: An object containing the definitions of the agents.
start
: An object representing the initial state of the conversation.
sources
: An object mapping agents to functions that generate responses based on the current state of the conversation.
on(event: string, callback: (event: string, output: string) => void)
Registers an event listener for the specified event. The callback function is called when the event is triggered, and is passed two arguments: the name of the event, and the output generated by the agent that triggered the event.
once(event: string, callback: (event: string, output: string) => void)
Registers an event listener for the specified event that will only be called once. The callback function is called when the event is triggered, and is passed two arguments: the name of the event, and the output generated by the agent that triggered the event.
off(event: string, callback: (event: string, output: string) => void)
Removes the specified event listener.
emit(event: string, output: any)
Triggers the specified event with the given output.
input(agent: string, query: string)
Sets the input for the specified agent and triggers the conversation.
run(agent: string)
Runs the specified agent and its bound agents.
complete(agent: any, query: string, options: any)
Generates a response for the specified agent with the given query and options.
Contributing
Contributions are welcome!
Please read the [contributing guidelines](