Skip to content

Commit

Permalink
Annotate parameter types
Browse files Browse the repository at this point in the history
  • Loading branch information
Amnah199 committed Aug 27, 2024
1 parent 1c5d72e commit ad55d37
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from typing import Any, Callable, Dict, List, Optional, Union
from typing import Any, Callable, Dict, Iterable, List, Optional, Union

from haystack.core.component import component
from haystack.core.serialization import default_from_dict, default_to_dict
Expand All @@ -11,6 +11,7 @@
from vertexai.preview.generative_models import (
Content,
GenerationConfig,
GenerationResponse,
GenerativeModel,
HarmBlockThreshold,
HarmCategory,
Expand Down Expand Up @@ -220,11 +221,11 @@ def run(
stream=streaming_callback is not None,
)

replies = self.get_stream_response(res, streaming_callback) if streaming_callback else self.get_response(res)
replies = self._get_stream_response(res, streaming_callback) if streaming_callback else self._get_response(res)

return {"replies": replies}

def get_response(self, response_body) -> List[ChatMessage]:
def _get_response(self, response_body: GenerationResponse) -> List[ChatMessage]:
"""
Extracts the responses from the Vertex AI response.
Expand All @@ -246,7 +247,9 @@ def get_response(self, response_body) -> List[ChatMessage]:
)
return replies

def get_stream_response(self, stream, streaming_callback: Callable[[StreamingChunk], None]) -> List[ChatMessage]:
def _get_stream_response(
self, stream: Iterable[GenerationResponse], streaming_callback: Callable[[StreamingChunk], None]
) -> List[ChatMessage]:
"""
Extracts the responses from the Vertex AI streaming response.
Expand Down

0 comments on commit ad55d37

Please sign in to comment.