chore: import upstream snapshot with attribution
Continuous Integration / Pre-commit Linter (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.10) (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.11) (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.12) (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.13) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.10) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.11) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.12) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.13) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.14) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.10) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.11) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.12) (push) Has been cancelled
Copybara PR Handler / close-imported-pr (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.13) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.14) (push) Has been cancelled
Continuous Integration / Pre-commit Linter (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.10) (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.11) (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.12) (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.13) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.10) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.11) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.12) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.13) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.14) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.10) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.11) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.12) (push) Has been cancelled
Copybara PR Handler / close-imported-pr (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.13) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.14) (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
# Copyright 2026 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
@@ -0,0 +1,57 @@
|
||||
# Copyright 2026 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from google.adk.models.gemma_llm import Gemma
|
||||
from google.adk.models.llm_request import LlmRequest
|
||||
from google.adk.models.llm_response import LlmResponse
|
||||
from google.genai import types
|
||||
from google.genai.types import Content
|
||||
from google.genai.types import Part
|
||||
import pytest
|
||||
|
||||
DEFAULT_GEMMA_MODEL = "gemma-3-1b-it"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def gemma_llm():
|
||||
return Gemma(model=DEFAULT_GEMMA_MODEL)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def gemma_request():
|
||||
return LlmRequest(
|
||||
model=DEFAULT_GEMMA_MODEL,
|
||||
contents=[
|
||||
Content(
|
||||
role="user",
|
||||
parts=[
|
||||
Part.from_text(text="You are a helpful assistant."),
|
||||
Part.from_text(text="Hello!"),
|
||||
],
|
||||
)
|
||||
],
|
||||
config=types.GenerateContentConfig(
|
||||
temperature=0.1,
|
||||
response_modalities=[types.Modality.TEXT],
|
||||
system_instruction="Talk like a pirate.",
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize("llm_backend", ["GOOGLE_AI"])
|
||||
async def test_generate_content_async(gemma_llm, gemma_request):
|
||||
async for response in gemma_llm.generate_content_async(gemma_request):
|
||||
assert isinstance(response, LlmResponse)
|
||||
assert response.content.parts[0].text
|
||||
@@ -0,0 +1,65 @@
|
||||
# Copyright 2026 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from google.adk.models.google_llm import Gemini
|
||||
from google.adk.models.llm_request import LlmRequest
|
||||
from google.adk.models.llm_response import LlmResponse
|
||||
from google.genai import types
|
||||
from google.genai.types import Content
|
||||
from google.genai.types import Part
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def gemini_llm():
|
||||
return Gemini(model="gemini-2.5-flash")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def llm_request():
|
||||
return LlmRequest(
|
||||
model="gemini-2.5-flash",
|
||||
contents=[Content(role="user", parts=[Part.from_text(text="Hello")])],
|
||||
config=types.GenerateContentConfig(
|
||||
temperature=0.1,
|
||||
response_modalities=[types.Modality.TEXT],
|
||||
system_instruction="You are a helpful assistant",
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_generate_content_async(gemini_llm, llm_request):
|
||||
async for response in gemini_llm.generate_content_async(llm_request):
|
||||
assert isinstance(response, LlmResponse)
|
||||
assert response.content.parts[0].text
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_generate_content_async_stream(gemini_llm, llm_request):
|
||||
responses = [
|
||||
resp
|
||||
async for resp in gemini_llm.generate_content_async(
|
||||
llm_request, stream=True
|
||||
)
|
||||
]
|
||||
text = ""
|
||||
for i in range(len(responses) - 1):
|
||||
assert responses[i].partial is True
|
||||
assert responses[i].content.parts[0].text
|
||||
text += responses[i].content.parts[0].text
|
||||
|
||||
# Last message should be accumulated text
|
||||
assert responses[-1].content.parts[0].text == text
|
||||
assert not responses[-1].partial
|
||||
@@ -0,0 +1,165 @@
|
||||
# Copyright 2026 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from google.adk.models.lite_llm import LiteLlm
|
||||
from google.adk.models.llm_request import LlmRequest
|
||||
from google.adk.models.llm_response import LlmResponse
|
||||
from google.genai import types
|
||||
from google.genai.types import Content
|
||||
from google.genai.types import Part
|
||||
import pytest
|
||||
|
||||
_TEST_MODEL_NAME = "vertex_ai/meta/llama-3.1-405b-instruct-maas"
|
||||
|
||||
_SYSTEM_PROMPT = """You are a helpful assistant."""
|
||||
|
||||
|
||||
def get_weather(city: str) -> str:
|
||||
"""Simulates a web search. Use it get information on weather.
|
||||
|
||||
Args:
|
||||
city: A string containing the location to get weather information for.
|
||||
|
||||
Returns:
|
||||
A string with the simulated weather information for the queried city.
|
||||
"""
|
||||
if "sf" in city.lower() or "san francisco" in city.lower():
|
||||
return "It's 70 degrees and foggy."
|
||||
return "It's 80 degrees and sunny."
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def oss_llm():
|
||||
return LiteLlm(model=_TEST_MODEL_NAME)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def llm_request():
|
||||
return LlmRequest(
|
||||
model=_TEST_MODEL_NAME,
|
||||
contents=[Content(role="user", parts=[Part.from_text(text="hello")])],
|
||||
config=types.GenerateContentConfig(
|
||||
temperature=0.1,
|
||||
response_modalities=[types.Modality.TEXT],
|
||||
system_instruction=_SYSTEM_PROMPT,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def llm_request_with_tools():
|
||||
return LlmRequest(
|
||||
model=_TEST_MODEL_NAME,
|
||||
contents=[
|
||||
Content(
|
||||
role="user",
|
||||
parts=[
|
||||
Part.from_text(text="What is the weather in San Francisco?")
|
||||
],
|
||||
)
|
||||
],
|
||||
config=types.GenerateContentConfig(
|
||||
temperature=0.1,
|
||||
response_modalities=[types.Modality.TEXT],
|
||||
system_instruction=_SYSTEM_PROMPT,
|
||||
tools=[
|
||||
types.Tool(
|
||||
function_declarations=[
|
||||
types.FunctionDeclaration(
|
||||
name="get_weather",
|
||||
description="Get the weather in a given location",
|
||||
parameters=types.Schema(
|
||||
type=types.Type.OBJECT,
|
||||
properties={
|
||||
"city": types.Schema(
|
||||
type=types.Type.STRING,
|
||||
description=(
|
||||
"The city to get the weather for."
|
||||
),
|
||||
),
|
||||
},
|
||||
required=["city"],
|
||||
),
|
||||
)
|
||||
]
|
||||
)
|
||||
],
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_generate_content_async(oss_llm, llm_request):
|
||||
async for response in oss_llm.generate_content_async(llm_request):
|
||||
assert isinstance(response, LlmResponse)
|
||||
assert response.content.parts[0].text
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_generate_content_async(oss_llm, llm_request):
|
||||
responses = [
|
||||
resp
|
||||
async for resp in oss_llm.generate_content_async(
|
||||
llm_request, stream=False
|
||||
)
|
||||
]
|
||||
part = responses[0].content.parts[0]
|
||||
assert len(part.text) > 0
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_generate_content_async_with_tools(
|
||||
oss_llm, llm_request_with_tools
|
||||
):
|
||||
responses = [
|
||||
resp
|
||||
async for resp in oss_llm.generate_content_async(
|
||||
llm_request_with_tools, stream=False
|
||||
)
|
||||
]
|
||||
function_call = responses[0].content.parts[0].function_call
|
||||
assert function_call.name == "get_weather"
|
||||
assert function_call.args["city"] == "San Francisco"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_generate_content_async_stream(oss_llm, llm_request):
|
||||
responses = [
|
||||
resp
|
||||
async for resp in oss_llm.generate_content_async(llm_request, stream=True)
|
||||
]
|
||||
text = ""
|
||||
for i in range(len(responses) - 1):
|
||||
assert responses[i].partial is True
|
||||
assert responses[i].content.parts[0].text
|
||||
text += responses[i].content.parts[0].text
|
||||
|
||||
# Last message should be accumulated text
|
||||
assert responses[-1].content.parts[0].text == text
|
||||
assert not responses[-1].partial
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_generate_content_async_stream_with_tools(
|
||||
oss_llm, llm_request_with_tools
|
||||
):
|
||||
responses = [
|
||||
resp
|
||||
async for resp in oss_llm.generate_content_async(
|
||||
llm_request_with_tools, stream=True
|
||||
)
|
||||
]
|
||||
function_call = responses[-1].content.parts[0].function_call
|
||||
assert function_call.name == "get_weather"
|
||||
assert function_call.args["city"] == "San Francisco"
|
||||
@@ -0,0 +1,112 @@
|
||||
# Copyright 2026 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from google.adk.models.lite_llm import LiteLlm
|
||||
from google.adk.models.llm_request import LlmRequest
|
||||
from google.genai import types
|
||||
from google.genai.types import Content
|
||||
from google.genai.types import Part
|
||||
import pytest
|
||||
|
||||
_TEST_MODEL_NAME = "vertex_ai/meta/llama-3.1-405b-instruct-maas"
|
||||
|
||||
_SYSTEM_PROMPT = """
|
||||
You are a helpful assistant, and call tools optionally.
|
||||
If call tools, the tool format should be in json body, and the tool argument values should be parsed from users inputs.
|
||||
"""
|
||||
|
||||
|
||||
_FUNCTIONS = [{
|
||||
"name": "get_weather",
|
||||
"description": "Get the weather in a given location",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"city": {
|
||||
"type": "string",
|
||||
"description": "The city to get the weather for.",
|
||||
},
|
||||
},
|
||||
"required": ["city"],
|
||||
},
|
||||
}]
|
||||
|
||||
|
||||
def get_weather(city: str) -> str:
|
||||
"""Simulates a web search. Use it get information on weather.
|
||||
|
||||
Args:
|
||||
city: A string containing the location to get weather information for.
|
||||
|
||||
Returns:
|
||||
A string with the simulated weather information for the queried city.
|
||||
"""
|
||||
if "sf" in city.lower() or "san francisco" in city.lower():
|
||||
return "It's 70 degrees and foggy."
|
||||
return "It's 80 degrees and sunny."
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def oss_llm_with_function():
|
||||
return LiteLlm(model=_TEST_MODEL_NAME, functions=_FUNCTIONS)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def llm_request():
|
||||
return LlmRequest(
|
||||
model=_TEST_MODEL_NAME,
|
||||
contents=[
|
||||
Content(
|
||||
role="user",
|
||||
parts=[
|
||||
Part.from_text(text="What is the weather in San Francisco?")
|
||||
],
|
||||
)
|
||||
],
|
||||
config=types.GenerateContentConfig(
|
||||
temperature=0.1,
|
||||
response_modalities=[types.Modality.TEXT],
|
||||
system_instruction=_SYSTEM_PROMPT,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_generate_content_async_with_function(
|
||||
oss_llm_with_function, llm_request
|
||||
):
|
||||
responses = [
|
||||
resp
|
||||
async for resp in oss_llm_with_function.generate_content_async(
|
||||
llm_request, stream=False
|
||||
)
|
||||
]
|
||||
function_call = responses[0].content.parts[0].function_call
|
||||
assert function_call.name == "get_weather"
|
||||
assert function_call.args["city"] == "San Francisco"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_generate_content_async_stream_with_function(
|
||||
oss_llm_with_function, llm_request
|
||||
):
|
||||
responses = [
|
||||
resp
|
||||
async for resp in oss_llm_with_function.generate_content_async(
|
||||
llm_request, stream=True
|
||||
)
|
||||
]
|
||||
function_call = responses[-1].content.parts[0].function_call
|
||||
assert function_call.name == "get_weather"
|
||||
assert function_call.args["city"] == "San Francisco"
|
||||
Reference in New Issue
Block a user