Создана первоначальная структура обращения к языковым моделям
This commit is contained in:
@@ -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
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user