Skip to content

chore(python): Updated Python documentation for 0.50 alpha#217

Open
huangjeff5 wants to merge 7 commits intomainfrom
jh-python-docs
Open

chore(python): Updated Python documentation for 0.50 alpha#217
huangjeff5 wants to merge 7 commits intomainfrom
jh-python-docs

Conversation

@huangjeff5
Copy link
Collaborator

No description provided.

@gemini-code-assist
Copy link

Summary of Changes

Hello @huangjeff5, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request delivers a substantial overhaul and expansion of the Python documentation for the Genkit 0.50 alpha release. The primary goal is to provide Python developers with comprehensive and current guides for integrating Genkit into their AI applications. This includes a strategic shift towards FastAPI for web framework integration, detailed instructions for various model and utility plugins, and in-depth explanations of core Genkit functionalities like prompt management, evaluation, and deployment. The updates aim to streamline the developer experience and ensure feature parity in documentation across supported languages.

Highlights

  • Python Documentation Expansion: The pull request introduces extensive new and updated documentation for Python, covering a wide array of Genkit features, plugins, and deployment strategies.
  • FastAPI Adoption: The Python web framework integration has shifted from Flask to FastAPI, with updated deployment guides for platforms like Cloud Run and general 'any-platform' deployments.
  • Enhanced Plugin Documentation: Detailed documentation has been added for numerous Python plugins, including Anthropic, DeepSeek, Google Cloud, Google GenAI, Ollama, OpenAI-Compatible, OpenAI, Vertex AI (with Vector Search for BigQuery and Firestore), and xAI.
  • Core Feature Guides for Python: Key Genkit features like Dotprompt, Evaluation, Flows, Interrupts, Local Observability, Model Context Protocol (MCP), Models (including parameters, structured output, media generation), Plugin Authoring, RAG (with Indexers), and Tool Calling now have comprehensive Python-specific guides and examples.
  • Improved Getting Started Experience: The Python getting started guide has been updated to recommend the uv package manager for project initialization and dependency management.
Changelog
  • src/content/docs/docs/chat.mdx
    • Added 'python' to the LanguageSelector component to enable Python-specific content.
    • Updated the Python-specific content to reflect that the specialized Chat API for Genkit Python is under development, replacing previous notes about unavailability.
  • src/content/docs/docs/deployment/any-platform.mdx
    • Replaced the Flask-based Python deployment guide with a new, comprehensive guide using FastAPI for deploying Genkit apps to any platform.
  • src/content/docs/docs/deployment/authorization.mdx
    • Updated the LanguageSelector component to support Python.
    • Corrected a note for Go regarding HTTP authorization guidance, changing 'Python' to 'Go'.
  • src/content/docs/docs/deployment/cloud-run.mdx
    • Replaced the Flask-based Python Cloud Run deployment guide with a detailed FastAPI-based guide, including project setup with uv, defining flows, creating a web server, running the app, deployment steps, and production best practices.
  • src/content/docs/docs/dotprompt.mdx
    • Updated the page description to include Python support for Dotprompt.
    • Added 'python' to the LanguageSelector component.
    • Removed the 'Feature unavailable for Python' note.
    • Added Python-specific examples for setting up a prompt directory, configuring prompt_dir, using the developer UI, loading and calling prompts (including streaming), configuring generation options, structured output with Pydantic models, defining partials, defining custom helpers, and using prompt variants.
  • src/content/docs/docs/evaluation.mdx
    • Added 'python' to the LanguageSelector component.
    • Replaced the 'Feature documentation unavailable for Python' note with a comprehensive guide on evaluation for Python, covering setup, dataset creation, running evaluations, core concepts, supported evaluators (Genkit, plugins, custom), programmatic evaluation, advanced comparison features, CLI usage, custom extractors, and synthesizing test data with LLMs.
  • src/content/docs/docs/flows.mdx
    • Updated Python flow examples to use from genkit import Output and output=Output(schema=...) instead of output_schema=....
    • Changed genkit start -- python app.py to genkit start -- uv run app.py in the Python section for running the Dev UI.
    • Added a new section 'Flow steps' for Python, explaining how ai.run() wraps non-Genkit code for tracing and providing an example.
  • src/content/docs/docs/frameworks/express.mdx
    • Updated the Python-specific note to refer to the 'FastAPI integration guide' instead of the 'Flask integration guide'.
  • src/content/docs/docs/get-started.mdx
    • Added uv package manager as a prerequisite for Python and provided installation instructions.
    • Updated Python project setup to use uv init instead of python3 -m venv and source bin/activate.
    • Changed Python package installation from pip3 install genkit genkit-plugin-google-genai (and requirements.txt) to uv add genkit genkit-plugin-google-genai.
    • Updated Python code examples to use from genkit import Output and output=Output(schema=...).
    • Changed json.dumps(recipe, indent=2) to recipe.model_dump_json(indent=2) for printing structured output.
    • Updated Python app execution commands from python3 main.py to uv run main.py and genkit start -- python3 main.py to genkit start -- uv run main.py.
  • src/content/docs/docs/integrations/anthropic.mdx
    • Added 'python' to the LanguageSelector component.
    • Replaced the 'Feature unavailable for Python' note with a complete Python documentation for the genkit-plugin-anthropic package, covering installation, configuration, authentication, available models, basic usage, structured output, thinking and reasoning, tool calling, streaming, multimodal input, and configuration options.
  • src/content/docs/docs/integrations/cloud-firestore.mdx
    • Updated the Python documentation for Firestore Vector Store, changing pip3 install to uv add.
    • Revised the configuration and usage examples to use define_firestore_vector_store and reflect current best practices for indexing and retrieving documents with embeddings.
  • src/content/docs/docs/integrations/deepseek.mdx
    • Updated the page description to include Python support for the DeepSeek plugin.
    • Added 'python' to the LanguageSelector component.
    • Replaced the 'Feature unavailable for Python' note with a comprehensive Python documentation for the genkit-plugin-deepseek package, including installation, configuration, authentication, usage with various models, reasoning model, tool calling, streaming, multi-turn chat, structured output, and passthrough configuration.
  • src/content/docs/docs/integrations/google-cloud.mdx
    • Added 'python' to the LanguageSelector component.
    • Added a new Python section for the Google Cloud telemetry plugin, detailing prerequisites, installation, configuration with add_gcp_telemetry, and authentication methods.
  • src/content/docs/docs/integrations/google-genai.mdx
    • Updated Python documentation for the genkit-plugin-google-genai package, expanding coverage to include various model types (Language, Embedding, Image, Video, Speech) and advanced features like structured output, thinking/reasoning, Google Search grounding, safety settings, and multimodal input.
  • src/content/docs/docs/integrations/ollama.mdx
    • Updated Python documentation for the genkit-plugin-ollama package, providing detailed prerequisites (Ollama server installation), installation with uv add, configuration with ModelDefinition and EmbeddingDefinition, usage examples, and advanced features like embeddings, streaming, tool calling, structured output, and custom server configuration.
  • src/content/docs/docs/integrations/openai-compatible.mdx
    • Updated the page description to include Python support for the OpenAI-compatible plugin.
    • Added 'python' to the LanguageSelector component.
    • Replaced the 'Feature unavailable for Python' note with a comprehensive Python documentation for the genkit-plugin-compat-oai package, covering overview, prerequisites, installation, configuration for compatible providers, and common configuration options.
  • src/content/docs/docs/integrations/openai.mdx
    • Changed pip install to uv add for Python installation.
    • Expanded Python documentation to include text embedding models and advanced usage with passthrough configuration.
  • src/content/docs/docs/integrations/vectorsearch-bigquery.mdx
    • Replaced the 'Feature unavailable for Python' note with a comprehensive Python documentation for Vertex AI Vector Search with BigQuery, covering installation, prerequisites, configuration with define_vertex_vector_search_big_query, indexing documents, retrieving documents, and a complete RAG example.
  • src/content/docs/docs/integrations/vectorsearch-firestore.mdx
    • Replaced the 'Feature unavailable for Python' note with a comprehensive Python documentation for Vertex AI Vector Search with Firestore, covering installation, prerequisites, configuration with define_vertex_vector_search_firestore, indexing documents, retrieving documents, and a complete RAG example.
  • src/content/docs/docs/integrations/vertex-ai.mdx
    • Added 'python' to the LanguageSelector component.
    • Significantly expanded the Python documentation for the Vertex AI plugin, separating basic model access from enterprise features. New sections include authentication methods (ADC, Express Mode), thinking config, grounding, context caching, Model Garden integration (Claude 3, Llama 3.1, Mistral), evaluation metrics, and vector search (Firestore, BigQuery).
  • src/content/docs/docs/integrations/xai.mdx
    • Updated the page description to include Python and Go support for the xAI plugin.
    • Added 'python' and 'go' to the LanguageSelector component.
    • Replaced the 'Feature unavailable for Python' note with a comprehensive Python documentation for the genkit-plugin-xai package, including installation, configuration, authentication, usage with Grok models, advanced features like tool calling, streaming, vision capabilities, structured output, and passthrough configuration.
  • src/content/docs/docs/interrupts.mdx
    • Updated Python examples for defining and using interrupts, including more detailed ctx.interrupt() usage, handling multiple interrupts in a loop, and tools with confirmation interrupts.
    • Added an example of using interrupts within flows for Python.
  • src/content/docs/docs/local-observability.mdx
    • Added a new Python section for local observability, explaining structlog integration and how the Google Cloud plugin injects trace/span fields.
    • Added Python examples for production observability with Firebase telemetry and third-party OTLP export.
  • src/content/docs/docs/model-context-protocol.mdx
    • Added 'python' to the LanguageSelector component.
    • Replaced the 'Feature unavailable for Python' note with a comprehensive Python documentation for the Model Context Protocol (MCP) plugin, covering installation, MCP client, MCP host, MCP server, configuration options, and using MCP tools with AI.
  • src/content/docs/docs/models.mdx
    • Added new Python sections under 'Models' for 'Before you begin', 'Models supported by Genkit', 'Parameters that control output length' (max_output_tokens, stop_sequences), 'Parameters that control "creativity"' (temperature, top_p, top_k), 'Experiment with model parameters', 'Handling errors' for structured output, 'Media generation', and 'Next steps' for advanced LLM use and testing model output.
  • src/content/docs/docs/observability/advanced-configuration.mdx
    • Added 'python' to the LanguageSelector component.
    • Removed the 'Unavailable for Python' note.
    • Added Python code examples for default telemetry configuration, exporting local telemetry (force_dev_export), adjusting export intervals, and disabling specific auto-instrumentation (input/output logging, metrics, traces).
  • src/content/docs/docs/observability/authentication.mdx
    • Added 'python' to the LanguageSelector component.
    • Removed the 'Unavailable for Python' note.
  • src/content/docs/docs/observability/getting-started.mdx
    • Added 'python' to the LanguageSelector component.
    • Removed the 'Unavailable for Python' note.
    • Added Python instructions for installing the Firebase telemetry plugin (pip install "genkit-plugin-firebase[telemetry]").
    • Added Python code example for enabling Firebase Genkit Monitoring in code (add_firebase_telemetry()).
    • Added Python instruction for setting force_dev_export to True for local telemetry export.
  • src/content/docs/docs/observability/telemetry-collection.mdx
    • Added 'python' to the LanguageSelector component.
    • Removed the 'Unavailable for Python' note.
  • src/content/docs/docs/observability/troubleshooting.mdx
    • Added 'python' to the LanguageSelector component.
    • Removed the 'Unavailable for Python' note.
    • Added Python code examples for enabling dev export (add_gcp_telemetry(force_dev_export=True)) and overriding metric export intervals/timeouts.
  • src/content/docs/docs/plugin-authoring/overview.mdx
    • Added 'python' to the LanguageSelector component.
    • Replaced the 'Unavailable for Python' note with comprehensive Python guidance for writing custom Genkit plugins, including basic structure, plugin options, building model plugins (defining models, capabilities), and publishing a plugin with recommended keywords.
  • src/content/docs/docs/rag.mdx
    • Added a new bullet point for 'Indexers' in the RAG overview.
    • Added a new 'Indexers' section for Python, detailing their purpose, defining custom indexers with ai.define_indexer(), using indexers, and IndexerRef.
    • Updated the Python Firestore retriever example to use define_firestore_vector_store and improved the RAG flow structure.
  • src/content/docs/docs/tool-calling.mdx
    • Removed the 'Dynamically defining tools at runtime' section.
    • Updated the 'Before you begin' section to refer to the 'Getting started' guide.
    • Added an ExampleLink component for a 'Tool Calling' demo.
    • Updated Python tool definition example to include name and description in the decorator.
    • Expanded 'Using tools' section with examples for generate(), definePrompt(), Prompt files, and Chat.
    • Added a new 'Streaming and Tool Calling' section with a Python example and explanation of chunks.
    • Added a new 'Limiting Tool Call Iterations with maxTurns' section with Python examples for web research and financial calculator agents.
    • Added a new 'Extending Tool Capabilities with MCP' section.
    • Updated 'Next steps' to include MCP, interrupts, RAG, and multi-agent systems.
  • src/sidebar.ts
    • Updated the sidebar entry for Python frameworks, changing 'Flask' to 'FastAPI' and updating the slug accordingly.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request significantly expands and updates the Python documentation across various Genkit features and integrations. Key changes include adding Python support to the LanguageSelector component in several documentation files (chat.mdx, dotprompt.mdx, evaluation.mdx, anthropic.mdx, deepseek.mdx, google-cloud.mdx, openai-compatible.mdx, xai.mdx, model-context-protocol.mdx, observability/advanced-configuration.mdx, observability/authentication.mdx, observability/getting-started.mdx, observability/telemetry-collection.mdx, observability/troubleshooting.mdx).

The Python deployment guides have been overhauled, replacing Flask-based examples with comprehensive FastAPI instructions for both general deployment (any-platform.mdx) and Cloud Run (cloud-run.mdx), including detailed setup with uv, Dockerfiles, and production best practices. The get-started.mdx guide now mandates uv for Python project setup and package management.

Python-specific content has been added or updated for advanced features such as Dotprompt (dotprompt.mdx), Evaluation (evaluation.mdx), Model Context Protocol (model-context-protocol.mdx), and Tool Calling (tool-calling.mdx), including examples for streaming, structured output, and handling interrupts. The flows.mdx file updates Python examples to use Output(schema=...) for structured output and introduces a 'Flow steps' section with ai.run() examples.

Plugin integration documentation for Python has been extensively updated or newly added for Anthropic, DeepSeek, Google Cloud, Google GenAI, Ollama, OpenAI, OpenAI-Compatible, xAI, Firebase Firestore, Vertex AI Vector Search with BigQuery, and Vertex AI Vector Search with Firestore. These updates include installation instructions using uv add (where applicable), configuration details, available models, and usage examples covering text generation, embeddings, structured output, tool calling, streaming, and multimodal capabilities. The rag.mdx file now includes Python examples for defining and using indexers.

Review comments highlight several issues: a missing slowapi dependency in the uv add command for rate limiting in cloud-run.mdx, an incorrect reference to genkit-tools.conf.js in the Python evaluation documentation, and consistent misuse of add_gcp_telemetry instead of add_firebase_telemetry in Python observability examples. Additionally, there are multiple instances of googleai/gemini-2.0-flash being used instead of the more current googleai/gemini-2.5-flash model name, and some pip install commands need to be updated to uv add for consistency.

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