Skip to content

Commit

Permalink
feat: add KG downloading (#71)
Browse files Browse the repository at this point in the history
Signed-off-by: Yusik Kim <107410898+kmyusk@users.noreply.github.com>
  • Loading branch information
kmyusk authored Mar 14, 2023
1 parent 3e91f63 commit 77cccc0
Show file tree
Hide file tree
Showing 6 changed files with 263 additions and 1 deletion.
123 changes: 123 additions & 0 deletions deepsearch/cps/apis/public/api/knowledge_graphs_api.py

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

19 changes: 19 additions & 0 deletions deepsearch/cps/cli/kgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,24 @@ def save_snapshot_of_data_flow(
typer.echo(f"A snapshot is being taken, see task {task.task_id!r}")


@app.command(name="download", help="Download KG")
def download_knowledge_graph(
proj_key: str = PROJ_KEY,
kg_key: str = KG_KEY,
output: OutputEnum = OutputOption,
):
api = CpsApi.default_from_env()
kg = api.knowledge_graphs.get(project=proj_key, key=kg_key)
if kg is None:
raise typer.BadParameter(
f"Unknown Knowledge Graph {kg_key!r} in project {proj_key!r}"
)
url = kg.download()

results = [{"url": url}]
# TODO: augment with topology details
cli_output(results, output, headers="keys")


if __name__ == "__main__":
app()
9 changes: 9 additions & 0 deletions deepsearch/cps/client/components/knowledge_graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,12 @@ def save_snapshot_of_data_flow(
)

return task

def download(self):
task: ProjectTask = (
self.api.knowledge_graphs.sw_api.download_project_knowledge_graph(
self.project, self.key
)
)

return self.api.tasks.wait_for(self.project, task.task_id)
82 changes: 82 additions & 0 deletions docs/apis/public/KnowledgeGraphsApi.md

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

29 changes: 29 additions & 0 deletions docs/guide/kgs.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,32 @@ result = api.queries.run(query)
```

More example queries are available in the [examples gallery](../gallery/index.md).

### Download a KG

=== "CLI"

Using the [`deepsearch cps`](../cli-reference.md#cps) component:
<div class="termy">

```console
$ deepsearch cps kgs download -p 'abc123' -k 'zxc987'

url
--------------------------------
https://host.domain/download-url
```

</div>

=== "Python"

After you have generated the `api` object (from [login configuration](../getting_started/#authentication))

```python
proj_key = "abc123" # get your proj_key from the UI details
kg_key = "xyz987" # get kg_key (also called bag_key) from the UI details
kg = api.knowledge_graphs.get(proj_key, kg_key)

download_url = kg.download()
```
2 changes: 1 addition & 1 deletion tools/swagger-client-generator/swagger-cps.json

Large diffs are not rendered by default.

0 comments on commit 77cccc0

Please sign in to comment.