community[patch]: YandexGPT API add ability to disable request logging (#20670)

Closes (#20622)

Added the ability to [disable logging of requests to
YandexGPT](https://yandex.cloud/en/docs/foundation-models/operations/yandexgpt/disable-logging).
This commit is contained in:
Dmitry Tyumentsev 2024-04-20 04:40:37 +03:00 committed by GitHub
parent e5f5d9ff56
commit f111efeb6e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 1 deletions

View File

@ -3,7 +3,7 @@ from __future__ import annotations
import logging import logging
import time import time
from typing import Any, Callable, Dict, List from typing import Any, Callable, Dict, List, Sequence
from langchain_core.embeddings import Embeddings from langchain_core.embeddings import Embeddings
from langchain_core.pydantic_v1 import BaseModel, Field, SecretStr, root_validator from langchain_core.pydantic_v1 import BaseModel, Field, SecretStr, root_validator
@ -65,6 +65,10 @@ class YandexGPTEmbeddings(BaseModel, Embeddings):
"""Maximum number of retries to make when generating.""" """Maximum number of retries to make when generating."""
sleep_interval: float = 0.0 sleep_interval: float = 0.0
"""Delay between API requests""" """Delay between API requests"""
disable_request_logging: bool = False
"""YandexGPT API logs all request data by default.
If you provide personal data, confidential information, disable logging."""
_grpc_metadata: Sequence
class Config: class Config:
"""Configuration for this pydantic object.""" """Configuration for this pydantic object."""
@ -110,6 +114,13 @@ class YandexGPTEmbeddings(BaseModel, Embeddings):
values[ values[
"model_uri" "model_uri"
] = f"emb://{values['folder_id']}/{values['model_name']}/{values['model_version']}" # noqa: E501 ] = f"emb://{values['folder_id']}/{values['model_name']}/{values['model_version']}" # noqa: E501
if values["disable_request_logging"]:
values["_grpc_metadata"].append(
(
"x-data-logging-enabled",
"false",
)
)
return values return values
def embed_documents(self, texts: List[str]) -> List[List[float]]: def embed_documents(self, texts: List[str]) -> List[List[float]]:

View File

@ -54,6 +54,9 @@ class _BaseYandexGPT(Serializable):
"""Maximum number of retries to make when generating.""" """Maximum number of retries to make when generating."""
sleep_interval: float = 1.0 sleep_interval: float = 1.0
"""Delay between API requests""" """Delay between API requests"""
disable_request_logging: bool = False
"""YandexGPT API logs all request data by default.
If you provide personal data, confidential information, disable logging."""
_grpc_metadata: Sequence _grpc_metadata: Sequence
@property @property
@ -104,6 +107,13 @@ class _BaseYandexGPT(Serializable):
values[ values[
"model_uri" "model_uri"
] = f"gpt://{values['folder_id']}/{values['model_name']}/{values['model_version']}" ] = f"gpt://{values['folder_id']}/{values['model_name']}/{values['model_version']}"
if values["disable_request_logging"]:
values["_grpc_metadata"].append(
(
"x-data-logging-enabled",
"false",
)
)
return values return values