community[patch]: YandexGPT Use recent yandexcloud sdk version (#19341)

Fixed inability to work with [yandexcloud
SDK](https://pypi.org/project/yandexcloud/) version higher 0.265.0
This commit is contained in:
Dmitry Tyumentsev 2024-03-26 03:05:57 +03:00 committed by GitHub
parent f1313339ac
commit 08b769d539
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 115 additions and 50 deletions

View File

@ -90,7 +90,7 @@
} }
], ],
"source": [ "source": [
"answer = chat_model(\n", "answer = chat_model.invoke(\n",
" [\n", " [\n",
" SystemMessage(\n", " SystemMessage(\n",
" content=\"You are a helpful assistant that translates English to French.\"\n", " content=\"You are a helpful assistant that translates English to French.\"\n",

View File

@ -96,7 +96,7 @@
"source": [ "source": [
"country = \"Russia\"\n", "country = \"Russia\"\n",
"\n", "\n",
"llm_chain.run(country)" "llm_chain.invoke(country)"
] ]
} }
], ],

View File

@ -127,6 +127,19 @@ def _make_request(
try: try:
import grpc import grpc
from google.protobuf.wrappers_pb2 import DoubleValue, Int64Value from google.protobuf.wrappers_pb2 import DoubleValue, Int64Value
try:
from yandex.cloud.ai.foundation_models.v1.text_common_pb2 import (
CompletionOptions,
Message,
)
from yandex.cloud.ai.foundation_models.v1.text_generation.text_generation_service_pb2 import ( # noqa: E501
CompletionRequest,
)
from yandex.cloud.ai.foundation_models.v1.text_generation.text_generation_service_pb2_grpc import ( # noqa: E501
TextGenerationServiceStub,
)
except ModuleNotFoundError:
from yandex.cloud.ai.foundation_models.v1.foundation_models_pb2 import ( from yandex.cloud.ai.foundation_models.v1.foundation_models_pb2 import (
CompletionOptions, CompletionOptions,
Message, Message,
@ -166,6 +179,20 @@ async def _amake_request(self: ChatYandexGPT, messages: List[BaseMessage]) -> st
import grpc import grpc
from google.protobuf.wrappers_pb2 import DoubleValue, Int64Value from google.protobuf.wrappers_pb2 import DoubleValue, Int64Value
try:
from yandex.cloud.ai.foundation_models.v1.text_common_pb2 import (
CompletionOptions,
Message,
)
from yandex.cloud.ai.foundation_models.v1.text_generation.text_generation_service_pb2 import ( # noqa: E501
CompletionRequest,
CompletionResponse,
)
from yandex.cloud.ai.foundation_models.v1.text_generation.text_generation_service_pb2_grpc import ( # noqa: E501
TextGenerationAsyncServiceStub,
)
except ModuleNotFoundError:
from yandex.cloud.ai.foundation_models.v1.foundation_models_pb2 import ( from yandex.cloud.ai.foundation_models.v1.foundation_models_pb2 import (
CompletionOptions, CompletionOptions,
Message, Message,

View File

@ -80,6 +80,7 @@ _module_lookup = {
"VolcanoEmbeddings": "langchain_community.embeddings.volcengine", "VolcanoEmbeddings": "langchain_community.embeddings.volcengine",
"VoyageEmbeddings": "langchain_community.embeddings.voyageai", "VoyageEmbeddings": "langchain_community.embeddings.voyageai",
"XinferenceEmbeddings": "langchain_community.embeddings.xinference", "XinferenceEmbeddings": "langchain_community.embeddings.xinference",
"YandexGPTEmbeddings": "langchain_community.embeddings.yandex",
} }

View File

@ -149,6 +149,15 @@ def _embed_with_retry(llm: YandexGPTEmbeddings, **kwargs: Any) -> Any:
def _make_request(self: YandexGPTEmbeddings, texts: List[str]): # type: ignore[no-untyped-def] def _make_request(self: YandexGPTEmbeddings, texts: List[str]): # type: ignore[no-untyped-def]
try: try:
import grpc import grpc
try:
from yandex.cloud.ai.foundation_models.v1.embedding.embedding_service_pb2 import ( # noqa: E501
TextEmbeddingRequest,
)
from yandex.cloud.ai.foundation_models.v1.embedding.embedding_service_pb2_grpc import ( # noqa: E501
EmbeddingsServiceStub,
)
except ModuleNotFoundError:
from yandex.cloud.ai.foundation_models.v1.foundation_models_service_pb2 import ( # noqa: E501 from yandex.cloud.ai.foundation_models.v1.foundation_models_service_pb2 import ( # noqa: E501
TextEmbeddingRequest, TextEmbeddingRequest,
) )

View File

@ -186,6 +186,19 @@ def _make_request(
try: try:
import grpc import grpc
from google.protobuf.wrappers_pb2 import DoubleValue, Int64Value from google.protobuf.wrappers_pb2 import DoubleValue, Int64Value
try:
from yandex.cloud.ai.foundation_models.v1.text_common_pb2 import (
CompletionOptions,
Message,
)
from yandex.cloud.ai.foundation_models.v1.text_generation.text_generation_service_pb2 import ( # noqa: E501
CompletionRequest,
)
from yandex.cloud.ai.foundation_models.v1.text_generation.text_generation_service_pb2_grpc import ( # noqa: E501
TextGenerationServiceStub,
)
except ModuleNotFoundError:
from yandex.cloud.ai.foundation_models.v1.foundation_models_pb2 import ( from yandex.cloud.ai.foundation_models.v1.foundation_models_pb2 import (
CompletionOptions, CompletionOptions,
Message, Message,
@ -222,6 +235,20 @@ async def _amake_request(self: YandexGPT, prompt: str) -> str:
import grpc import grpc
from google.protobuf.wrappers_pb2 import DoubleValue, Int64Value from google.protobuf.wrappers_pb2 import DoubleValue, Int64Value
try:
from yandex.cloud.ai.foundation_models.v1.text_common_pb2 import (
CompletionOptions,
Message,
)
from yandex.cloud.ai.foundation_models.v1.text_generation.text_generation_service_pb2 import ( # noqa: E501
CompletionRequest,
CompletionResponse,
)
from yandex.cloud.ai.foundation_models.v1.text_generation.text_generation_service_pb2_grpc import ( # noqa: E501
TextGenerationAsyncServiceStub,
)
except ModuleNotFoundError:
from yandex.cloud.ai.foundation_models.v1.foundation_models_pb2 import ( from yandex.cloud.ai.foundation_models.v1.foundation_models_pb2 import (
CompletionOptions, CompletionOptions,
Message, Message,

View File

@ -65,6 +65,7 @@ EXPECTED_ALL = [
"QuantizedBiEncoderEmbeddings", "QuantizedBiEncoderEmbeddings",
"NeMoEmbeddings", "NeMoEmbeddings",
"SparkLLMTextEmbeddings", "SparkLLMTextEmbeddings",
"YandexGPTEmbeddings",
] ]