Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
add gen-template command
Browse files Browse the repository at this point in the history
  • Loading branch information
acatav committed Feb 8, 2024
1 parent 65b85ee commit 7d3d467
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,16 @@ INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
### Stopping the server
To stop the server, simply press `CTRL+C` in the terminal where you started it.

### Dumping a config Yaml template file

The first step in writing your own configuration file is to start from a valid template. You can dump a configuration file template using the following command:

```bash
canopy gen-config /path/to/my-config.yaml --template cohere.yaml
```

You can find the available templates under [src/canopy/config](src/canopy/config/).


## Evaluation chat tool

Expand Down
33 changes: 32 additions & 1 deletion src/canopy_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Dict, Any, Optional, List, Iterable

import click
import importlib.resources as pkg_resources
from prompt_toolkit import prompt
import time

Expand Down Expand Up @@ -178,7 +179,7 @@ def __init__(self, name=None, commands=None, **attrs):
"health": 4,
"stop": 5,
"api-docs": 6,

"gen-config": 7,
}

def list_commands(self, ctx):
Expand Down Expand Up @@ -210,6 +211,36 @@ def health(url):
return


@cli.command(help="Writes a config template YAML file to the specified path.")
@click.argument("path", type=click.Path(), required=True)
@click.option("--template", default="default", help="The name of the template to use.")
def gen_config(path, template):

if not template.endswith('.yaml'):
template += '.yaml'

try:
with pkg_resources.open_text('canopy.config', template) as f:
config = yaml.safe_load(f)
except FileNotFoundError:
files = pkg_resources.files('canopy.config')
template_names = [f.name for f in files.iterdir()]
click.echo(f"Template '{template}' not found."
f"Available templates: {template_names}",
err=True)
return
except Exception as e:
click.echo(f"Failed to load template '{template}'. Reason: {e}"
f"Make sure you pip installed `canopy-sdk`.",
err=True)
return

with open(path, 'w') as dst_file:
yaml.dump(config, dst_file)

click.echo(f"Config template '{template}' written to {path}")


@cli.command(
help=(
"""
Expand Down

0 comments on commit 7d3d467

Please sign in to comment.