Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def __init__(
*,
project_id: str,
location: str,
contents: ContentListUnionDict,
contents: ContentListUnionDict | list[str],
model: str,
generation_config: GenerateContentConfig | dict[str, Any] | None = None,
gcp_conn_id: str = "google_cloud_default",
Expand Down Expand Up @@ -311,7 +311,7 @@ def __init__(
*,
project_id: str,
location: str,
contents: ContentListUnion | ContentListUnionDict,
contents: ContentListUnion | ContentListUnionDict | list[str],
model: str,
config: CountTokensConfigOrDict | None = None,
gcp_conn_id: str = "google_cloud_default",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from __future__ import annotations

import os
from collections.abc import Sequence
from datetime import datetime

import requests
Expand Down Expand Up @@ -199,22 +200,23 @@ def _get_metrics():
You are an expert researcher. You always stick to the facts in the sources provided, and never make up new facts.
Now look at these research papers, and answer the following questions.
"""
_CACHED_CONTENTS: Sequence[Content] = [
Content(
role="user",
parts=[
Part.from_uri(
file_uri="gs://cloud-samples-data/generative-ai/pdf/2312.11805v3.pdf",
mime_type="application/pdf",
),
Part.from_uri(
file_uri="gs://cloud-samples-data/generative-ai/pdf/2403.05530.pdf",
mime_type="application/pdf",
),
],
)
]
CACHED_CONTENT_CONFIG = CreateCachedContentConfig(
contents=[
Content(
role="user",
parts=[
Part.from_uri(
file_uri="gs://cloud-samples-data/generative-ai/pdf/2312.11805v3.pdf",
mime_type="application/pdf",
),
Part.from_uri(
file_uri="gs://cloud-samples-data/generative-ai/pdf/2403.05530.pdf",
mime_type="application/pdf",
),
],
)
],
contents=_CACHED_CONTENTS,
system_instruction=CACHED_SYSTEM_INSTRUCTION,
display_name="test-cache",
ttl="3600s",
Expand Down
32 changes: 17 additions & 15 deletions providers/google/tests/unit/google/cloud/hooks/test_gen_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# under the License.
from __future__ import annotations

from collections.abc import Sequence
from unittest import mock
from unittest.mock import AsyncMock

Expand Down Expand Up @@ -75,22 +76,23 @@
Now look at these research papers, and answer the following questions.
"""

_CACHED_CONTENTS: Sequence[Content] = [
Content(
role="user",
parts=[
Part.from_uri(
file_uri="gs://cloud-samples-data/generative-ai/pdf/2312.11805v3.pdf",
mime_type="application/pdf",
),
Part.from_uri(
file_uri="gs://cloud-samples-data/generative-ai/pdf/2403.05530.pdf",
mime_type="application/pdf",
),
],
)
]
CACHED_CONTENT_CONFIG = CreateCachedContentConfig(
contents=[
Content(
role="user",
parts=[
Part.from_uri(
file_uri="gs://cloud-samples-data/generative-ai/pdf/2312.11805v3.pdf",
mime_type="application/pdf",
),
Part.from_uri(
file_uri="gs://cloud-samples-data/generative-ai/pdf/2403.05530.pdf",
mime_type="application/pdf",
),
],
)
],
contents=_CACHED_CONTENTS,
system_instruction=TEST_CACHED_SYSTEM_INSTRUCTION,
display_name="test-cache",
ttl="3600s",
Expand Down
32 changes: 17 additions & 15 deletions providers/google/tests/unit/google/cloud/operators/test_gen_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# under the License.
from __future__ import annotations

from collections.abc import Sequence
from unittest import mock

import pytest
Expand Down Expand Up @@ -60,22 +61,23 @@
You are an expert researcher. You always stick to the facts in the sources provided, and never make up new facts.
Now look at these research papers, and answer the following questions.
"""
_CACHED_CONTENTS: Sequence[Content] = [
Content(
role="user",
parts=[
Part.from_uri(
file_uri="gs://cloud-samples-data/generative-ai/pdf/2312.11805v3.pdf",
mime_type="application/pdf",
),
Part.from_uri(
file_uri="gs://cloud-samples-data/generative-ai/pdf/2403.05530.pdf",
mime_type="application/pdf",
),
],
)
]
CACHED_CONTENT_CONFIG = CreateCachedContentConfig(
contents=[
Content(
role="user",
parts=[
Part.from_uri(
file_uri="gs://cloud-samples-data/generative-ai/pdf/2312.11805v3.pdf",
mime_type="application/pdf",
),
Part.from_uri(
file_uri="gs://cloud-samples-data/generative-ai/pdf/2403.05530.pdf",
mime_type="application/pdf",
),
],
)
],
contents=_CACHED_CONTENTS,
system_instruction=CACHED_SYSTEM_INSTRUCTION,
display_name="test-cache",
ttl="3600s",
Expand Down
Loading