Skip to content

Commit

Permalink
Merge pull request #21 from ai-forever/feature/ssl_support
Browse files Browse the repository at this point in the history
refactor: Adds ssl context support for gigachat
  • Loading branch information
Rai220 authored Jan 15, 2025
2 parents c2dc5bb + 4fd4f51 commit 6676b2b
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 16 deletions.
7 changes: 7 additions & 0 deletions libs/gigachat/langchain_gigachat/chat_models/base_gigachat.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import logging
import ssl
from functools import cached_property
from typing import TYPE_CHECKING, Any, Dict, List, Literal, Optional

Expand Down Expand Up @@ -41,6 +42,11 @@ class _BaseGigaChat(Serializable):
verify_ssl_certs: Optional[bool] = None
""" Check certificates for all requests """

ssl_context: Optional[ssl.SSLContext] = None

class Config:
arbitrary_types_allowed = True

ca_bundle_file: Optional[str] = None
cert_file: Optional[str] = None
key_file: Optional[str] = None
Expand Down Expand Up @@ -103,6 +109,7 @@ def _client(self) -> gigachat.GigaChat:
user=self.user,
password=self.password,
timeout=self.timeout,
ssl_context=self.ssl_context,
verify_ssl_certs=self.verify_ssl_certs,
ca_bundle_file=self.ca_bundle_file,
cert_file=self.cert_file,
Expand Down
7 changes: 7 additions & 0 deletions libs/gigachat/langchain_gigachat/embeddings/gigachat.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import logging
import ssl
from functools import cached_property
from typing import Any, Dict, List, Optional

Expand Down Expand Up @@ -55,6 +56,11 @@ class GigaChatEmbeddings(BaseModel, Embeddings):
verify_ssl_certs: Optional[bool] = None
""" Check certificates for all requests """

ssl_context: Optional[ssl.SSLContext] = None

class Config:
arbitrary_types_allowed = True

ca_bundle_file: Optional[str] = None
cert_file: Optional[str] = None
key_file: Optional[str] = None
Expand Down Expand Up @@ -82,6 +88,7 @@ def _client(self) -> Any:
user=self.user,
password=self.password,
timeout=self.timeout,
ssl_context=self.ssl_context,
verify_ssl_certs=self.verify_ssl_certs,
ca_bundle_file=self.ca_bundle_file,
cert_file=self.cert_file,
Expand Down
2 changes: 1 addition & 1 deletion libs/gigachat/langchain_gigachat/tools/giga_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def from_function(
args_schema: Optional[type[BaseModel]] = None,
infer_schema: bool = True,
return_schema: Optional[Type[BaseModel]] = None,
few_shot_examples: Optional[List[Dict[str, Any]]] = None,
few_shot_examples: FewShotExamples = None,
*,
response_format: Literal["content", "content_and_artifact"] = "content",
parse_docstring: bool = False,
Expand Down
14 changes: 7 additions & 7 deletions libs/gigachat/langchain_gigachat/utils/function_calling.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,13 +323,13 @@ def format_tool_to_gigachat_function(tool: BaseTool) -> GigaFunctionDescription:
else:
return_schema = None

return {
"name": tool.name,
"description": tool.description,
"parameters": {"properties": {}, "type": "object"},
"few_shot_examples": few_shot_examples,
"return_parameters": return_schema,
}
return GigaFunctionDescription(
name=tool.name,
description=tool.description,
parameters={"properties": {}, "type": "object"},
few_shot_examples=few_shot_examples,
return_parameters=return_schema,
)


def convert_pydantic_to_gigachat_function(
Expand Down
12 changes: 6 additions & 6 deletions libs/gigachat/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions libs/gigachat/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "langchain-gigachat"
version = "0.3.2"
version = "0.3.3"
description = "An integration package connecting GigaChat and LangChain"
authors = []
readme = "README.md"
Expand All @@ -13,7 +13,7 @@ license = "MIT"
[tool.poetry.dependencies]
python = ">=3.9,<4.0"
langchain-core = "^0.3"
gigachat = "^0.1.36"
gigachat = "^0.1.37"
types-requests = "^2.32"

[tool.poetry.group.dev]
Expand Down

0 comments on commit 6676b2b

Please sign in to comment.