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).
pull/20602/head
Dmitry Tyumentsev 1 month ago committed by GitHub
parent e5f5d9ff56
commit f111efeb6e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -3,7 +3,7 @@ from __future__ import annotations
import logging
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.pydantic_v1 import BaseModel, Field, SecretStr, root_validator
@ -65,6 +65,10 @@ class YandexGPTEmbeddings(BaseModel, Embeddings):
"""Maximum number of retries to make when generating."""
sleep_interval: float = 0.0
"""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:
"""Configuration for this pydantic object."""
@ -110,6 +114,13 @@ class YandexGPTEmbeddings(BaseModel, Embeddings):
values[
"model_uri"
] = 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
def embed_documents(self, texts: List[str]) -> List[List[float]]:

@ -54,6 +54,9 @@ class _BaseYandexGPT(Serializable):
"""Maximum number of retries to make when generating."""
sleep_interval: float = 1.0
"""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
@property
@ -104,6 +107,13 @@ class _BaseYandexGPT(Serializable):
values[
"model_uri"
] = 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

Loading…
Cancel
Save