Copilot
This is the Copilot interface.
class Copilot(AbstractPlugin):
"""
Define the Copilot interface.
All copilots implement the Plugin interface, so it is easy to use a copilot as a plugin in another copilot.
"""
def __init__(self, config: Dict):
"""
Configure the copilot without initialization.
Make sure the `type` in the config file is set to "copilot".
:param config: configures read from its config file (default to "config.yaml")
"""
super(Copilot, self).__init__(config)
assert self.type=='copilot'
@abc.abstractmethod
def initialize(self):
"""
Initialize the framework and resources
"""
pass
@abc.abstractmethod
def finalize(self):
"""
Finalize the framework and resources
"""
pass
@abc.abstractmethod
def run_interaction(self):
"""
Run the copilot interaction.
This is the main logic of the copilot,
so write your special task pipeline here.
"""
pass
@abc.abstractmethod
def run(self):
"""
The entrance of the copilot task pipeline.
This method does the initialization, runs the interaction, and does the finalization.
"""
pass
def command(self, command_name: str, param: Any, **kwargs) -> Any:
"""
The Plugin command method.
Ignore this method if you are not expect your copilot acting as a plugin in other copilots,
or you have to override it as the same way of which in developing Plugins.
:param command_name: command name
:param param: command parameters
:param kwargs: reserved, not recommend to use
:return: the command result
"""
return {}
We provided a general purposed Copilot implementation: the BasicCopilot.
It is generally not necessary to change the framework or code of a Copilot,
just change its "config.yaml" adding more necessary component or replacing existed components for specific tasks.
The General Purposed Copilot Implementation
group_id: org.concopilot.basic.copilot
artifact_id: basic-copilot
Framework
When an instance of this Copilot is created and run, it executes below tasks step by step:
-
__init__-
resource_manager:- construct the Resource Manager according to the
config.resource_managersection in the "config.yaml" file. - construct all resources under the
resource_managersection (currently the resources are not initialized)
- construct the Resource Manager according to the
-
storage: construct the Storage for the Copilot memery according to theconfig.storagesection in the "config.yaml" file. -
user_interface: construct the User Interface according to theconfig.user_interfacesection in the "config.yaml" file. -
cerebrum: construct the Cerebrum instance to take advantages from LLM for task analysis according to theconfig.cerebrumsection in the "config.yaml" file. -
plugin_manager:- construct the Plugin Manager according to the
config.plugin_managersection in the "config.yaml" file. - construct the Plugin Prompt Generator according to the
plugin_prompt_generatorsection under theplugin_managersection in the "config.yaml" file. - construct all plugins under the
plugin_managersection (currently the plugins are not initialized)
- construct the Plugin Manager according to the
-
message_manager: construct the Message Manager according to theconfig.message_managersection in the "config.yaml" file. -
interactor: construct the Interactor according to theconfig.interactorsection in the "config.yaml" file. theresource_manager,cerebrum,plugin_manager, andmessage_managerwill be passed to the interactor as it is the central coordinator.
-
-
initialize
-
initialize the
resource_manager, and all resources under it. The resources can only be used after this step. -
config resources for all components. A component can only access its necessary resources after this step.
-
config a context for the Copilot so that every component can access below global components by using its
self.contextfield:storageassets(additional materials apart from chat histories to be passed to Cerebrum LLM to analysis if necessary)user_interface
-
initialize the
interactor- config general prompts by calling the
interactor.setup_promptsmethod. This step is to config the general prompts for the interactor as well as its subcomponents' prompt if applicable. Details will vary for different kinds of interactor. - config the
plugin_managerand all plugins by calling theinteractor.setup_pluginsmethod. This step is for configuring plugins as well as pass all plugins to the cerebrum object for potential necessary initialization (such as the OpenAI function call).
- config general prompts by calling the
-
-
run interaction: run the main task loop defined by the Interactor.
-
finalize: release/close all resources if necessary and exit the program.
Config
-
resource_manager: Specify a Resource Manager to manager resources. Add all necessary resources under the resource manager config also. -
cerebrum: Add a cerebrum component for task analysis. A cerebrum usually backed on a LLM to analyse user requirements and plugin information. -
interactor: This is the central part of a Copilot. It controls the information dispatching, task coordinating, and plugin calls in a Copilot. Different task may need different "Interaction Framework". Replace this component rather than the Copilot itself for specific tasks. -
plugin_manager: Specify a Plugin Manager to manage plugins. Add all necessary plugins under the plugin manager config section also. -
message_manager: Specify a Message Manager to deal with Cerebrum response. -
storage: Specify this for Copilot memory. -
user_interface: Specify this to interact with users.
Usage
Choose suitable component from our website for your specific tasks,
and use them to modify the Copilot "config.yaml",
then use our conpack tool to run the Copilot.
Here is a runnable "config.yaml" example.