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

chore: use primitives instead of typing imports and fixes completion … #149

Merged
merged 1 commit into from
Oct 15, 2024

Conversation

codefromthecrypt
Copy link
Collaborator

…signature

This migrates from typing imports to primitives per the following feedback from @lamchau:

:nit: i think our patterns here don't realize as of python 3.9+ we generally don't need Dict, List, and Tuple anymore we can use the primitives (dict, list, and tuple respectively)

This also fixes inconsistency in our provider completion signature with regards to:

  • tools: more precisely allow any amount of tools as often there are none
-    tools: Tuple[Tool] = field(factory=tuple, converter=tuple)
+    tools: tuple[Tool, ...] = field(factory=tuple, converter=tuple)
  • kwargs: providers were inconsistent on accepting this, which could lead to small bugs
-        messages: List[Message],
-        tools: Tuple[Tool],
-    ) -> Tuple[Message, Usage]:
+        messages: list[Message],
+        tools: tuple[Tool, ...],
+        **kwargs: dict[str, any],
+    ) -> tuple[Message, Usage]:

…signature

This migrates from typing imports to primitives per the following feedback from @lamchau:

> :nit: i think our patterns here don't realize as of python 3.9+ we generally don't need `Dict`, `List`, and `Tuple` anymore we can use the primitives (`dict`, `list`, and `tuple` respectively)

This also fixes inconsistency in our provider completion signature with regards to:

* tools: more precisely allow any amount of tools as often there are none
```diff
-    tools: Tuple[Tool] = field(factory=tuple, converter=tuple)
+    tools: tuple[Tool, ...] = field(factory=tuple, converter=tuple)
```

* kwargs: providers were inconsistent on accepting this, which could lead to small bugs

```diff
-        messages: List[Message],
-        tools: Tuple[Tool],
-    ) -> Tuple[Message, Usage]:
+        messages: list[Message],
+        tools: tuple[Tool, ...],
+        **kwargs: dict[str, any],
+    ) -> tuple[Message, Usage]:
```

Signed-off-by: Adrian Cole <adrian.cole@elastic.co>
Copy link
Collaborator Author

@codefromthecrypt codefromthecrypt left a comment

Choose a reason for hiding this comment

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

notes

@@ -14,10 +14,10 @@
@pytest.mark.parametrize(
"env_var_name",
[
("AZURE_CHAT_COMPLETIONS_HOST_NAME"),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

static analysis found this an unnecessary coersion

@@ -1,5 +1,5 @@
import re
from typing import Callable, List, Tuple
from typing import Callable
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

in cases like this, I couldn't use the primitive as it wasn't subscriptable

Copy link
Collaborator

@lamchau lamchau Oct 15, 2024

Choose a reason for hiding this comment

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

fwiw this Callable was deprecated which kind of solves the subscriptable problem. we'd probably always need to keep one of those since i don't recall it's hinting can be expressed otherwise

https://docs.python.org/3/library/typing.html#typing.Callable

Deprecated since version 3.9: collections.abc.Callable now supports subscripting ([]). See PEP 585 and Generic Alias Type.

edit: i stand corrected there is a callable primitive for hinting but not sure what's going on here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

me neither.. if you figure it out, ping me!

@lamchau
Copy link
Collaborator

lamchau commented Oct 15, 2024

lgtm!

@codefromthecrypt codefromthecrypt merged commit c247c8e into block:main Oct 15, 2024
4 checks passed
@codefromthecrypt codefromthecrypt deleted the primitives branch October 15, 2024 22:42
ahau-square added a commit that referenced this pull request Oct 16, 2024
* origin/main:
  docs: add subheaders to the 'Other ways to run Goose' section (#155)
  fix: Remove tools from exchange when summarizing files (#157)
  chore: use primitives instead of typing imports and fixes completion … (#149)
  chore: make vcr tests pretty-print JSON (#146)
  chore(release): goose 0.9.5 (#159)
  chore(release): exchange 0.9.5 (#158)
lukealvoeiro added a commit that referenced this pull request Oct 17, 2024
* main: (23 commits)
  feat: Run with resume session (#153)
  refactor: move langfuse wrapper to a module in exchange instead of a package (#138)
  docs: add subheaders to the 'Other ways to run Goose' section (#155)
  fix: Remove tools from exchange when summarizing files (#157)
  chore: use primitives instead of typing imports and fixes completion … (#149)
  chore: make vcr tests pretty-print JSON (#146)
  chore(release): goose 0.9.5 (#159)
  chore(release): exchange 0.9.5 (#158)
  chore: updates ollama default model from mistral-nemo to qwen2.5 (#150)
  feat: add vision support for Google (#141)
  fix: session resume with arg handled incorrectly (#145)
  docs: add release instructions to CONTRIBUTING.md (#143)
  docs: add link to action, IDE words (#140)
  docs: goosehints doc fix only (#142)
  chore(release): release 0.9.4 (#136)
  revert: "feat: add local langfuse tracing option  (#106)" (#137)
  feat: add local langfuse tracing option  (#106)
  feat: add groq provider (#134)
  feat: add a deep thinking reasoner model (o1-preview/mini) (#68)
  fix: use concrete SessionNotifier (#135)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants