Создана первоначальная структура обращения к языковым моделям

This commit is contained in:
Даниил Грабарь
2026-09-28 16:11:34 +03:00
commit 40cb7b6716
12 changed files with 2220 additions and 0 deletions
+44
View File
@@ -0,0 +1,44 @@
import json
from dataclasses import asdict
from pathlib import Path
from pydantic_ai.providers.openai_codex import (
OpenAICodexCredentials,
OpenAICodexCredentialSource,
)
class FileCodexCredentionalSource(OpenAICodexCredentialSource):
def __init__(self,
path: Path,
encoding: str="utf-8",
ensure_ascii: bool=False,
indent: int=2):
super().__init__()
self._path = path
self._encoding=encoding
self._ensure_ascii=ensure_ascii
self._indent=indent
@property
def path(self):
return self._path
async def load(self) -> OpenAICodexCredentials:
return OpenAICodexCredentials(
**json.loads(
self._path.read_text(encoding=self._encoding)
)
)
async def save(self, credentials: OpenAICodexCredentials) -> None:
self._path.write_text(
json.dumps(
asdict(credentials),
ensure_ascii=self._ensure_ascii,
indent=self._indent
),
encoding=self._encoding
)