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

add operator impl #7

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
44 changes: 44 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import fiftyone.operators as foo
import fiftyone.operators.types as types

from fiftyone.docs_search.query_index import query_index


class SearchDocs(foo.DynamicOperator):
def __init__(self):
super().__init__(
"@voxel51/search-docs",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for anyone curious. This name match match the operator name defined in yaml. As far as the teams runtime is concerned, it will only refer to what is listed in the fiftyone.yml, not that it reads from this file.

"Search the FiftyOne docs",
)

def resolve_input(self, ctx):
inputs = types.Object()
inputs.str("query", label="Query", required=True)
return types.Property(inputs)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolve_input returns a Property to allow for customizing the entire form view the property.view. This is because the entire form is actually defined by a Property of the operators definition (which is a types.Object).

In the operator type system, base types like object do not have ui metadata associated with them, since they should be re-usable and generic (in both senses of the word eg. List(String) - List is a "Generic" type aka template type.)


def execute(self, ctx):
results = query_index(
ctx.params.get("query")
)
links = []
for url, text, score in results:
links.append({
"href": url,
"label": text
})
return {"links": links}

def resolve_output(self, ctx):
outputs = types.Object()
outputs.define_property("links", types.List(types.Link()))
return types.Property(outputs)


op = None

def register():
Copy link
Contributor

@brimoor brimoor Apr 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could auto-register as well. One way to do that would be to import this module and then automatically register all classes in the namespace that derive from foo.Operator. Or, if we wanted to be explicit, we could include the names of the operator(s?) in the yaml file that should be registered.

op = SearchDocs()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't update the top-level op object. You'd have to include global op in order to do that.
https://en.wikipedia.org/wiki/Variable_shadowing

foo.register_operator(op)

def unregister():
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may be able to omit this and auto-unregister anything defined in the yaml.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should find a way to auto-unregister w/o needing this function

foo.unregister_operator(op)
6 changes: 6 additions & 0 deletions fiftyone.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fiftyone:
version: ~0.21.0
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This defines the compatible version using semver matchers.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably need a way to also define the teams compatible version.

Copy link
Contributor

@brimoor brimoor Apr 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every version of the Teams SDK has a corresponding OSS version (a range of compatible OSS versions, in fact), so we could require all users to "speak" OSS versions for now

name: '@voxel51/fiftyone-docs-search'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should encourage this pattern, which is to match the github repo name to the plugin name. In theory we could also split this and then every "name" in this file is technically prefixed with the org name:

org: voxel51
name: fiftyone-docs-search
operators:
  - name: search-docs

Copy link

@kaixi-wang kaixi-wang Apr 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should encourage this pattern, which is to match the github repo name to the plugin name. In theory we could also split this and then every "name" in this file is technically prefixed with the org name:

org: voxel51
name: fiftyone-docs-search
operators:
  - name: search-docs

I prefer this version. Typing @voxel51/fiftyone-docs-search for plugin name in zoo methods is an unnecessary pain

operators:
- name: '@voxel51/search-docs'
description: Search https://docs.voxel51.com with an LLM!