주소 파싱코드 분리 및 에러 수정

This commit is contained in:
skkim committed 2026-06-02 17:21:27 +09:00
1 parent 2b4c89217a
commit bdee852bed
6 files changed
+134 -124

No files matched your search

+17 -12
View File
@@ -12,6 +12,20 @@ _SCOPES = [
"https://www.googleapis.com/auth/spreadsheets.readonly"
]
_sheet_cache: dict[str, tuple[str, str]] = {}
def _read_sheet_data(sheet_name: str) -> tuple[str, str]:
if sheet_name not in _sheet_cache:
creds = Credentials.from_service_account_file(
prompt_settings.GOOGLE_SERVICE_ACCOUNT_JSON, scopes=_SCOPES
)
gc = gspread.authorize(creds)
ws = gc.open_by_key(prompt_settings.PROMPT_SPREADSHEET).worksheet(sheet_name)
_sheet_cache[sheet_name] = (ws.cell(3, 2).value, ws.cell(2, 2).value)
return _sheet_cache[sheet_name]
class Prompt():
sheet_name: str
prompt_template: str
@@ -24,20 +38,11 @@ class Prompt():
self.sheet_name = sheet_name
self.prompt_input_class = prompt_input_class
self.prompt_output_class = prompt_output_class
self.prompt_template, self.prompt_model = self._read_from_sheets()
def _read_from_sheets(self) -> tuple[str, str]:
creds = Credentials.from_service_account_file(
prompt_settings.GOOGLE_SERVICE_ACCOUNT_JSON, scopes=_SCOPES
)
gc = gspread.authorize(creds)
ws = gc.open_by_key(prompt_settings.PROMPT_SPREADSHEET).worksheet(self.sheet_name)
model = ws.cell(2, 2).value
input_text = ws.cell(3, 2).value
return input_text, model
self.prompt_template, self.prompt_model = _read_sheet_data(sheet_name)
def _reload_prompt(self):
self.prompt_template, self.prompt_model = self._read_from_sheets()
_sheet_cache.pop(self.sheet_name, None)
self.prompt_template, self.prompt_model = _read_sheet_data(self.sheet_name)
def build_prompt(self, input_data:dict, silent:bool = False) -> str:
verified_input = self.prompt_input_class(**input_data)