Skip to content

Commit

Permalink
started flow
Browse files Browse the repository at this point in the history
  • Loading branch information
nicola-corbellini committed Dec 8, 2023
1 parent a1c7de9 commit 4963ed6
Show file tree
Hide file tree
Showing 8 changed files with 183 additions and 132 deletions.
18 changes: 1 addition & 17 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,10 @@ permissions:
env:
PLUGIN_JSON: "0.0.1"
TAG_EXISTS: false
PLUGIN_NAME: "my_plugin"
PLUGIN_NAME: "hello_dear_world"

jobs:
# This will be deleted by setup.py
check:
runs-on: ubuntu-latest
outputs:
plugin_name: ${{ steps.init.outputs.plugin_name }}
steps:
- name: Get plugin name
id: init
run: |
echo "plugin_name=${{ env.PLUGIN_NAME }}" >> $GITHUB_OUTPUT
# This is the end of the removed section
release:
# This will be deleted by setup.py
needs: check
if: startsWith(needs.check.outputs.plugin_name, 'MY_PLUGIN') == false
# This is the end of the removed section
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# My plugin
# Hello Dear World

[![awesome plugin](https://custom-icon-badges.demolab.com/static/v1?label=&message=awesome+plugin&color=383938&style=for-the-badge&logo=cheshire_cat_ai)](https://)
[![Awesome plugin](https://custom-icon-badges.demolab.com/static/v1?label=&message=Awesome+plugin&color=000000&style=for-the-badge&logo=cheshire_cat_ai)](https://)
Expand Down
31 changes: 0 additions & 31 deletions my_plugin.py

This file was deleted.

8 changes: 4 additions & 4 deletions plugin.json
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"
}
79 changes: 0 additions & 79 deletions setup.py

This file was deleted.

51 changes: 51 additions & 0 deletions tool.py
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!"
1 change: 1 addition & 0 deletions utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
def create_file(path):
125 changes: 125 additions & 0 deletions wizard.py
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

0 comments on commit 4963ed6

Please sign in to comment.