Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Python API Docs on GitHub Pages #619

Open
wants to merge 53 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
87510b0
Create .readthedocs.yaml
vi-shruti Oct 27, 2024
9fb4f08
Update .readthedocs.yaml
vi-shruti Oct 27, 2024
b88e7dd
Update .readthedocs.yaml
vi-shruti Oct 27, 2024
d21c16d
Update .readthedocs.yaml
vi-shruti Oct 27, 2024
6abddcc
Update .readthedocs.yaml
vi-shruti Oct 27, 2024
c3d3d64
Update .readthedocs.yaml
vi-shruti Oct 27, 2024
11b0eb7
Sphinx
vi-shruti Oct 28, 2024
23cd0a9
Update conf.py
vi-shruti Oct 28, 2024
e8284e5
Update conf.py
vi-shruti Oct 28, 2024
3697a05
Update conf.py
vi-shruti Oct 28, 2024
d01c518
Experimenting sphinx-external-toc
vi-shruti Oct 29, 2024
ba26b3f
Update conf.py
vi-shruti Oct 29, 2024
d89a190
Update conf.py
vi-shruti Oct 29, 2024
e458d8f
Added requirements
vi-shruti Oct 29, 2024
3654008
Updated path
vi-shruti Oct 29, 2024
710543c
Update conf.py
vi-shruti Oct 29, 2024
db3cc98
Update conf.py
vi-shruti Oct 29, 2024
3a7cfb2
Update conf.py
vi-shruti Oct 29, 2024
9db223d
Update conf.py
vi-shruti Oct 29, 2024
fd810ca
Merge branch 'google-gemini:main' into main
vi-shruti Nov 4, 2024
aaa72b1
Github Actions
vi-shruti Nov 6, 2024
b323605
Update gh_pages_doc.yaml
vi-shruti Nov 6, 2024
de533e1
Update conf.py
vi-shruti Nov 6, 2024
790b9da
Update conf.py
vi-shruti Nov 6, 2024
d267e5b
Update conf.py
vi-shruti Nov 6, 2024
a0dab2d
Update conf.py
vi-shruti Nov 6, 2024
bda54f8
Update conf.py
vi-shruti Nov 6, 2024
a4ea698
Update conf.py
vi-shruti Nov 6, 2024
af9ba4d
Update conf.py
vi-shruti Nov 6, 2024
3729339
Update conf.py
vi-shruti Nov 6, 2024
4e4ee2e
Update conf.py
vi-shruti Nov 6, 2024
e31b2c7
Update conf.py
vi-shruti Nov 6, 2024
b27e084
Update conf.py
vi-shruti Nov 6, 2024
5d6b9bf
Update conf.py
vi-shruti Nov 6, 2024
77ad635
Update conf.py
vi-shruti Nov 6, 2024
534a0ef
Update conf.py
vi-shruti Nov 6, 2024
1ae6e66
Update conf.py
vi-shruti Nov 6, 2024
c5b6ae3
Update conf.py
vi-shruti Nov 6, 2024
fea5e85
Update conf.py
vi-shruti Nov 6, 2024
f409798
Update conf.py
vi-shruti Nov 6, 2024
3fd0a25
Myst XRef
vi-shruti Nov 6, 2024
22bd52b
Update conf.py
vi-shruti Nov 6, 2024
1454d27
Update conf.py
vi-shruti Nov 6, 2024
d4545dc
Updated conf.py
vi-shruti Nov 6, 2024
cb11760
Create index.md
vi-shruti Nov 6, 2024
2062670
Updated index.md
vi-shruti Nov 6, 2024
87a1ffd
Update conf.py
vi-shruti Nov 6, 2024
2d62030
Update conf.py
vi-shruti Nov 6, 2024
6c8fc2e
Update conf.py
vi-shruti Nov 6, 2024
f628168
Update conf.py
vi-shruti Nov 6, 2024
e726528
Update conf.py
vi-shruti Nov 6, 2024
bab6c39
Update conf.py
vi-shruti Nov 7, 2024
63fbdd1
Update conf.py
vi-shruti Nov 7, 2024
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
45 changes: 45 additions & 0 deletions .github/workflows/gh_pages_doc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Deploy Sphinx documentation to Pages

on:
push:
branches: [main]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Install dependencies
run: |
pip install sphinx myst-parser[linkify] myst_nb

- name: Build the documentation
run: |
cd docs
make html

- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: "docs/_build/html"

pages:
needs: build
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
permissions:
pages: write
id-token: write
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
70 changes: 70 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import re

project = 'Google Generative AI - Python'
copyright = '2024, Google LLC'
author = 'Google LLC'

extensions = [
'sphinx.ext.autosectionlabel',
'sphinx.ext.coverage',
'myst_parser',
'sphinx.ext.viewcode',
'sphinx.ext.githubpages',
]

# autosectionlabel_prefix_document = True

myst_url_schemes = ["http", "https", "mailto"]
myst_enable_extensions = [
"colon_fence",
"deflist",
"fieldlist",
"html_image",
"replacements",
"smartquotes",
"strikethrough",
"tasklist",
"substitution",
"linkify",
]
# https://myst-parser.readthedocs.io/en/latest/syntax/optional.html#syntax-header-anchors
# Controls allowable header anchors in markdown files. Value allows header anchors for h1 - h6
myst_heading_anchors = 6
suppress_warnings = ["myst.xref_missing", "myst.iref_ambiguous"]

source_suffix = {'.md': 'markdown',}
master_doc = 'index' #'api/google/generativeai'

templates_path = ['_templates']
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']

html_theme = 'alabaster'
# html_static_path = ['_static']


def set_relative_links(app, docname, source):
source[0] = source[0].replace(
'../google/generativeai/',
'/api/google/generativeai/'
)

def replace_md_links(app, pagename, templatename, context, doctree):
"""Replaces all .md links with .html in the final HTML output."""
if 'body' in context:
# Pattern to identify and replace <a href="*.md#anchor"> links
pattern = re.compile(r'<a href="([^"]+)\.md(#[^"]*)?">')

# Function to replace matched .md links with .html links
def md_to_html(match):
# Get the base link and optional fragment
base_link = match.group(1)
fragment = match.group(2) or ""
# Replace .md with .html and retain the fragment if present
return f'<a href="/generative-ai-python{base_link}.html{fragment}" class="reference internal">'

# Apply the replacement to all <a> links in the HTML body
context['body'] = pattern.sub(md_to_html, context['body'])

def setup(app):
app.connect('html-page-context', replace_md_links)
app.connect('source-read', set_relative_links)
138 changes: 138 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
description: Google AI Python SDK

<div itemscope itemtype="http://developers.google.com/ReferenceObject">
<meta itemprop="name" content="google.generativeai" />
<meta itemprop="path" content="Stable" />
<meta itemprop="property" content="__version__"/>
<meta itemprop="property" content="annotations"/>
</div>

# Module: google.generativeai

<!-- Insert buttons and diff -->

<table class="tfo-notebook-buttons tfo-api nocontent" align="left">
<td>
<a target="_blank" href="https://github.com/google/generative-ai-python/blob/master/google/generativeai/__init__.py">
<img src="https://www.tensorflow.org/images/GitHub-Mark-32px.png" />
View source on GitHub
</a>
</td>
</table>



Google AI Python SDK



## Setup

```posix-terminal
pip install google-generativeai
```

## GenerativeModel

Use `genai.GenerativeModel` to access the API:

```
import google.generativeai as genai
import os

genai.configure(api_key=os.environ['API_KEY'])

model = genai.GenerativeModel(model_name='gemini-1.5-flash')
response = model.generate_content('Teach me about how an LLM works')

print(response.text)
```

See the [python quickstart](https://ai.google.dev/tutorials/python_quickstart) for more details.

## Modules

[`protos`](../google/generativeai/protos.md) module: This module provides low level access to the ProtoBuffer "Message" classes used by the API.

[`types`](../google/generativeai/types.md) module: A collection of type definitions used throughout the library.

## Classes

[`class ChatSession`](../google/generativeai/ChatSession.md): Contains an ongoing conversation with the model.

[`class GenerationConfig`](../google/generativeai/types/GenerationConfig.md): A simple dataclass used to configure the generation parameters of <a href="../google/generativeai/GenerativeModel.md#generate_content"><code>GenerativeModel.generate_content</code></a>.

[`class GenerativeModel`](../google/generativeai/GenerativeModel.md): The `genai.GenerativeModel` class wraps default parameters for calls to <a href="../google/generativeai/GenerativeModel.md#generate_content"><code>GenerativeModel.generate_content</code></a>, <a href="../google/generativeai/GenerativeModel.md#count_tokens"><code>GenerativeModel.count_tokens</code></a>, and <a href="../google/generativeai/GenerativeModel.md#start_chat"><code>GenerativeModel.start_chat</code></a>.

## Functions

[`chat(...)`](../google/generativeai/chat.md): Calls the API to initiate a chat with a model using provided parameters

[`chat_async(...)`](../google/generativeai/chat_async.md): Calls the API to initiate a chat with a model using provided parameters

[`configure(...)`](../google/generativeai/configure.md): Captures default client configuration.

[`count_message_tokens(...)`](../google/generativeai/count_message_tokens.md): Calls the API to calculate the number of tokens used in the prompt.

[`count_text_tokens(...)`](../google/generativeai/count_text_tokens.md): Calls the API to count the number of tokens in the text prompt.

[`create_tuned_model(...)`](../google/generativeai/create_tuned_model.md): Calls the API to initiate a tuning process that optimizes a model for specific data, returning an operation object to track and manage the tuning progress.

[`delete_file(...)`](../google/generativeai/delete_file.md): Calls the API to permanently delete a specified file using a supported file service.

[`delete_tuned_model(...)`](../google/generativeai/delete_tuned_model.md): Calls the API to delete a specified tuned model

[`embed_content(...)`](../google/generativeai/embed_content.md): Calls the API to create embeddings for content passed in.

[`embed_content_async(...)`](../google/generativeai/embed_content_async.md): Calls the API to create async embeddings for content passed in.

[`generate_embeddings(...)`](../google/generativeai/generate_embeddings.md): Calls the API to create an embedding for the text passed in.

[`generate_text(...)`](../google/generativeai/generate_text.md): Calls the API to generate text based on the provided prompt.

[`get_base_model(...)`](../google/generativeai/get_base_model.md): Calls the API to fetch a base model by name.

[`get_file(...)`](../google/generativeai/get_file.md): Calls the API to retrieve a specified file using a supported file service.

[`get_model(...)`](../google/generativeai/get_model.md): Calls the API to fetch a model by name.

[`get_operation(...)`](../google/generativeai/get_operation.md): Calls the API to get a specific operation

[`get_tuned_model(...)`](../google/generativeai/get_tuned_model.md): Calls the API to fetch a tuned model by name.

[`list_files(...)`](../google/generativeai/list_files.md): Calls the API to list files using a supported file service.

[`list_models(...)`](../google/generativeai/list_models.md): Calls the API to list all available models.

[`list_operations(...)`](../google/generativeai/list_operations.md): Calls the API to list all operations

[`list_tuned_models(...)`](../google/generativeai/list_tuned_models.md): Calls the API to list all tuned models.

[`update_tuned_model(...)`](../google/generativeai/update_tuned_model.md): Calls the API to push updates to a specified tuned model where only certain attributes are updatable.

[`upload_file(...)`](../google/generativeai/upload_file.md): Calls the API to upload a file using a supported file service.



<!-- Tabular view -->
<table class="responsive fixed orange">
<colgroup><col width="214px"><col></colgroup>
<tr><th colspan="2"><h2 class="add-link">Other Members</h2></th></tr>

<tr>
<td>
__version__<a id="__version__"></a>
</td>
<td>
`'0.7.2'`
</td>
</tr><tr>
<td>
annotations<a id="annotations"></a>
</td>
<td>
Instance of `__future__._Feature`
</td>
</tr>
</table>

35 changes: 35 additions & 0 deletions docs/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=.
set BUILDDIR=_build

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.https://www.sphinx-doc.org/
exit /b 1
)

if "%1" == "" goto help

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
Loading