|
113 | 113 | }
|
114 | 114 |
|
115 | 115 |
|
116 |
| -def mock_stream_generate_content( |
| 116 | +def mock_generate_content( |
117 | 117 | self,
|
118 | 118 | request: gapic_prediction_service_types.GenerateContentRequest,
|
119 | 119 | *,
|
@@ -161,56 +161,18 @@ def mock_stream_generate_content(
|
161 | 161 | ),
|
162 | 162 | ],
|
163 | 163 | )
|
164 |
| - yield response |
| 164 | + return response |
165 | 165 |
|
166 | 166 |
|
167 |
| -def mock_generate_content( |
| 167 | +def mock_stream_generate_content( |
168 | 168 | self,
|
169 | 169 | request: gapic_prediction_service_types.GenerateContentRequest,
|
170 | 170 | *,
|
171 | 171 | model: Optional[str] = None,
|
172 | 172 | contents: Optional[MutableSequence[gapic_content_types.Content]] = None,
|
173 | 173 | ) -> Iterable[gapic_prediction_service_types.GenerateContentResponse]:
|
174 |
| - is_continued_chat = len(request.contents) > 1 |
175 |
| - has_tools = bool(request.tools) |
176 |
| - |
177 |
| - if has_tools: |
178 |
| - has_function_response = any( |
179 |
| - "function_response" in content.parts[0] for content in request.contents |
180 |
| - ) |
181 |
| - needs_function_call = not has_function_response |
182 |
| - if needs_function_call: |
183 |
| - response_part_struct = _RESPONSE_FUNCTION_CALL_PART_STRUCT |
184 |
| - else: |
185 |
| - response_part_struct = _RESPONSE_AFTER_FUNCTION_CALL_PART_STRUCT |
186 |
| - elif is_continued_chat: |
187 |
| - response_part_struct = {"text": "Other planets may have different sky color."} |
188 |
| - else: |
189 |
| - response_part_struct = _RESPONSE_TEXT_PART_STRUCT |
190 |
| - |
191 |
| - return gapic_prediction_service_types.GenerateContentResponse( |
192 |
| - candidates=[ |
193 |
| - gapic_content_types.Candidate( |
194 |
| - index=0, |
195 |
| - content=gapic_content_types.Content( |
196 |
| - # Model currently does not identify itself |
197 |
| - # role="model", |
198 |
| - parts=[ |
199 |
| - gapic_content_types.Part(response_part_struct), |
200 |
| - ], |
201 |
| - ), |
202 |
| - finish_reason=gapic_content_types.Candidate.FinishReason.STOP, |
203 |
| - safety_ratings=[ |
204 |
| - gapic_content_types.SafetyRating(rating) |
205 |
| - for rating in _RESPONSE_SAFETY_RATINGS_STRUCT |
206 |
| - ], |
207 |
| - citation_metadata=gapic_content_types.CitationMetadata( |
208 |
| - citations=[ |
209 |
| - gapic_content_types.Citation(_RESPONSE_CITATION_STRUCT), |
210 |
| - ] |
211 |
| - ), |
212 |
| - ), |
213 |
| - ], |
| 174 | + yield mock_generate_content( |
| 175 | + self=self, request=request, model=model, contents=contents |
214 | 176 | )
|
215 | 177 |
|
216 | 178 |
|
|
0 commit comments