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

Make printing less verbose. #340

Merged
merged 4 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 0 additions & 2 deletions google/generativeai/generative_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
from __future__ import annotations

from collections.abc import Iterable
import dataclasses
import textwrap
from typing import Any
from typing import Union
import reprlib

# pylint: disable=bad-continuation, line-too-long
Expand Down
4 changes: 3 additions & 1 deletion google/generativeai/types/generation_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,9 @@ def __str__(self) -> str:
else:
_iterator = f"<{self._iterator.__class__.__name__}>"

as_dict = self.to_dict()
as_dict = type(self._result).to_dict(
self._result, use_integers_for_enums=False, including_default_value_fields=False
)
json_str = json.dumps(as_dict, indent=2)

_result = f"glm.GenerateContentResponse({json_str})"
Expand Down
18 changes: 4 additions & 14 deletions tests/test_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,13 +531,8 @@ def test_repr_for_generate_content_response_from_response(self):
{
"text": "Hello world!"
}
],
"role": ""
},
"finish_reason": 0,
"safety_ratings": [],
"token_count": 0,
"grounding_attributions": []
]
}
}
]
}),
Expand Down Expand Up @@ -567,13 +562,8 @@ def test_repr_for_generate_content_response_from_iterator(self):
{
"text": "a"
}
],
"role": ""
},
"finish_reason": 0,
"safety_ratings": [],
"token_count": 0,
"grounding_attributions": []
]
}
}
]
}),
Expand Down
113 changes: 23 additions & 90 deletions tests/test_generative_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -809,13 +809,8 @@ def test_repr_for_unary_non_streamed_response(self):
{
"text": "world!"
}
],
"role": ""
},
"finish_reason": 0,
"safety_ratings": [],
"token_count": 0,
"grounding_attributions": []
]
}
}
]
}),
Expand Down Expand Up @@ -847,13 +842,8 @@ def test_repr_for_streaming_start_to_finish(self):
{
"text": "first"
}
],
"role": ""
},
"finish_reason": 0,
"safety_ratings": [],
"token_count": 0,
"grounding_attributions": []
]
}
}
]
}),
Expand All @@ -877,28 +867,14 @@ def test_repr_for_streaming_start_to_finish(self):
{
"text": "first second"
}
],
"role": ""
]
},
"index": 0,
"citation_metadata": {
"citation_sources": []
},
"finish_reason": 0,
"safety_ratings": [],
"token_count": 0,
"grounding_attributions": []
"citation_metadata": {}
}
],
"prompt_feedback": {
"block_reason": 0,
"safety_ratings": []
},
"usage_metadata": {
"prompt_token_count": 0,
"candidates_token_count": 0,
"total_token_count": 0
}
"prompt_feedback": {},
"usage_metadata": {}
}),
)"""
)
Expand All @@ -920,28 +896,14 @@ def test_repr_for_streaming_start_to_finish(self):
{
"text": "first second third"
}
],
"role": ""
]
},
"index": 0,
"citation_metadata": {
"citation_sources": []
},
"finish_reason": 0,
"safety_ratings": [],
"token_count": 0,
"grounding_attributions": []
"citation_metadata": {}
}
],
"prompt_feedback": {
"block_reason": 0,
"safety_ratings": []
},
"usage_metadata": {
"prompt_token_count": 0,
"candidates_token_count": 0,
"total_token_count": 0
}
"prompt_feedback": {},
"usage_metadata": {}
}),
)"""
)
Expand Down Expand Up @@ -970,10 +932,8 @@ def test_repr_error_info_for_stream_prompt_feedback_blocked(self):
iterator=<generator>,
result=glm.GenerateContentResponse({
"prompt_feedback": {
"block_reason": 1,
"safety_ratings": []
},
"candidates": []
"block_reason": "SAFETY"
}
}),
),
error=<BlockedPromptException> prompt_feedback {
Expand Down Expand Up @@ -1028,28 +988,14 @@ def no_throw():
{
"text": "123"
}
],
"role": ""
]
},
"index": 0,
"citation_metadata": {
"citation_sources": []
},
"finish_reason": 0,
"safety_ratings": [],
"token_count": 0,
"grounding_attributions": []
"citation_metadata": {}
}
],
"prompt_feedback": {
"block_reason": 0,
"safety_ratings": []
},
"usage_metadata": {
"prompt_token_count": 0,
"candidates_token_count": 0,
"total_token_count": 0
}
"prompt_feedback": {},
"usage_metadata": {}
}),
),
error=<ValueError> """
Expand Down Expand Up @@ -1101,28 +1047,15 @@ def test_repr_error_info_for_chat_streaming_unexpected_stop(self):
{
"text": "abc"
}
],
"role": ""
]
},
"finish_reason": 3,
"finish_reason": "SAFETY",
"index": 0,
"citation_metadata": {
"citation_sources": []
},
"safety_ratings": [],
"token_count": 0,
"grounding_attributions": []
"citation_metadata": {}
}
],
"prompt_feedback": {
"block_reason": 0,
"safety_ratings": []
},
"usage_metadata": {
"prompt_token_count": 0,
"candidates_token_count": 0,
"total_token_count": 0
}
"prompt_feedback": {},
"usage_metadata": {}
}),
),
error=<StopCandidateException> index: 0
Expand Down
Loading