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

Replace roles.yaml with roles/<name>.md #804

Closed
sigoden opened this issue Aug 27, 2024 · 5 comments · Fixed by #810
Closed

Replace roles.yaml with roles/<name>.md #804

sigoden opened this issue Aug 27, 2024 · 5 comments · Fixed by #810
Labels
enhancement New feature or request

Comments

@sigoden
Copy link
Owner

sigoden commented Aug 27, 2024

Instead of using a central roles.yaml file to store all the roles, we can use a dedicated roles folder. Each file within this folder would represent a single role, with the filename corresponding to the role's name.

Benefits

  • Create/Edit a single role within the REPL
  • Load on demand, resulting in less memory usage

REPL

  • .role <name>: Create a new role if one doesn't exist
  • .edit role: Edit the current role
  • .save role: Save the current role to file

Options

---
model: openai:gpt-4
temperature: 0
top_p: 0
...
---

Your are a ...
@sigoden sigoden added the enhancement New feature or request label Aug 27, 2024
@sigoden
Copy link
Owner Author

sigoden commented Aug 30, 2024

We provide a Python script to convert roles.yaml to roles/<name>.md

import yaml
import os

def convert(yaml_file, saved_dir):
    with open(yaml_file, 'r', encoding='utf-8') as f:
        yaml_content = f.read()

    data = yaml.safe_load(yaml_content)
    
    os.makedirs(saved_dir, exist_ok=True)

    for item in data:
        if 'name' not in item or 'prompt' not in item:
            continue  # Skip items that do not have the necessary fields

        name = item.pop('name').replace(':', '#')
        prompt = item.pop('prompt')
        
        markdown_file = os.path.join(saved_dir, f"{name}.md")

        metadata = ''
        if item:
            metadata = '---\n' + yaml.dump(item) + '---\n\n'
        
        with open(markdown_file, 'w', encoding='utf-8') as f:
            f.write(metadata + prompt)

convert("roles.yaml", "roles")
cd <aichat-config-dir>
python convert.py

@jiahut
Copy link

jiahut commented Sep 2, 2024

Confirm if there are any parameters that don't support __ARG1__ ?
I used the script locally and the original role included __ARG1__ failed to convert the role

@fmaida
Copy link

fmaida commented Sep 5, 2024

We provide a Python script to convert roles.yaml to roles/<name>.md

[ ... ]

Thank you for the script. However, please remind the viewers that this script requires the PyYAML library to be installed in order to work ( https://pypi.org/project/PyYAML/ ).

Since PyYaml is not included in the Python standard library by default, if you want to run this script from the command line, you will often need to enter the following commands:

cd <aichat-config-dir>
python -m venv .venv
source .venv/bin/activate  # if you use bash or zsh, if you are using Fish use "source .venv/bin/activate.fish"
pip install pyyaml
python convert.py
deactivate
rm -rf .venv

@xeruf
Copy link

xeruf commented Oct 10, 2024

Would be nice to have a link to this included when not finding a role for the next few versions, took me a while to get here after my existing roles unexpectedly stopped working

@xeruf
Copy link

xeruf commented Oct 10, 2024

aichat could also offer to automatically run the migration

small issue, this role is not correctly converted:

- name: convert:json:yaml
  prompt: convert __ARG1__ below to __ARG2__

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

Successfully merging a pull request may close this issue.

4 participants