-
Notifications
You must be signed in to change notification settings - Fork 284
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
1,429 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +0,0 @@ | ||
from .command_group import cli as command_group_cli | ||
from .commands import auth, database, ingestion, management, retrieval, server | ||
from .main import main | ||
|
||
__all__ = [ | ||
# From cli.py | ||
"main", | ||
# From Command Collection | ||
"command_group_cli", | ||
# From Commands | ||
"auth", | ||
"ingestion", | ||
"management", | ||
"kg", | ||
"database", | ||
"retrieval", | ||
"server", | ||
] | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
import json | ||
|
||
import asyncclick as click | ||
from asyncclick import pass_context | ||
|
||
from r2r import R2RAsyncClient | ||
from cli.utils.timer import timer | ||
|
||
|
||
@click.group() | ||
def collections(): | ||
"""Collections commands.""" | ||
pass | ||
|
||
|
||
@collections.command() | ||
@click.argument("name", required=True, type=str) | ||
@click.option("--description", type=str) | ||
@pass_context | ||
async def create(ctx, name, description): | ||
"""Create a collection.""" | ||
client: R2RAsyncClient = ctx.obj | ||
|
||
with timer(): | ||
response = await client.collections.create( | ||
name=name, | ||
description=description, | ||
) | ||
|
||
click.echo(json.dumps(response, indent=2)) | ||
|
||
|
||
@collections.command() | ||
@click.option("--ids", multiple=True, help="Collection IDs to fetch") | ||
@click.option( | ||
"--offset", | ||
default=0, | ||
help="The offset to start from. Defaults to 0.", | ||
) | ||
@click.option( | ||
"--limit", | ||
default=100, | ||
help="The maximum number of nodes to return. Defaults to 100.", | ||
) | ||
@pass_context | ||
async def list(ctx, ids, offset, limit): | ||
"""Get an overview of collections.""" | ||
client: R2RAsyncClient = ctx.obj | ||
ids = list(ids) if ids else None | ||
|
||
with timer(): | ||
response = await client.collections.list( | ||
ids=ids, | ||
offset=offset, | ||
limit=limit, | ||
) | ||
|
||
for user in response["results"]: | ||
click.echo(json.dumps(user, indent=2)) | ||
|
||
|
||
@collections.command() | ||
@click.argument("id", required=True, type=str) | ||
@pass_context | ||
async def retrieve(ctx, id): | ||
"""Retrieve a collection by ID.""" | ||
client: R2RAsyncClient = ctx.obj | ||
|
||
with timer(): | ||
response = await client.collections.retrieve(id=id) | ||
|
||
click.echo(json.dumps(response, indent=2)) | ||
|
||
|
||
@collections.command() | ||
@click.argument("id", required=True, type=str) | ||
@pass_context | ||
async def delete(ctx, id): | ||
"""Delete a collection by ID.""" | ||
client: R2RAsyncClient = ctx.obj | ||
|
||
with timer(): | ||
response = await client.collections.delete(id=id) | ||
|
||
click.echo(json.dumps(response, indent=2)) | ||
|
||
|
||
@collections.command() | ||
@click.argument("id", required=True, type=str) | ||
@click.option( | ||
"--offset", | ||
default=0, | ||
help="The offset to start from. Defaults to 0.", | ||
) | ||
@click.option( | ||
"--limit", | ||
default=100, | ||
help="The maximum number of nodes to return. Defaults to 100.", | ||
) | ||
@pass_context | ||
async def list_documents(ctx, id, offset, limit): | ||
"""Get an overview of collections.""" | ||
client: R2RAsyncClient = ctx.obj | ||
|
||
with timer(): | ||
response = await client.collections.list_documents( | ||
id=id, | ||
offset=offset, | ||
limit=limit, | ||
) | ||
|
||
for user in response["results"]: | ||
click.echo(json.dumps(user, indent=2)) | ||
|
||
|
||
@collections.command() | ||
@click.argument("id", required=True, type=str) | ||
@click.option( | ||
"--offset", | ||
default=0, | ||
help="The offset to start from. Defaults to 0.", | ||
) | ||
@click.option( | ||
"--limit", | ||
default=100, | ||
help="The maximum number of nodes to return. Defaults to 100.", | ||
) | ||
@pass_context | ||
async def list_users(ctx, id, offset, limit): | ||
"""Get an overview of collections.""" | ||
client: R2RAsyncClient = ctx.obj | ||
|
||
with timer(): | ||
response = await client.collections.list_users( | ||
id=id, | ||
offset=offset, | ||
limit=limit, | ||
) | ||
|
||
for user in response["results"]: | ||
click.echo(json.dumps(user, indent=2)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import json | ||
|
||
import asyncclick as click | ||
from asyncclick import pass_context | ||
|
||
from r2r import R2RAsyncClient | ||
from cli.utils.timer import timer | ||
|
||
|
||
@click.group() | ||
def conversations(): | ||
"""Conversations commands.""" | ||
pass | ||
|
||
|
||
@conversations.command() | ||
@pass_context | ||
async def create(ctx): | ||
"""Create a conversation.""" | ||
client: R2RAsyncClient = ctx.obj | ||
|
||
with timer(): | ||
response = await client.conversations.create() | ||
|
||
click.echo(json.dumps(response, indent=2)) | ||
|
||
|
||
@conversations.command() | ||
@click.option("--ids", multiple=True, help="Conversation IDs to fetch") | ||
@click.option( | ||
"--offset", | ||
default=0, | ||
help="The offset to start from. Defaults to 0.", | ||
) | ||
@click.option( | ||
"--limit", | ||
default=100, | ||
help="The maximum number of nodes to return. Defaults to 100.", | ||
) | ||
@pass_context | ||
async def list(ctx, ids, offset, limit): | ||
"""Get an overview of conversations.""" | ||
client: R2RAsyncClient = ctx.obj | ||
ids = list(ids) if ids else None | ||
|
||
with timer(): | ||
response = await client.conversations.list( | ||
ids=ids, | ||
offset=offset, | ||
limit=limit, | ||
) | ||
|
||
for user in response["results"]: | ||
click.echo(json.dumps(user, indent=2)) | ||
|
||
|
||
@conversations.command() | ||
@click.argument("id", required=True, type=str) | ||
@pass_context | ||
async def retrieve(ctx, id): | ||
"""Retrieve a collection by ID.""" | ||
client: R2RAsyncClient = ctx.obj | ||
|
||
with timer(): | ||
response = await client.conversations.retrieve(id=id) | ||
|
||
click.echo(json.dumps(response, indent=2)) | ||
|
||
|
||
@conversations.command() | ||
@click.argument("id", required=True, type=str) | ||
@pass_context | ||
async def delete(ctx, id): | ||
"""Delete a collection by ID.""" | ||
client: R2RAsyncClient = ctx.obj | ||
|
||
with timer(): | ||
response = await client.conversations.delete(id=id) | ||
|
||
click.echo(json.dumps(response, indent=2)) | ||
|
||
|
||
@conversations.command() | ||
@click.argument("id", required=True, type=str) | ||
@pass_context | ||
async def list_branches(ctx, id): | ||
"""List all branches in a conversation.""" | ||
client: R2RAsyncClient = ctx.obj | ||
|
||
with timer(): | ||
response = await client.conversations.list_branches( | ||
id=id, | ||
) | ||
|
||
for user in response["results"]: | ||
click.echo(json.dumps(user, indent=2)) | ||
|
||
|
||
@conversations.command() | ||
@click.argument("id", required=True, type=str) | ||
@click.option( | ||
"--offset", | ||
default=0, | ||
help="The offset to start from. Defaults to 0.", | ||
) | ||
@click.option( | ||
"--limit", | ||
default=100, | ||
help="The maximum number of nodes to return. Defaults to 100.", | ||
) | ||
@pass_context | ||
async def list_users(ctx, id, offset, limit): | ||
"""Get an overview of collections.""" | ||
client: R2RAsyncClient = ctx.obj | ||
|
||
with timer(): | ||
response = await client.collections.list_users( | ||
id=id, | ||
offset=offset, | ||
limit=limit, | ||
) | ||
|
||
for user in response["results"]: | ||
click.echo(json.dumps(user, indent=2)) |
Oops, something went wrong.