Skip to content

feat: chat caching via X-Session-ID #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/gigachat/api/post_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def _get_kwargs(
chat: Chat,
access_token: Optional[str] = None,
) -> Dict[str, Any]:
headers = build_headers(access_token)
headers = build_headers(access_token, chat.session_id)

return {
"method": "POST",
Expand Down
5 changes: 3 additions & 2 deletions src/gigachat/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
USER_AGENT = "GigaChat-python-lib"


def build_headers(access_token: Optional[str] = None) -> Dict[str, str]:
def build_headers(access_token: Optional[str] = None, session_id: Optional[str] = None) -> Dict[str, str]:
headers = {}

if access_token:
Expand All @@ -25,7 +25,8 @@ def build_headers(access_token: Optional[str] = None) -> Dict[str, str]:
headers["User-Agent"] = USER_AGENT

authorization = authorization_cvar.get()
session_id = session_id_cvar.get()
if session_id is None:
session_id = session_id_cvar.get()
request_id = request_id_cvar.get()
service_id = service_id_cvar.get()
operation_id = operation_id_cvar.get()
Expand Down
2 changes: 2 additions & 0 deletions src/gigachat/models/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ class Chat(BaseModel):
"""Набор функций, которые могут быть вызваны моделью"""
flags: Optional[List[str]] = None
"""Флаги, включающие особенные фичи"""
session_id: Optional[str] = None
"""Идентификатор сессии для кэширования X-Session-ID"""