yoda
2.0.2
Persönlicher Assistent auf der Kommandozeile.
pip install yodapa
yoda --help
yoda configure
Yoda ist erweiterbar konzipiert. Sie können Ihre eigenen Plugins schreiben oder die KI verwenden, um eines für Sie zu generieren.
Der Hilfebefehl listet alle verfügbaren Plugins auf.
❯ yoda --help
Usage: yoda [OPTIONS] COMMAND [ARGS]...
╭─ Options ────────────────────────────────────────────────────────────────╮
│ --install-completion Install completion for the current shell. │
│ --show-completion Show completion for the current shell, to │
│ copy it or customize the installation. │
│ --help Show this message and exit. │
╰──────────────────────────────────────────────────────────────────────────╯
╭─ Commands ───────────────────────────────────────────────────────────────╮
│ ai AI command. Allows you to communicate with your local LLMs │
│ config Config management │
│ dev │
│ init Init yoda configurations │
│ plugin Commands to manage plugins │
│ url │
╰──────────────────────────────────────────────────────────────────────────╯
Sie können die Details für jedes Plugin mit dem Flag --help
finden. Einige Beispiele:
❯ yoda ai --help
Usage: yoda ai [OPTIONS] COMMAND [ARGS]...
AI command. Allows you to communicate with your local LLMs
╭─ Options ────────────────────────────────────────────────────────────────╮
│ --help Show this message and exit. │
╰──────────────────────────────────────────────────────────────────────────╯
╭─ Commands ───────────────────────────────────────────────────────────────╮
│ chat Chat with the AI model based on the provided prompt. │
│ generate-command Generate code for a new plugin command based on the │
│ provided prompt. │
╰──────────────────────────────────────────────────────────────────────────╯
❯ yoda dev --help
Usage: yoda dev [OPTIONS] COMMAND [ARGS]...
╭─ Options ────────────────────────────────────────────────────────────────╮
│ --help Show this message and exit. │
╰──────────────────────────────────────────────────────────────────────────╯
╭─ Commands ───────────────────────────────────────────────────────────────╮
│ checksite Check if a site is up and running │
│ coinflip Flip a coin! │
│ generatepassword Generates a secure password │
│ speedtest Test your internet connection │
│ whois Check whois info for a domain name │
╰──────────────────────────────────────────────────────────────────────────╯
Erstellen Sie einfach eine Klasse mit dem Dekorator @yoda_plugin(name="plugin-name")
und fügen Sie ihr Methoden hinzu. Die nicht privaten Methoden werden automatisch als Unterbefehle zu Yoda hinzugefügt, wobei der Befehl der Name ist, den Sie dem Dekorateur geben.
import typer
app = typer . Typer ( help = """
Hi plugin. Say hello.
Example:
$ yoda hi hello --name MP
$ yoda hi hello
""" )
@ app . command ()
def hello ( name : str = None ):
"""Say hello."""
name = name or "Padawan"
typer . echo ( f"Hello { name } !" )
$ yoda ai generate-command weather " show weather for the provided location "
? Generated code:
import requests
from typing import Optional
app = typer.Typer(help= " " "
Show weather for a given location.
Example:
$ yoda weather London
$ yoda weather -l London
" " " )
@app.command ()
def weather(location: str, units: Optional[str] = None):
" " " Show the current weather for a given location. " " "
# Set up your API key or database connection here
api_key = " YOUR_API_KEY "
db_conn = None # Initialize your DB connection here
# Use the requests library to make an HTTP request to the API
url = f " https://api.openweathermap.org/data/2.5/weather?q={location}&appid={api_key} "
response = requests.get(url)
# If the response is successful, parse the JSON data and return it in a format that typer can display
if response.status_code == 200:
data = response.json ()
temperature = data[ " main " ][ " temp " ]
humidity = data[ " main " ][ " humidity " ]
wind = data[ " wind " ][ " speed " ]
pressure = data[ " main " ][ " pressure " ]
typer.echo(f " Weather for {location}: " )
typer.echo(f " tTemperature: {temperature}°C " )
typer.echo(f " tHumidity: {humidity}% " )
typer.echo(f " tWind speed: {wind} m/s " )
typer.echo(f " tPressure: {pressure} hPa " )
# If the response is not successful, print an error message
else:
typer.echo(f " Error: {response.status_code} " )
.. oder chatte mit Yoda:
❯ yoda ai chat " How are you? "
? AI response:
I am well, young one. The Force is strong with me.
# 1. Install poetry from their website: https://python-poetry.org/docs/#installation
# 2. Install dependencies and this package
poetry install
# 3. Activate the virtual environment
poetry shell
# Now you should be able to communicate with yoda
yoda --help
# Run tests when in the virtual environment
pytest