Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api-client-py working - but not working inside a cat plugin #1

Closed
ElioErrico opened this issue Sep 23, 2023 · 1 comment
Closed

api-client-py working - but not working inside a cat plugin #1

ElioErrico opened this issue Sep 23, 2023 · 1 comment

Comments

@ElioErrico
Copy link

Hello Nicola.
Thank you for the answer in the other issue #Furrmidable-Crew/schrodinger_cat#1 (comment).
I tried to upload a .txt from my computer to the cat using https://github.com/cheshire-cat-ai/api-client-py.git and everything worked without any issue.

My goal was to load a document (stored in the plugin folder) inside the declarative memory of the cat just asking it to him.
So I tried to:

  1. copy the api-client-py inside the plug-in folder of the cat (with the requirements.txt file) with no modifications.
  2. run the plug-in inside the cat

the cat gave me this output error in loading the plugin :

cheshire_cat_core | [2023-09-23 09:43:29.325] WARNING cat.mad_hatter.MadHatter.toggle_plugin::228 => 'Toggle plugin 08_upload file from plug in v3: Activate' cheshire_cat_core | [2023-09-23 09:43:32.106] ERROR cat.mad_hatter.Plugin._load_hooks_and_tools::183 => ('Error in cat.plugins.08_upload file from plug in v3.scripts.release_notes: ' cheshire_cat_core | [2023-09-23 09:43:32.106] ERROR cat.mad_hatter.Plugin._load_hooks_and_tools::183 => "'TAG'")

The question are:

  1. is it possible to do what I'm trying to do?
  2. It is a error that can be solved easily?
  3. is there a more intelligent way to do it with some cat features that I ignore?

This one below is the main code of the plugin but I think it is not required.
tool_caricamento_file.txt

@nicola-corbellini
Copy link
Member

nicola-corbellini commented Sep 23, 2023

Hello Elio, nice to see you experimenting with the Python client.

If you want to upload a document just asking the Cat, you can avoid using the Python api client.
The library is meant for interacting with the Cat from "outside", if you want to develop a custom client.

Rather, your goal can be achieved with the following tool

from cat.mad_hatter.decorators import tool

@tool 
def upload_document(tool_input, cat):
"""Useful to upload a document in the memory. Input is the name to the document."""

    # Full document path
    doc_path = f"{cat.get_static_path()}/{tool_input}"

    # Upload the document to declarative memory
    cat.rabbit_hole.ingest_file(doc_path)

    return "Done"

where cat.get_static_path() is the folder you see under core/cat/static/ and is a static server where you should place the document to be loaded; while cat.rabbit_hole.ingest_file is the same method you used from the Python client.

You can trigger the tool with something like "Please, upload the file foo.txt". The Cat will format the path to be cat/static/foo.txt,

This is just a simple example you can customize to your needs. Please, let me know if this solves your issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants