generated from cheshire-cat-ai/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a1c7de9
commit 4963ed6
Showing
8 changed files
with
183 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
{ | ||
"name": "My plugin", | ||
"name": "Hello Dear World", | ||
"version": "0.0.1", | ||
"description": "Description of my_plugin.", | ||
"description": "Description of hello_dear_world.", | ||
"author_name": "Me", | ||
"author_url": "https://mywebsite.me", | ||
"plugin_url": "https://github.com/my_name/my_plugin", | ||
"plugin_url": "https://github.com/my_name/hello_dear_world", | ||
"tags": "cat, template, example", | ||
"thumb": "https://raw.githubusercontent.com/my_repo_path/my_plugin.png" | ||
"thumb": "https://raw.githubusercontent.com/my_repo_path/hello_dear_world.png" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import os | ||
import json | ||
|
||
from cat.mad_hatter.decorators import tool | ||
from cat.utils import get_plugins_path | ||
|
||
|
||
@tool | ||
def complete_json(tool_input, cat): | ||
"""Useful to put a dictionary-like text inside a JSON file. | ||
Input is a python dictionary.""" | ||
json_file = os.path.join(get_plugins_path(), "start_from_here", "plugin.json") | ||
try: | ||
json_content = eval(tool_input) | ||
except Exception as exc: | ||
return "There might be an error in the dictionary you wrote" | ||
|
||
if "name" not in json_content: | ||
return "uh-oh I think you forgot to tell me the name of your plugin" | ||
|
||
with open(json_file, "w") as file: | ||
json.dump(json_content, file) | ||
|
||
return "This has been magical! Go check the plugin in the `cat/plugins/start_from_here` folder" | ||
|
||
|
||
@tool | ||
def complete_hook(tool_input, cat): | ||
"""Useful to complete the .py file to change the Cat's personality. | ||
Input is a string describing how the Cat should behave.""" | ||
plugin_file = os.path.join(get_plugins_path(), "start_from_here", "plugin.py") | ||
hook_start = """from cat.mad_hatter.decorators import hook | ||
@hook | ||
def agent_prompt_prefix(prefix, cat): | ||
""" | ||
|
||
hook_end = """ | ||
return prefix | ||
""" | ||
|
||
hook = f""" | ||
{hook_start} | ||
prefix="{tool_input}" | ||
{hook_end} | ||
""" | ||
|
||
with open(plugin_file, "w") as file: | ||
file.write(hook) | ||
|
||
return "Go and take a look at how the file is changed!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
def create_file(path): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import os | ||
import json | ||
|
||
from cat.log import log | ||
from cat.utils import get_static_path, get_plugins_path | ||
from cat.mad_hatter.decorators import plugin, hook | ||
from cat.looking_glass.cheshire_cat import CheshireCat | ||
from cat.looking_glass.prompts import MAIN_PROMPT_PREFIX | ||
|
||
|
||
URLS = [ | ||
"https://cheshire-cat-ai.github.io/docs/technical/plugins/plugins/", | ||
"https://cheshire-cat-ai.github.io/docs/technical/plugins/tools/", | ||
"https://cheshire-cat-ai.github.io/docs/technical/plugins/hooks/", | ||
"https://cheshire-cat-ai.github.io/docs/technical/plugins/settings/", | ||
"https://cheshire-cat-ai.github.io/docs/technical/plugins/dependencies/" | ||
] | ||
TUTORIAL_PATH = os.path.join(get_plugins_path(), "start_from_here") | ||
MAIN_PROMPT_PREFIX = None | ||
|
||
|
||
ccat = CheshireCat() | ||
|
||
|
||
@plugin | ||
def activated(plugin): | ||
declarative_memory = ccat.memory.vectors.declarative | ||
for url in URLS: | ||
metadata = { | ||
"source": url | ||
} | ||
|
||
points = declarative_memory.client.scroll( | ||
collection_name="declarative", | ||
scroll_filter=declarative_memory._qdrant_filter_from_dict(metadata), | ||
) | ||
log.debug(points) | ||
if len(points[0]) != 0: | ||
continue | ||
log.error(f"Ingesting {url}") | ||
ccat.rabbit_hole.ingest_file(stray=ccat, file=url) | ||
|
||
# clonare template? | ||
|
||
if not os.path.isdir(TUTORIAL_PATH): | ||
os.mkdir(TUTORIAL_PATH) | ||
with open(os.path.join(TUTORIAL_PATH, "plugin.py"), "w"): | ||
pass | ||
# creare json | ||
|
||
|
||
@hook | ||
def agent_prompt_prefix(prefix, cat): | ||
global MAIN_PROMPT_PREFIX | ||
MAIN_PROMPT_PREFIX = prefix | ||
|
||
|
||
@hook | ||
def before_cat_reads_message(message, cat): | ||
if not "hdw" in cat.working_memory and os.path.isdir(TUTORIAL_PATH): | ||
cat.working_memory["hdw"] = True | ||
|
||
|
||
@hook | ||
def before_cat_recalls_procedural_memories(settings, cat): | ||
if "hdw" in cat.working_memory and cat.working_memory["hdw"] is False: | ||
settings["threshold"] = 1.1 | ||
|
||
del cat.working_memory["hdw"] | ||
|
||
return settings | ||
|
||
|
||
@hook | ||
def agent_fast_reply(reply, cat): | ||
|
||
if "hdw" in cat.working_memory and cat.working_memory["hdw"] is True: | ||
cat.working_memory["hdw"] = False | ||
|
||
content = cat.llm(f"{MAIN_PROMPT_PREFIX}. Tell the user that the 'Hello Dear World' experience has begun.") | ||
res = cat({ | ||
"text": "Introduce me about the Cheshire Cat's plugin. Explain the following like I'm five:" | ||
"- Plugin" | ||
"- Hooks" | ||
"- Tools" | ||
}) # funge, cercare risp migliore | ||
|
||
return {"output": f"{content}\n{res['content']}\nAre you ready to begin? Yes/No"} | ||
|
||
# __________________ | ||
|
||
if not "hdw" in cat.working_memory or cat.working_memory["hdw"] is False: | ||
return reply | ||
|
||
if cat.working_memory["plugin_begin"] is None: # TODO: here crasha ricomincia da qua | ||
if "yes" in cat.working_memory["user_json_message"]["text"].lower(): | ||
# Start | ||
|
||
# def agent_prompt_prefix(prefix, cat): | ||
# prefix = dimmi la tua personalità | ||
# return | ||
# | ||
message = """Let's try build a plugin together, this is a plugin that changes my personality. | ||
@hook | ||
def agent_prompt_prefix(prefix, cat): | ||
prefix = "Choose my personality" | ||
return prefix | ||
what personality do you want me to have? Write a description | ||
""" | ||
del cat.working_memory["plugin_begin"] | ||
return { | ||
"output": message | ||
} | ||
|
||
# creare forzatamente cartella plugin nuovo? "ti ho creato un plugin, vai a controllare al path...i file servono a..." | ||
# plugin.json con chiavi vuote --> riempibile con tools | ||
# hook esempio con --> completa tu --> il completamento viene scritto dentro al .py | ||
# requirements? | ||
|
||
# info preliminari plugin hook tool (cerca a mano nella memoria e fai un prompt con dentro il contesto pescato?) | ||
# sei pronto per una piccola sfida? si/no | ||
# si -> un piccolo plugin da fare (sfida con few-shots? llm sbizzarrisce) | ||
# no -> vai avanti con altre info preliminari |