Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow listing projects for an organization #236

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions nomic/atlas.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,35 @@
from .settings import *
from .utils import b64int, get_random_name, arrow_iterator

from .project import AtlasClass
import requests

def list_projects(organization_id=None):
"""
Lists all projects in an Atlas organization.

If called without an organization id, it will list all projects in the
current user's main organization.
"""
c = AtlasClass()
if organization_id is None:
organization = c._get_current_users_main_organization()
if organization is None:
raise ValueError(
"No organization id provided and no main organization found."
)
organization_id = organization['organization_id']
response = requests.get(
c.atlas_api_path + f"/v1/organization/{organization_id}",
headers=c.header
)
proj_info = response.json()['projects']
return [
{'name': p['project_name'],
'id': p['id'],
'created_timestamp': p['created_timestamp']}
for p in proj_info
]

def map_embeddings(
embeddings: np.array,
Expand Down
11 changes: 11 additions & 0 deletions nomic/tests/test_atlas_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,3 +468,14 @@ def test_map_text_iterator():
map = project.get_map(name='UNITTEST_pandas_text')
assert project.total_datums == 50
project.delete()


def test_list_projects():
# Create a project if none exists
proj = AtlasProject(name='existence', modality='text', unique_id_field='id', reset_project_if_exists=False)
projects = atlas.list_projects()
bmschmidt marked this conversation as resolved.
Show resolved Hide resolved
assert len(projects) > 0
assert isinstance(projects[0], dict)
assert 'name' in projects[0]
assert 'existence' in set([p['name'] for p in projects])
proj.delete()
1 change: 0 additions & 1 deletion nomic/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import sys
import pyarrow as pa
from uuid import UUID

from wonderwords import RandomWord


Expand Down