Skip to content

Commit

Permalink
feat: add project creation (#49)
Browse files Browse the repository at this point in the history
Signed-off-by: Panos Vagenas <35837085+vagenas@users.noreply.github.com>
  • Loading branch information
vagenas authored Nov 23, 2022
1 parent a955d9b commit 4a5a52f
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 18 deletions.
12 changes: 12 additions & 0 deletions deepsearch/cps/cli/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,17 @@ def list(
cli_output(results, output, headers="keys")


@app.command(name="create", help="Create a project")
def create(
proj_name: str,
output: OutputEnum = OutputOption,
):
api = CpsApi.default_from_env()
proj = api.projects.create(name=proj_name)
results = [{"key": proj.key, "name": proj.name}]

cli_output(results, output, headers="keys")


if __name__ == "__main__":
app()
5 changes: 5 additions & 0 deletions deepsearch/cps/client/components/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ def get(self, key: str) -> Optional[Project]:
projects = self.list()
return next((proj for proj in projects if proj.key == key), None)

def create(self, name: str) -> Project:
create_data = {"name": name}
proj: deepsearch.cps.apis.user.Project = self.sw_api.create(data=create_data)
return self._load(proj)

def _load(self, project: deepsearch.cps.apis.user.Project) -> Project:
return Project(
# api=self.api,
Expand Down
14 changes: 7 additions & 7 deletions docs/guide/data_indices.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

# Data indices

A data index stores a collection of documents in a project. This page shows how to create and delete a data index, and to list all data indices in a project.
A data index stores a collection of documents in a project. This page shows how to create and delete a data index, and to list all data indices in a project.

Since a data index "lives" inside a project, we need to specify which project we are referring to. This is accomplished by a project key `PROJ_KEY`. We can obtain the project keys for our projects by [listing them](../guide/projects.md).


## Create data index in a project
## Creating a data index in a project

Suppose you want to create an index called `NAME`. Optionally, a description,`DESC`, for the data index can be provided.
Suppose you want to create an index called `NAME`. Optionally, a description,`DESC`, for the data index can be provided.

=== "CLI"
<div class="termy">
Expand Down Expand Up @@ -64,7 +64,7 @@ In addition, it is possible to specify non-default `type` of data index. For mor
```
---

## Deleting data index in a project
## Deleting a data index from a project

To delete a data index, you need to specify an index via its `INDEX_KEY`. [Listing data indices](#listing-data-indices-in-a-project) will show the `INDEX_KEY` for all the indices in a project.

Expand All @@ -88,7 +88,7 @@ To delete a data index, you need to specify an index via its `INDEX_KEY`. [Listi

---

## Adding documents in a project
## Adding documents to a project

Documents can be converted and added, directly, to a data index in a project. Briefly, documents can be on a local machine or on the remote files. Local documents can be in PDF format, ZIP archives, or directory containing both (`PATH_DOCS`). The web address of a remote document is input directly or multiple web addresses can be stored in a text file (`PATH_URL`). The specification of documents is same as in [Document Conversion](../guide/convert-doc.md).

Expand All @@ -99,7 +99,7 @@ Documents can be converted and added, directly, to a data index in a project. Br
```console
// for local documents
$ deepsearch cps data-indices upload -p PROJ_KEY -x INDEX_KEY -i PATH_DOCS

// for online documents
$ deepsearch cps data-indices upload -p PROJ_KEY -x INDEX_KEY -u PATH_URL
```
Expand All @@ -125,4 +125,4 @@ Documents can be converted and added, directly, to a data index in a project. Br
ds.data_indices_utilities.upload_files(coords=coords, url=input_urls)
```

---
---
49 changes: 39 additions & 10 deletions docs/guide/projects.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,54 @@
!!! tip
The features described on this page are not available in the public service. [Contact us](https://ds4sd.github.io/) to know more.

# Projects

Deep Search projects allow users to collaborate.
All resources such as data, models and knowledge graphs belog to a project.
All resources such as data, models and knowledge graphs belong to a project.

Collaborators may be added to a project as `owners`, `editors` or `viewers`. Below is a description of the roles.
A collaborator may be added to a project as `owner`, `editor`, or `viewer`. Below is a description of these roles.

| Role | Description |
| ---------- | ------------------------------------ |
| `viewer` | Inspect documents, view all project resources, query project knowledge graphs. |
| `editor` | All permissions of `viewer` + creating and editing new project resources. |
| `owner` | All permissions of `editor` + possibility to manage collaborators and delete the project. |

## Project management

!!! info
Make sure to [configure your login](../getting_started/index.md#authentication) before
using the project management features listed below.

## Listing projects
### Creating a project

!!! info
Please [configure your login](../getting_started/index.md#authentication) before trying these examples.
=== "CLI"

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

```console
$ deepsearch cps projects create my-project

key name
---------------------------------------- ----------
d1d526e14cdac562b5174c2df9dd1b04c29a8c33 my-project
```

</div>

=== "Python"

After you have generated the `api` object (from [login configuration](../getting_started/#authentication)), creating a project is very easy.

```python
proj = api.projects.create(name="my-project")

print(proj)
# > Project(key='7be8d8e763b55996710007cf97f31244e8ea237c', name='my-project')
```

### Listing projects

=== "CLI"

Expand All @@ -31,17 +60,17 @@ Collaborators may be added to a project as `owners`, `editors` or `viewers`. Bel

key name
---------------------------------------- ---------------------
c5e1f35a57e1a538c111c59752f06df07aab6c91 dev
20ae7fb2567d4b777712a6bb50f133c118497d0d MyProjects
1146f5cf2c5ebb4774df38888d5fa608673fca33 IT Services
d1d526e14cdac562b5174c2df9dd1b04c29a8c33 my-project
20ae7fb2567d4b777712a6bb50f133c118497d0d test-project
1146f5cf2c5ebb4774df38888d5fa608673fca33 it-services
744978acd58c0cd16893ec4e0ccdd69fd8dd5566 ...
```

</div>

=== "Python"

After you have generated the api object (from [login configuration](../getting_started/#authentication)), listing projects is very easy.
After you have generated the `api` object (from [login configuration](../getting_started/#authentication)), listing projects is very easy.

```python
projects = api.projects.list() # returns list of projects
Expand Down
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ nav:
- Getting started: getting_started/index.md
- User guide:
- "guide/index.md"
- Document Conversion: guide/convert_doc.md
- Document conversion: guide/convert_doc.md
- Projects: guide/projects.md
- Data: guide/data_indices.md
- Knowledge graphs: guide/kgs.md
Expand Down

0 comments on commit 4a5a52f

Please sign in to comment.