mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Python: Fix Gemini client support for Gemini API and Vertex AI (#5258)
* Add Gemini and Vertex AI client support Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Address Gemini PR review feedback Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * removed sample run readme part --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Evan Mattson <35585003+moonbox3@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
Unverified
parent
c14beedb3a
commit
90a633967c
@@ -4,9 +4,9 @@
|
||||
|
||||
Allows the model to reason through complex problems before responding.
|
||||
|
||||
Requires the following environment variables to be set:
|
||||
- GEMINI_API_KEY
|
||||
- GEMINI_MODEL
|
||||
Requires ``GOOGLE_MODEL`` or ``GEMINI_MODEL`` and either Gemini Developer API credentials
|
||||
(``GEMINI_API_KEY`` or ``GOOGLE_API_KEY``) or Vertex AI settings
|
||||
(``GOOGLE_GENAI_USE_VERTEXAI``, ``GOOGLE_CLOUD_PROJECT``, and ``GOOGLE_CLOUD_LOCATION``).
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
@@ -23,10 +23,12 @@ async def main() -> None:
|
||||
"""Example of extended thinking with a Python version comparison question."""
|
||||
print("=== Extended thinking ===")
|
||||
|
||||
# 1. Configure Gemini extended thinking for a reasoning-heavy request.
|
||||
options: GeminiChatOptions = {
|
||||
"thinking_config": ThinkingConfig(thinking_budget=2048),
|
||||
}
|
||||
|
||||
# 2. Create the agent with the Gemini chat client and default thinking options.
|
||||
agent = Agent(
|
||||
client=GeminiChatClient(),
|
||||
name="PythonAgent",
|
||||
@@ -34,6 +36,7 @@ async def main() -> None:
|
||||
default_options=options,
|
||||
)
|
||||
|
||||
# 3. Stream the answer so you can see the final response as it arrives.
|
||||
query = "What new language features were introduced in Python between 3.10 and 3.14?"
|
||||
print(f"User: {query}")
|
||||
print("Agent: ", end="", flush=True)
|
||||
@@ -45,3 +48,12 @@ async def main() -> None:
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
|
||||
"""
|
||||
Sample output:
|
||||
=== Extended thinking ===
|
||||
User: What new language features were introduced in Python between 3.10 and 3.14?
|
||||
Agent: Python 3.11 introduced exception groups and TaskGroup.
|
||||
Python 3.12 added PEP 695 type parameter syntax.
|
||||
Python 3.13-3.14 continued improving typing, performance, and developer ergonomics.
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user