langchain-b12 0.1.5__py3-none-any.whl → 0.1.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- langchain_b12/genai/embeddings.py +13 -12
- langchain_b12/genai/genai.py +7 -1
- {langchain_b12-0.1.5.dist-info → langchain_b12-0.1.7.dist-info}/METADATA +1 -1
- langchain_b12-0.1.7.dist-info/RECORD +9 -0
- langchain_b12-0.1.5.dist-info/RECORD +0 -9
- {langchain_b12-0.1.5.dist-info → langchain_b12-0.1.7.dist-info}/WHEEL +0 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import os
|
|
2
2
|
|
|
3
3
|
from google.genai import Client
|
|
4
|
+
from google.genai.types import EmbedContentConfigOrDict
|
|
4
5
|
from google.oauth2 import service_account
|
|
5
6
|
from langchain_core.embeddings import Embeddings
|
|
6
7
|
from pydantic import BaseModel, ConfigDict, Field
|
|
@@ -19,6 +20,7 @@ class GenAIEmbeddings(Embeddings, BaseModel):
|
|
|
19
20
|
),
|
|
20
21
|
exclude=True,
|
|
21
22
|
)
|
|
23
|
+
embed_content_config: EmbedContentConfigOrDict | None = Field(default=None)
|
|
22
24
|
model_config = ConfigDict(
|
|
23
25
|
arbitrary_types_allowed=True,
|
|
24
26
|
)
|
|
@@ -33,19 +35,17 @@ class GenAIEmbeddings(Embeddings, BaseModel):
|
|
|
33
35
|
list[list[float]]: The embedding vectors.
|
|
34
36
|
"""
|
|
35
37
|
embeddings = []
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
response = self.client.models.embed_content(
|
|
39
|
+
model=self.model_name,
|
|
40
|
+
contents=texts,
|
|
41
|
+
config=self.embed_content_config,
|
|
42
|
+
)
|
|
43
|
+
assert response.embeddings is not None, "No embeddings found in the response."
|
|
44
|
+
for embedding in response.embeddings:
|
|
41
45
|
assert (
|
|
42
|
-
|
|
43
|
-
), "No
|
|
44
|
-
|
|
45
|
-
assert (
|
|
46
|
-
embedding.values is not None
|
|
47
|
-
), "No embedding values found in the response."
|
|
48
|
-
embeddings.append(embedding.values)
|
|
46
|
+
embedding.values is not None
|
|
47
|
+
), "No embedding values found in the response."
|
|
48
|
+
embeddings.append(embedding.values)
|
|
49
49
|
assert len(embeddings) == len(
|
|
50
50
|
texts
|
|
51
51
|
), "The number of embeddings does not match the number of texts."
|
|
@@ -75,6 +75,7 @@ class GenAIEmbeddings(Embeddings, BaseModel):
|
|
|
75
75
|
response = await self.client.aio.models.embed_content(
|
|
76
76
|
model=self.model_name,
|
|
77
77
|
contents=texts,
|
|
78
|
+
config=self.embed_content_config,
|
|
78
79
|
)
|
|
79
80
|
assert response.embeddings is not None, "No embeddings found in the response."
|
|
80
81
|
for embedding in response.embeddings:
|
langchain_b12/genai/genai.py
CHANGED
|
@@ -408,12 +408,18 @@ class ChatGenAI(BaseChatModel):
|
|
|
408
408
|
"finish_reason": top_candidate.finish_reason,
|
|
409
409
|
"finish_message": top_candidate.finish_message,
|
|
410
410
|
}
|
|
411
|
-
|
|
411
|
+
try:
|
|
412
|
+
message = parse_response_candidate(top_candidate)
|
|
413
|
+
except Exception as e:
|
|
414
|
+
raise ValueError(
|
|
415
|
+
f"Failed to parse model response: {top_candidate.finish_message}"
|
|
416
|
+
) from e
|
|
412
417
|
if lc_usage:
|
|
413
418
|
message.usage_metadata = lc_usage
|
|
414
419
|
# add model name if final chunk
|
|
415
420
|
if top_candidate.finish_reason is not None:
|
|
416
421
|
message.response_metadata["model_name"] = self.model_name
|
|
422
|
+
message.response_metadata["tags"] = self.tags or []
|
|
417
423
|
|
|
418
424
|
return (
|
|
419
425
|
ChatGenerationChunk(
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
langchain_b12/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
langchain_b12/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
+
langchain_b12/citations/citations.py,sha256=ZQvYayjQXIUaRosJ0qwL3Nc7kC8sBzmaIkE-BOslaVI,12261
|
|
4
|
+
langchain_b12/genai/embeddings.py,sha256=h0Z-5PltDW9q79AjSrLemsz-_QKMB-043XXDvYSRQds,3483
|
|
5
|
+
langchain_b12/genai/genai.py,sha256=Nsbwe0nlMW2p5bDtKRunDzamRcWM62zHqUNDBlbNFSg,16936
|
|
6
|
+
langchain_b12/genai/genai_utils.py,sha256=tA6UiJURK25-11vtaX4768UV47jDCYwVKIIWydD4Egw,10736
|
|
7
|
+
langchain_b12-0.1.7.dist-info/METADATA,sha256=_wBqxchZ-bO6Ol5cw2IbRLgB0BgF8fa_-XqjlKLsvVU,1204
|
|
8
|
+
langchain_b12-0.1.7.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
9
|
+
langchain_b12-0.1.7.dist-info/RECORD,,
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
langchain_b12/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
langchain_b12/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
-
langchain_b12/citations/citations.py,sha256=ZQvYayjQXIUaRosJ0qwL3Nc7kC8sBzmaIkE-BOslaVI,12261
|
|
4
|
-
langchain_b12/genai/embeddings.py,sha256=od2bVIgt7v9aNAHG0PVypVF1H_XgHto2nTd8vwfvyN8,3355
|
|
5
|
-
langchain_b12/genai/genai.py,sha256=7X7nDt76Icc5woV5b7FX_uza9YgFpFp1_PcYtXPriqE,16667
|
|
6
|
-
langchain_b12/genai/genai_utils.py,sha256=tA6UiJURK25-11vtaX4768UV47jDCYwVKIIWydD4Egw,10736
|
|
7
|
-
langchain_b12-0.1.5.dist-info/METADATA,sha256=unv3NxdFU_VrlPmIuTmDB2dHRi9go44B-q83kQgLUqI,1204
|
|
8
|
-
langchain_b12-0.1.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
9
|
-
langchain_b12-0.1.5.dist-info/RECORD,,
|
|
File without changes
|