prompts.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import json
  2. import asyncclick as click
  3. from asyncclick import pass_context
  4. from cli.utils.timer import timer
  5. from r2r import R2RAsyncClient
  6. @click.group()
  7. def prompts():
  8. """Prompts commands."""
  9. pass
  10. @prompts.command()
  11. @pass_context
  12. async def list(ctx):
  13. """Get an overview of prompts."""
  14. client: R2RAsyncClient = ctx.obj
  15. with timer():
  16. response = await client.prompts.list()
  17. for prompt in response["results"]:
  18. click.echo(json.dumps(prompt, indent=2))
  19. @prompts.command()
  20. @click.argument("name", type=str)
  21. @click.option("--inputs", default=None, type=str)
  22. @click.option("--prompt-override", default=None, type=str)
  23. @pass_context
  24. async def retrieve(ctx, name, inputs, prompt_override):
  25. """Retrieve an prompts by name."""
  26. client: R2RAsyncClient = ctx.obj
  27. with timer():
  28. response = await client.prompts.retrieve(
  29. name=name,
  30. inputs=inputs,
  31. prompt_override=prompt_override,
  32. )
  33. click.echo(json.dumps(response, indent=2))
  34. @prompts.command()
  35. @click.argument("name", required=True, type=str)
  36. @pass_context
  37. async def delete(ctx, name):
  38. """Delete an index by name."""
  39. client: R2RAsyncClient = ctx.obj
  40. with timer():
  41. response = await client.prompts.delete(
  42. name=name,
  43. )
  44. click.echo(json.dumps(response, indent=2))