vertexai[patch]: ChatVertexAI.generate, stream, bind_tools#166
Merged
Conversation
Contributor
Erick Friis (efriis)
left a comment
There was a problem hiding this comment.
big fan of the gemini/non gemini split
Contributor
Author
|
note: tests/integration_tests/test_chat_models.py::test_chat_vertexai_gemini_function_calling_with_multiple_parts fails non-deterministically |
| tools: Sequence[Union[Type[BaseModel], Callable, BaseTool]], | ||
| tool_config: Optional[Dict[str, Any]] = None, | ||
| tools: Sequence[Union[_FunctionDeclarationLike, VertexTool]], | ||
| tool_config: Optional[_ToolConfigDict] = None, |
Collaborator
There was a problem hiding this comment.
nits: should we add to the docstring an example how to contsruct _ToolConfigDict and _ToolChoiceType?
so that people don't need to read the source code.
Leonid Kuligin (lkuligin)
approved these changes
Apr 19, 2024
| except (ValueError, IndexError): | ||
| return False | ||
|
|
||
| def _generate( |
Contributor
There was a problem hiding this comment.
+1 for splitting gemini vs non-gemini.
WDYT if we make this method to only select which function to run, and move gemini implementation to _generate_gemini (and obviously in other methods) like this:
def _generate(
self,
messages: List[BaseMessage],
stop: Optional[List[str]] = None,
run_manager: Optional[CallbackManagerForLLMRun] = None,
stream: Optional[bool] = None,
**kwargs: Any,
) -> ChatResult:
if stream is True or (stream is None and self.streaming):
stream_iter = self._stream(
messages, stop=stop, run_manager=run_manager, **kwargs
)
return generate_from_stream(stream_iter)
if not self._is_gemini_model:
return self._generate_non_gemini(messages, stop=stop, **kwargs)
return self._generate_gemini(messages, stop=stop, **kwargs)
def _generate_gemini(
self,
messages: List[BaseMessage],
stop: Optional[List[str]] = None,
**kwargs: Any,
):
client, contents = self._gemini_client_and_contents(messages)
params = self._gemini_params(stop=stop, **kwargs)
with telemetry.tool_context_manager(self._user_agent):
response = client.generate_content(contents, **params)
return self._gemini_response_to_chat_result(response)
def _generate_non_gemini(
self,
messages: List[BaseMessage],
stop: Optional[List[str]] = None,
**kwargs: Any,
) -> ChatResult:
...That would make testing a little bit cleaner.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.