Skip to content

Commit

Permalink
refact!: adjust import paths (#268)
Browse files Browse the repository at this point in the history
* adjust import paths

* fix coverage
  • Loading branch information
masci authored Jan 25, 2024
1 parent 7e21bd8 commit fa72811
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 31 deletions.
18 changes: 9 additions & 9 deletions integrations/google_ai/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ Documentation = "https://github.com/deepset-ai/haystack-core-integrations/tree/m
Issues = "https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/google_ai_haystack/issues"
Source = "https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/google_ai_haystack"

[tool.hatch.build.targets.wheel]
packages = ["src/haystack_integrations"]

[tool.hatch.version]
source = "vcs"
tag-pattern = 'integrations\/google_ai-v(?P<version>.*)'
Expand Down Expand Up @@ -70,7 +73,7 @@ dependencies = [
"ruff>=0.0.243",
]
[tool.hatch.envs.lint.scripts]
typing = "mypy --install-types --non-interactive {args:src/google_ai_haystack tests}"
typing = "mypy --install-types --non-interactive --explicit-package-bases {args:src/ tests}"
style = [
"ruff {args:.}",
"black --check --diff {args:.}",
Expand Down Expand Up @@ -136,26 +139,22 @@ unfixable = [
]

[tool.ruff.isort]
known-first-party = ["google_ai_haystack"]
known-first-party = ["haystack_integrations"]

[tool.ruff.flake8-tidy-imports]
ban-relative-imports = "all"
ban-relative-imports = "parents"

[tool.ruff.per-file-ignores]
# Tests can use magic values, assertions, and relative imports
"tests/**/*" = ["PLR2004", "S101", "TID252"]

[tool.coverage.run]
source_pkgs = ["google_ai_haystack", "tests"]
branch = true
parallel = true
omit = [
"src/google_ai_haystack/__about__.py",
]

[tool.coverage.paths]
google_ai_haystack = ["src/google_ai_haystack", "*/google_ai_haystack/src/google_ai_haystack"]
tests = ["tests", "*/google_ai_haystack/tests"]
google_ai_haystack = ["src"]
tests = ["tests"]

[tool.coverage.report]
exclude_lines = [
Expand All @@ -167,6 +166,7 @@ exclude_lines = [
module = [
"google.*",
"haystack.*",
"haystack_integrations.*",
"pytest.*",
"numpy.*",
]
Expand Down
3 changes: 0 additions & 3 deletions integrations/google_ai/src/google_ai_haystack/__init__.py

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# SPDX-FileCopyrightText: 2023-present deepset GmbH <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0
from .chat.gemini import GoogleAIGeminiChatGenerator
from .gemini import GoogleAIGeminiGenerator

__all__ = ["GoogleAIGeminiGenerator", "GoogleAIGeminiChatGenerator"]
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class GoogleAIGeminiChatGenerator:
Sample usage:
```python
from haystack.dataclasses.chat_message import ChatMessage
from google_ai_haystack.generators.chat.gemini import GoogleAIGeminiChatGenerator
from haystack_integrations.components.generators.google_ai import GoogleAIGeminiChatGenerator
gemini_chat = GoogleAIGeminiChatGenerator(model="gemini-pro", api_key="<MY_API_KEY>")
Expand All @@ -43,7 +43,7 @@ class GoogleAIGeminiChatGenerator:
from haystack.dataclasses.chat_message import ChatMessage
from google.ai.generativelanguage import FunctionDeclaration, Tool
from google_ai_haystack.generators.chat.gemini import GoogleAIGeminiChatGenerator
from haystack_integrations.components.generators.google_ai import GoogleAIGeminiChatGenerator
# Example function to get the current weather
def get_current_weather(location: str, unit: str = "celsius") -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class GoogleAIGeminiGenerator:
Sample usage:
```python
from google_ai_haystack.generators.gemini import GoogleAIGeminiGenerator
from haystack_integrations.components.generators.google_ai import GoogleAIGeminiGenerator
gemini = GoogleAIGeminiGenerator(model="gemini-pro", api_key="<MY_API_KEY>")
res = gemini.run(parts = ["What is the most interesting thing you know?"])
Expand All @@ -32,7 +32,7 @@ class GoogleAIGeminiGenerator:
```python
import requests
from haystack.dataclasses.byte_stream import ByteStream
from google_ai_haystack.generators.gemini import GoogleAIGeminiGenerator
from haystack_integrations.components.generators.google_ai import GoogleAIGeminiGenerator
BASE_URL = (
"https://raw.githubusercontent.com/deepset-ai/haystack-core-integrations"
Expand Down
14 changes: 8 additions & 6 deletions integrations/google_ai/tests/generators/chat/test_chat_gemini.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from google.generativeai.types import HarmBlockThreshold, HarmCategory
from haystack.dataclasses.chat_message import ChatMessage

from google_ai_haystack.generators.chat.gemini import GoogleAIGeminiChatGenerator
from haystack_integrations.components.generators.google_ai import GoogleAIGeminiChatGenerator


def test_init():
Expand Down Expand Up @@ -40,7 +40,9 @@ def test_init():
)

tool = Tool(function_declarations=[get_current_weather_func])
with patch("google_ai_haystack.generators.chat.gemini.genai.configure") as mock_genai_configure:
with patch(
"haystack_integrations.components.generators.google_ai.chat.gemini.genai.configure"
) as mock_genai_configure:
gemini = GoogleAIGeminiChatGenerator(
generation_config=generation_config,
safety_settings=safety_settings,
Expand Down Expand Up @@ -85,14 +87,14 @@ def test_to_dict():

tool = Tool(function_declarations=[get_current_weather_func])

with patch("google_ai_haystack.generators.chat.gemini.genai.configure"):
with patch("haystack_integrations.components.generators.google_ai.chat.gemini.genai.configure"):
gemini = GoogleAIGeminiChatGenerator(
generation_config=generation_config,
safety_settings=safety_settings,
tools=[tool],
)
assert gemini.to_dict() == {
"type": "google_ai_haystack.generators.chat.gemini.GoogleAIGeminiChatGenerator",
"type": "haystack_integrations.components.generators.google_ai.chat.gemini.GoogleAIGeminiChatGenerator",
"init_parameters": {
"model": "gemini-pro-vision",
"generation_config": {
Expand All @@ -114,10 +116,10 @@ def test_to_dict():


def test_from_dict():
with patch("google_ai_haystack.generators.chat.gemini.genai.configure"):
with patch("haystack_integrations.components.generators.google_ai.chat.gemini.genai.configure"):
gemini = GoogleAIGeminiChatGenerator.from_dict(
{
"type": "google_ai_haystack.generators.chat.gemini.GoogleAIGeminiChatGenerator",
"type": "haystack_integrations.components.generators.google_ai.chat.gemini.GoogleAIGeminiChatGenerator",
"init_parameters": {
"model": "gemini-pro-vision",
"generation_config": {
Expand Down
12 changes: 6 additions & 6 deletions integrations/google_ai/tests/generators/test_gemini.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from google.generativeai import GenerationConfig, GenerativeModel
from google.generativeai.types import HarmBlockThreshold, HarmCategory

from google_ai_haystack.generators.gemini import GoogleAIGeminiGenerator
from haystack_integrations.components.generators.google_ai import GoogleAIGeminiGenerator


def test_init():
Expand Down Expand Up @@ -39,7 +39,7 @@ def test_init():
)

tool = Tool(function_declarations=[get_current_weather_func])
with patch("google_ai_haystack.generators.gemini.genai.configure") as mock_genai_configure:
with patch("haystack_integrations.components.generators.google_ai.gemini.genai.configure") as mock_genai_configure:
gemini = GoogleAIGeminiGenerator(
generation_config=generation_config,
safety_settings=safety_settings,
Expand Down Expand Up @@ -84,14 +84,14 @@ def test_to_dict():

tool = Tool(function_declarations=[get_current_weather_func])

with patch("google_ai_haystack.generators.gemini.genai.configure"):
with patch("haystack_integrations.components.generators.google_ai.gemini.genai.configure"):
gemini = GoogleAIGeminiGenerator(
generation_config=generation_config,
safety_settings=safety_settings,
tools=[tool],
)
assert gemini.to_dict() == {
"type": "google_ai_haystack.generators.gemini.GoogleAIGeminiGenerator",
"type": "haystack_integrations.components.generators.google_ai.gemini.GoogleAIGeminiGenerator",
"init_parameters": {
"model": "gemini-pro-vision",
"generation_config": {
Expand All @@ -113,10 +113,10 @@ def test_to_dict():


def test_from_dict():
with patch("google_ai_haystack.generators.gemini.genai.configure"):
with patch("haystack_integrations.components.generators.google_ai.gemini.genai.configure"):
gemini = GoogleAIGeminiGenerator.from_dict(
{
"type": "google_ai_haystack.generators.gemini.GoogleAIGeminiGenerator",
"type": "haystack_integrations.components.generators.google_ai.gemini.GoogleAIGeminiGenerator",
"init_parameters": {
"model": "gemini-pro-vision",
"generation_config": {
Expand Down

0 comments on commit fa72811

Please sign in to comment.