Skip to content

Commit 06b968e

Browse files
authored
Docs (#9)
* Add view source links for the generated docs. b/281617372 * remove stray oneof and code-block tags (b/281615596) * Include generativelanguage_{version} in docs * Minor doc fixes
1 parent cc7fe29 commit 06b968e

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

docs/build_docs.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import os
2424
import pathlib
25+
import re
2526
import textwrap
2627

2728
from absl import app
@@ -36,8 +37,6 @@
3637

3738
import yaml
3839

39-
# del google.ai.generativelanguage_v1beta2
40-
4140
google.ai.generativelanguage.__doc__ = """\
4241
This package, `google.ai.generativelanguage`, is a low-level auto-generated client library for the PaLM API.
4342
@@ -132,13 +131,15 @@ def drop_staticmethods(self, parent, children):
132131
yield name, value
133132

134133
def __call__(self, path, parent, children):
135-
if "generativelanguage" in path or "generativeai" in path:
134+
if (
135+
any("generativelanguage" in part for part in path)
136+
or "generativeai" in path):
136137
children = self.filter_base_dirs(path, parent, children)
137138
children = public_api.explicit_package_contents_filter(
138139
path, parent, children
139140
)
140141

141-
if "generativelanguage" in path:
142+
if any("generativelanguage" in part for part in path):
142143
if "ServiceClient" in path[-1]:
143144
children = list(self.drop_staticmethods(parent, children))
144145

@@ -154,7 +155,7 @@ def make_default_filters(self):
154155
public_api.add_proto_fields,
155156
public_api.filter_builtin_modules,
156157
public_api.filter_private_symbols,
157-
MyFilter(self._base_dir), # public_api.FilterBaseDirs(self._base_dir),
158+
MyFilter(self._base_dir), # Replaces: public_api.FilterBaseDirs(self._base_dir),
158159
public_api.FilterPrivateMap(self._private_map),
159160
public_api.filter_doc_controls_skip,
160161
public_api.ignore_typing,
@@ -182,12 +183,10 @@ def gen_api_docs():
182183
pathlib.Path(google.generativeai.__file__).parent,
183184
pathlib.Path(google.ai.generativelanguage.__file__).parent.parent,
184185
),
185-
code_url_prefix=(None, None),
186+
code_url_prefix=('https://github.com/google/generative-ai-python/blob/master/google/generativeai',
187+
'https://github.com/googleapis/google-cloud-python/tree/main/packages/google-ai-generativelanguage/google/ai'),
186188
search_hints=_SEARCH_HINTS.value,
187189
site_path=_SITE_PATH.value,
188-
# This callback ensures that docs are only generated for objects that
189-
# are explicitly imported in your __init__.py files. There are other
190-
# options but this is a good starting point.
191190
callbacks=[],
192191
)
193192

@@ -213,6 +212,16 @@ def gen_api_docs():
213212
redirects["redirects"].insert(0, {"from": "/api/python", "to": "/api/"})
214213
redirects_path.write_text(yaml.dump(redirects))
215214

215+
# clear `oneof` junk from proto pages
216+
for fpath in out_path.rglob('*.md'):
217+
old_content = fpath.read_text()
218+
new_content = old_content
219+
new_content = re.sub(r'\.\. _oneof:.*?\n', '', new_content)
220+
new_content = re.sub(r'`oneof`_.*?\n', '', new_content)
221+
new_content = re.sub(r'\.\. code-block:: python.*?\n', '', new_content)
222+
if new_content != old_content:
223+
fpath.write_text(new_content)
224+
216225
print("Output docs to: ", _OUTPUT_DIR.value)
217226

218227

google/generativeai/types/discuss_types.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class ChatResponse(abc.ABC):
102102
"""A chat response from the model.
103103
104104
* Use `response.last` (settable) for easy access to the text of the last response.
105-
(`messages[0]['content']`)
105+
(`messages[-1]['content']`)
106106
* Use `response.messages` to access the message history (including `.last`).
107107
* Use `response.candidates` to access all the responses generated by the model.
108108
@@ -112,7 +112,7 @@ class ChatResponse(abc.ABC):
112112
```
113113
import google.generativeai as genai
114114
115-
genai.configure(api_key=os.environ['API_KEY'])
115+
genai.configure(api_key=os.environ['GOOGLE_API_KEY'])
116116
117117
response = genai.chat(messages=["Hello."])
118118
print(response.last) # 'Hello! What can I help you with?'
@@ -160,9 +160,9 @@ class ChatResponse(abc.ABC):
160160
temperature: Optional[float]
161161
candidate_count: Optional[int]
162162
candidates: List[MessageDict]
163+
filters: List[safety_types.ContentFilterDict]
163164
top_p: Optional[float] = None
164165
top_k: Optional[float] = None
165-
filters: List[safety_types.ContentFilterDict]
166166

167167
@property
168168
@abc.abstractmethod
@@ -194,4 +194,5 @@ def reply(self, message: MessageOptions) -> "ChatResponse":
194194

195195

196196
class AuthorError(Exception):
197+
"""Raised by the `chat` (or `reply`) functions when the author list can't be normalized."""
197198
pass

google/generativeai/types/text_types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ class Completion(abc.ABC):
3939
Attributes:
4040
candidates: A list of candidate text completions generated by the model.
4141
result: The output of the first candidate,
42-
filters: Indicates the reasons why content may have been blocked
43-
Either Unspecified, Safety, or Other. See `types.ContentFilter`.
42+
filters: Indicates the reasons why content may have been blocked.
43+
See `types.BlockedReason`.
4444
safety_feedback: Indicates which safety settings blocked content in this result.
4545
"""
4646

0 commit comments

Comments
 (0)