-
Notifications
You must be signed in to change notification settings - Fork 61
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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", | ||
"Search the FiftyOne docs", | ||
) | ||
|
||
def resolve_input(self, ctx): | ||
inputs = types.Object() | ||
inputs.str("query", label="Query", required=True) | ||
return types.Property(inputs) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. resolve_input returns a 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. |
||
|
||
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(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
op = SearchDocs() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't update the top-level |
||
foo.register_operator(op) | ||
|
||
def unregister(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
fiftyone: | ||
version: ~0.21.0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This defines the compatible version using semver matchers. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We probably need a way to also define the teams compatible version. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I prefer this version. Typing |
||
operators: | ||
- name: '@voxel51/search-docs' | ||
description: Search https://docs.voxel51.com with an LLM! |
There was a problem hiding this comment.
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.