1
1
from __future__ import annotations
2
2
3
3
import queue
4
- from typing import Any , Iterator , Optional , Sequence
4
+ from typing import Any , Dict , Iterator , List , Optional , Sequence
5
5
6
6
from langchain_core .callbacks .manager import CallbackManagerForLLMRun
7
7
from langchain_core .language_models .llms import LLM
@@ -102,7 +102,7 @@ def from_model_path(
102
102
def _call (
103
103
self ,
104
104
prompt : str ,
105
- stop : Optional [list [str ]] = None ,
105
+ stop : Optional [List [str ]] = None ,
106
106
run_manager : Optional [CallbackManagerForLLMRun ] = None ,
107
107
** kwargs : Any ,
108
108
) -> str :
@@ -128,7 +128,7 @@ def _call(
128
128
def _stream (
129
129
self ,
130
130
prompt : str ,
131
- stop : Optional [list [str ]] = None ,
131
+ stop : Optional [List [str ]] = None ,
132
132
run_manager : Optional [CallbackManagerForLLMRun ] = None ,
133
133
** kwargs : Any ,
134
134
) -> Iterator [GenerationChunk ]:
@@ -239,8 +239,8 @@ def __init__(self, **kwargs: Any):
239
239
240
240
def _generate (
241
241
self ,
242
- messages : list [BaseMessage ],
243
- stop : Optional [list [str ]] = None ,
242
+ messages : List [BaseMessage ],
243
+ stop : Optional [List [str ]] = None ,
244
244
run_manager : Optional [CallbackManagerForLLMRun ] = None ,
245
245
** kwargs : Any ,
246
246
) -> ChatResult :
@@ -250,8 +250,8 @@ def _generate(
250
250
251
251
def _stream (
252
252
self ,
253
- messages : list [BaseMessage ],
254
- stop : Optional [list [str ]] = None ,
253
+ messages : List [BaseMessage ],
254
+ stop : Optional [List [str ]] = None ,
255
255
run_manager : Optional [CallbackManagerForLLMRun ] = None ,
256
256
** kwargs : Any ,
257
257
) -> Iterator [ChatGenerationChunk ]:
@@ -266,7 +266,7 @@ def _stream(
266
266
267
267
def _to_chat_prompt (
268
268
self ,
269
- messages : list [BaseMessage ],
269
+ messages : List [BaseMessage ],
270
270
) -> str :
271
271
"""Convert a list of messages into a prompt format expected by wrapped LLM."""
272
272
try :
@@ -472,22 +472,22 @@ def run_mean_pooling(model_output: Any, attention_mask: Any) -> Any:
472
472
473
473
model_config = ConfigDict (extra = "forbid" , protected_namespaces = ())
474
474
475
- def embed_documents (self , texts : list [str ]) -> list [ list [float ]]:
475
+ def embed_documents (self , texts : List [str ]) -> List [ List [float ]]:
476
476
"""Compute doc embeddings using a HuggingFace transformer model.
477
477
478
478
Args:
479
479
texts: The list of texts to embed.
480
480
481
481
Returns:
482
- list of embeddings, one for each text.
482
+ List of embeddings, one for each text.
483
483
"""
484
484
485
485
texts = list (map (lambda x : x .replace ("\n " , " " ), texts ))
486
486
embeddings = self .encode (texts , show_progress_bar = self .show_progress , ** self .encode_kwargs )
487
487
488
488
return embeddings
489
489
490
- def embed_query (self , text : str ) -> list [float ]:
490
+ def embed_query (self , text : str ) -> List [float ]:
491
491
"""Compute query embeddings using a HuggingFace transformer model.
492
492
493
493
Args:
@@ -529,20 +529,20 @@ def __init__(self, **kwargs: Any):
529
529
if "-zh" in self .model_path :
530
530
self .query_instruction = DEFAULT_QUERY_BGE_INSTRUCTION_ZH
531
531
532
- def embed_documents (self , texts : list [str ]) -> list [ list [float ]]:
532
+ def embed_documents (self , texts : List [str ]) -> List [ List [float ]]:
533
533
"""Compute doc embeddings using a HuggingFace transformer model.
534
534
535
535
Args:
536
536
texts: The list of texts to embed.
537
537
538
538
Returns:
539
- list of embeddings, one for each text.
539
+ List of embeddings, one for each text.
540
540
"""
541
541
texts = [self .embed_instruction + t .replace ("\n " , " " ) for t in texts ]
542
542
embeddings = self .encode (texts , ** self .encode_kwargs )
543
543
return embeddings
544
544
545
- def embed_query (self , text : str ) -> list [float ]:
545
+ def embed_query (self , text : str ) -> List [float ]:
546
546
"""Compute query embeddings using a HuggingFace transformer model.
547
547
548
548
Args:
0 commit comments