Skip to content

fix list initialization and redundant parentheses #412

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

Merged
merged 10 commits into from
Jul 1, 2024
3 changes: 1 addition & 2 deletions google/generativeai/notebook/sheets_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ def __init__(self, sid: sheets_id.SheetsIdentifier):
def write_outputs(self, outputs: llmfn_outputs.LLMFnOutputsBase) -> None:
# Transpose `outputs` into a list of rows.
outputs_dict = outputs.as_dict()
outputs_rows: list[Sequence[Any]] = []
outputs_rows.append(list(outputs_dict.keys()))
outputs_rows: list[Sequence[Any]] = [list(outputs_dict.keys())]
outputs_rows.extend([list(x) for x in zip(*outputs_dict.values())])

gspread_client.get_client().write_records(
Expand Down
9 changes: 6 additions & 3 deletions samples/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_chat(self):
]
)
response = chat.send_message("I have 2 dogs in my house.")
print(response.text)
print(response.text)
response = chat.send_message("How many paws are in my house?")
print(response.text)
# [END chat]
Expand Down Expand Up @@ -62,11 +62,14 @@ def test_chat_streaming_with_images(self):
model = genai.GenerativeModel("gemini-1.5-flash")
chat = model.start_chat()

response = chat.send_message("Hello, I'm interested in learning about musical instruments. Can I show you one?", stream=True)
response = chat.send_message(
"Hello, I'm interested in learning about musical instruments. Can I show you one?",
stream=True,
)
for chunk in response:
print(chunk.text) # Yes.
print("_" * 80)

organ = genai.upload_file(media / "organ.jpg")
response = chat.send_message(
["What family of intruments does this instrument belong to?", organ], stream=True
Expand Down
2 changes: 1 addition & 1 deletion tests/notebook/test_cmd_line_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def _set_output_sink(text_result: str, sink: llmfn_outputs.LLMFnOutputsSink) ->
llmfn_output_row.LLMFnOutputRow(
data={
llmfn_outputs.ColumnNames.RESULT_NUM: 0,
llmfn_outputs.ColumnNames.TEXT_RESULT: (text_result),
llmfn_outputs.ColumnNames.TEXT_RESULT: text_result,
},
result_type=str,
)
Expand Down
2 changes: 1 addition & 1 deletion tests/notebook/test_sheets_sanitize_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_domain_must_be_docs_google_com(self):
"""Domain must be docs.google.com."""
with self.assertRaisesRegex(
ValueError,
('Domain for Sheets url must be "docs.google.com", got' ' "sheets.google.com"'),
'Domain for Sheets url must be "docs.google.com", got' ' "sheets.google.com"',
):
sanitize_sheets_url("https://sheets.google.com")

Expand Down
6 changes: 3 additions & 3 deletions tests/test_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def test_join_contents(self):
result = generation_types._join_contents(contents)
expected = {
"parts": [
{"text": ("Tell me a story about a magic backpack that looks like" " this: ")},
{"text": "Tell me a story about a magic backpack that looks like" " this: "},
{"inline_data": {"mime_type": "image/png", "data": "REFUQSE="}},
],
"role": "assistant",
Expand Down Expand Up @@ -254,7 +254,7 @@ def test_join_candidates(self):
expected = {
"content": {
"parts": [
{"text": ("Tell me a story about a magic backpack that looks like" " this: ")},
{"text": "Tell me a story about a magic backpack that looks like" " this: "},
{"text": ""},
],
"role": "assistant",
Expand Down Expand Up @@ -438,7 +438,7 @@ def test_join_prompt_feedbacks(self):
{
"content": {
"parts": [
{"text": ("Tell me a story about a magic backpack" " that looks like this: ")},
{"text": "Tell me a story about a magic backpack" " that looks like this: "},
{
"inline_data": {
"mime_type": "image/png",
Expand Down
Loading