Skip to content
Merged
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ giga = GigaChat(
)
```

Авторизация с помощью токена доступа:
Авторизация с помощью токена доступа:

```py
giga = GigaChat(
Expand Down
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* [Асинхронная работа с потоковой обработкой токенов](./streaming_asyncio.py)
* [Взаимная аутентификация по протоколу TLS (mTLS)](./example_auth_certs_mtls.py)
* [Использование необязательны заголовков](./example_contextvars.py)

Пример демонстрирует как с помощью библиотеки вы можете передавать необязательные заголовки `X-Session-ID`, `X-Request-ID` и другие.

Необязательные заголовки могут использоваться для различных целей. Например, для упрощения логирования или для [кэширования запросов](https://developers.sber.ru/docs/ru/gigachat/api/keeping-context#keshirovanie-zaprosov).
Expand Down
381 changes: 224 additions & 157 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "gigachat"
version = "0.1.39"
version = "0.1.39post1"
description = "GigaChat. Python-library for GigaChain and LangChain"
authors = ["Konstantin Krestnikov <[email protected]>", "Sergey Malyshev <[email protected]>"]
license = "MIT"
Expand Down
4 changes: 3 additions & 1 deletion src/gigachat/api/post_chat.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
from typing import Any, Dict, Optional

import httpx
Expand All @@ -12,11 +13,12 @@ def _get_kwargs(
access_token: Optional[str] = None,
) -> Dict[str, Any]:
headers = build_headers(access_token)
headers["Content-Type"] = "application/json"

return {
"method": "POST",
"url": "/chat/completions",
"json": chat.dict(exclude_none=True, by_alias=True, exclude={"stream"}),
"content": json.dumps(chat.dict(exclude_none=True, by_alias=True, exclude={"stream"}), ensure_ascii=False),
"headers": headers,
}

Expand Down
4 changes: 3 additions & 1 deletion src/gigachat/api/post_embeddings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
from typing import Any, Dict, List, Optional

import httpx
Expand All @@ -13,11 +14,12 @@ def _get_kwargs(
access_token: Optional[str] = None,
) -> Dict[str, Any]:
headers = build_headers(access_token)
headers["Content-Type"] = "application/json"

return {
"method": "POST",
"url": "/embeddings",
"json": {"input": input_, "model": model},
"content": json.dumps({"input": input_, "model": model}, ensure_ascii=False),
"headers": headers,
}

Expand Down
4 changes: 3 additions & 1 deletion src/gigachat/api/post_tokens_count.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
from http import HTTPStatus
from typing import Any, Dict, List, Optional

Expand All @@ -15,14 +16,15 @@ def _get_kwargs(
access_token: Optional[str] = None,
) -> Dict[str, Any]:
headers = build_headers(access_token)
headers["Content-Type"] = "application/json"

json_data = {"model": model, "input": input_}

return {
"method": "POST",
"url": "/tokens/count",
"headers": headers,
"json": json_data,
"content": json.dumps(json_data, ensure_ascii=False),
}


Expand Down
4 changes: 3 additions & 1 deletion src/gigachat/api/stream_chat.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
from http import HTTPStatus
from typing import Any, AsyncIterator, Dict, Iterator, Optional

Expand All @@ -18,11 +19,12 @@ def _get_kwargs(
headers = build_headers(access_token)
headers["Accept"] = EVENT_STREAM
headers["Cache-Control"] = "no-store"
headers["Content-Type"] = "application/json"

return {
"method": "POST",
"url": "/chat/completions",
"json": {**chat.dict(exclude_none=True, by_alias=True), **{"stream": True}},
"content": json.dumps({**chat.dict(exclude_none=True, by_alias=True), **{"stream": True}}, ensure_ascii=False),
"headers": headers,
}

Expand Down
2 changes: 1 addition & 1 deletion src/gigachat/models/storage.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Dict, Optional, Any
from typing import Any, Dict, Optional

from gigachat.pydantic_v1 import BaseModel

Expand Down
2 changes: 1 addition & 1 deletion tests/data/balance.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
"value": 900000
}
]
}
}
2 changes: 1 addition & 1 deletion tests/data/convert_functions.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@
]
}
]
}
}
2 changes: 1 addition & 1 deletion tests/data/get_file.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
"created_at": 1740658568,
"filename": "invoicesample.pdf",
"purpose": "general"
}
}
2 changes: 1 addition & 1 deletion tests/data/get_files.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
"purpose": "general"
}
]
}
}
2 changes: 1 addition & 1 deletion tests/data/post_files_delete.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"id": "123",
"object": "file",
"deleted": true
}
}