Skip to content

Commit

Permalink
Merge pull request #299 from manparvesh/v2
Browse files Browse the repository at this point in the history
add AI command
  • Loading branch information
manparvesh authored Oct 10, 2024
2 parents a58580c + 7576330 commit 38c1107
Show file tree
Hide file tree
Showing 6 changed files with 366 additions and 2 deletions.
77 changes: 76 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

Personal Assistant on the command line.

![Yoda](docs/docs/logo.png)
![Yoda](logo.png)

## Installation

Expand All @@ -23,6 +23,16 @@ yoda configure

## Plugins

Yoda is designed to be extensible. You can write your own plugins or use the AI to generate one for you.

### List plugins

The help command will list all the available plugins.

```bash
$ yoda --help
```

### Write your own plugin for Yoda

Simply create a class with the `@yoda_plugin(name="plugin-name")` decorator and add methods to it. The non-private
Expand Down Expand Up @@ -54,6 +64,71 @@ class HiPlugin:
raise NotImplementedError()
```

### Use AI to generate your own plugin

```bash
$ yoda ai generate-command todo "todo list that keeps track of your todos"

🤖 Generated code:

import typer

from yodapa.plugin_manager.decorator import yoda_plugin


@yoda_plugin(name="todo")
class TodoPlugin:
"""
Todo plugin. Keeps track of your todos.
Example:
$ yoda todo list --all
$ yoda todo add "Finish assignment"
$ yoda todo done 1
$ yoda todo delete 2
"""

def list(self, all: bool = False):
"""List all todos."""
if all:
typer.echo("All todos:")
for todo in self.todos:
typer.echo(f"- {todo}")
else:
typer.echo("Active todos:")
for todo in self.active_todos:
typer.echo(f"- {todo}")

def add(self, name: str):
"""Add a new todo."""
if name == "":
raise ValueError("Todo name cannot be empty")
self.todos.append(name)
typer.echo(f"Added todo '{name}'")

def done(self, id: int):
"""Mark a todo as done."""
if id < 0 or id >= len(self.todos):
raise ValueError("Todo ID out of range")
self.active_todos.remove(self.todos[id])
typer.echo(f"Marked todo {id} as done")

def delete(self, id: int):
"""Delete a todo."""
if id < 0 or id >= len(self.todos):
raise ValueError("Todo ID out of range")
self.todos.remove(self.todos[id])
typer.echo(f"Deleted todo {id}")

def __init__(self):
self.todos = []
self.active_todos = []

if __name__ == "__main__":
typer.run(TodoPlugin())

```
## Development setup
```bash
Expand Down
75 changes: 75 additions & 0 deletions docs/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ yoda configure

## Plugins

Yoda is designed to be extensible. You can write your own plugins or use the AI to generate one for you.

### List plugins

The help command will list all the available plugins.

```bash
$ yoda --help
```

### Write your own plugin for Yoda

Simply create a class with the `@yoda_plugin(name="plugin-name")` decorator and add methods to it. The non-private
Expand Down Expand Up @@ -54,6 +64,71 @@ class HiPlugin:
raise NotImplementedError()
```

### Use AI to generate your own plugin

```bash
$ yoda ai generate-command todo "todo list that keeps track of your todos"

🤖 Generated code:

import typer

from yodapa.plugin_manager.decorator import yoda_plugin


@yoda_plugin(name="todo")
class TodoPlugin:
"""
Todo plugin. Keeps track of your todos.
Example:
$ yoda todo list --all
$ yoda todo add "Finish assignment"
$ yoda todo done 1
$ yoda todo delete 2
"""

def list(self, all: bool = False):
"""List all todos."""
if all:
typer.echo("All todos:")
for todo in self.todos:
typer.echo(f"- {todo}")
else:
typer.echo("Active todos:")
for todo in self.active_todos:
typer.echo(f"- {todo}")

def add(self, name: str):
"""Add a new todo."""
if name == "":
raise ValueError("Todo name cannot be empty")
self.todos.append(name)
typer.echo(f"Added todo '{name}'")

def done(self, id: int):
"""Mark a todo as done."""
if id < 0 or id >= len(self.todos):
raise ValueError("Todo ID out of range")
self.active_todos.remove(self.todos[id])
typer.echo(f"Marked todo {id} as done")

def delete(self, id: int):
"""Delete a todo."""
if id < 0 or id >= len(self.todos):
raise ValueError("Todo ID out of range")
self.todos.remove(self.todos[id])
typer.echo(f"Deleted todo {id}")

def __init__(self):
self.todos = []
self.active_todos = []

if __name__ == "__main__":
typer.run(TodoPlugin())

```
## Development setup
```bash
Expand Down
Binary file added logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
106 changes: 105 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pytest = "^8.3.3"
pyyaml = "^6.0.2"
mkdocs = "^1.6.1"
mkdocs-material = "^9.5.39"
ollama = "^0.3.3"

[tool.poetry.group.dev.dependencies]
pytest = "^8.3.3"
Expand Down
Loading

0 comments on commit 38c1107

Please sign in to comment.