Skip to content

Commit 1adde2c

Browse files
committed
restore typehints in rag
1 parent 37c3cc1 commit 1adde2c

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

notebooks/llm-rag-langchain/ov_langchain_helper.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
import queue
4-
from typing import Any, Iterator, Optional, Sequence
4+
from typing import Any, Dict, Iterator, List, Optional, Sequence
55

66
from langchain_core.callbacks.manager import CallbackManagerForLLMRun
77
from langchain_core.language_models.llms import LLM
@@ -102,7 +102,7 @@ def from_model_path(
102102
def _call(
103103
self,
104104
prompt: str,
105-
stop: Optional[list[str]] = None,
105+
stop: Optional[List[str]] = None,
106106
run_manager: Optional[CallbackManagerForLLMRun] = None,
107107
**kwargs: Any,
108108
) -> str:
@@ -128,7 +128,7 @@ def _call(
128128
def _stream(
129129
self,
130130
prompt: str,
131-
stop: Optional[list[str]] = None,
131+
stop: Optional[List[str]] = None,
132132
run_manager: Optional[CallbackManagerForLLMRun] = None,
133133
**kwargs: Any,
134134
) -> Iterator[GenerationChunk]:
@@ -239,8 +239,8 @@ def __init__(self, **kwargs: Any):
239239

240240
def _generate(
241241
self,
242-
messages: list[BaseMessage],
243-
stop: Optional[list[str]] = None,
242+
messages: List[BaseMessage],
243+
stop: Optional[List[str]] = None,
244244
run_manager: Optional[CallbackManagerForLLMRun] = None,
245245
**kwargs: Any,
246246
) -> ChatResult:
@@ -250,8 +250,8 @@ def _generate(
250250

251251
def _stream(
252252
self,
253-
messages: list[BaseMessage],
254-
stop: Optional[list[str]] = None,
253+
messages: List[BaseMessage],
254+
stop: Optional[List[str]] = None,
255255
run_manager: Optional[CallbackManagerForLLMRun] = None,
256256
**kwargs: Any,
257257
) -> Iterator[ChatGenerationChunk]:
@@ -266,7 +266,7 @@ def _stream(
266266

267267
def _to_chat_prompt(
268268
self,
269-
messages: list[BaseMessage],
269+
messages: List[BaseMessage],
270270
) -> str:
271271
"""Convert a list of messages into a prompt format expected by wrapped LLM."""
272272
try:
@@ -472,22 +472,22 @@ def run_mean_pooling(model_output: Any, attention_mask: Any) -> Any:
472472

473473
model_config = ConfigDict(extra="forbid", protected_namespaces=())
474474

475-
def embed_documents(self, texts: list[str]) -> list[list[float]]:
475+
def embed_documents(self, texts: List[str]) -> List[List[float]]:
476476
"""Compute doc embeddings using a HuggingFace transformer model.
477477
478478
Args:
479479
texts: The list of texts to embed.
480480
481481
Returns:
482-
list of embeddings, one for each text.
482+
List of embeddings, one for each text.
483483
"""
484484

485485
texts = list(map(lambda x: x.replace("\n", " "), texts))
486486
embeddings = self.encode(texts, show_progress_bar=self.show_progress, **self.encode_kwargs)
487487

488488
return embeddings
489489

490-
def embed_query(self, text: str) -> list[float]:
490+
def embed_query(self, text: str) -> List[float]:
491491
"""Compute query embeddings using a HuggingFace transformer model.
492492
493493
Args:
@@ -529,20 +529,20 @@ def __init__(self, **kwargs: Any):
529529
if "-zh" in self.model_path:
530530
self.query_instruction = DEFAULT_QUERY_BGE_INSTRUCTION_ZH
531531

532-
def embed_documents(self, texts: list[str]) -> list[list[float]]:
532+
def embed_documents(self, texts: List[str]) -> List[List[float]]:
533533
"""Compute doc embeddings using a HuggingFace transformer model.
534534
535535
Args:
536536
texts: The list of texts to embed.
537537
538538
Returns:
539-
list of embeddings, one for each text.
539+
List of embeddings, one for each text.
540540
"""
541541
texts = [self.embed_instruction + t.replace("\n", " ") for t in texts]
542542
embeddings = self.encode(texts, **self.encode_kwargs)
543543
return embeddings
544544

545-
def embed_query(self, text: str) -> list[float]:
545+
def embed_query(self, text: str) -> List[float]:
546546
"""Compute query embeddings using a HuggingFace transformer model.
547547
548548
Args:

0 commit comments

Comments
 (0)