직접입력시 업종추가
This commit is contained in:
1 parent
46449a7a3f
commit
4d8462651a
4 files changed
+36
-10
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import json
|
||||
import re
|
||||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel, ValidationError
|
||||
from typing import List, Optional
|
||||
from openai import AsyncOpenAI
|
||||
|
||||
@@ -131,11 +131,23 @@ class ChatgptService:
|
||||
})
|
||||
last_error = None
|
||||
for attempt in range(self.max_retries + 1):
|
||||
response = await self.client.beta.chat.completions.parse(
|
||||
model=model,
|
||||
messages=[{"role": "user", "content": content}],
|
||||
response_format=output_format
|
||||
)
|
||||
try:
|
||||
response = await self.client.beta.chat.completions.parse(
|
||||
model=model,
|
||||
messages=[{"role": "user", "content": content}],
|
||||
response_format=output_format
|
||||
)
|
||||
except (ValidationError, json.JSONDecodeError) as e:
|
||||
# 모델이 스키마에 맞지 않는 JSON을 반환한 경우 (예: trailing characters).
|
||||
# 확률적 출력 문제일 수 있으므로 재시도 대상에 포함한다.
|
||||
logger.warning(
|
||||
f"[ChatgptService({self.model_type})] Structured output parse failed "
|
||||
f"(attempt {attempt + 1}/{self.max_retries + 1}): {e}"
|
||||
)
|
||||
last_error = ChatGPTResponseError("parse_error", type(e).__name__, str(e))
|
||||
if attempt < self.max_retries:
|
||||
logger.info(f"[ChatgptService({self.model_type})] Retrying request...")
|
||||
continue
|
||||
# Response 디버그 로깅
|
||||
logger.debug(f"[ChatgptService({self.model_type})] attempt: {attempt}")
|
||||
logger.debug(f"[ChatgptService({self.model_type})] Response ID: {response.id}")
|
||||
|
||||
Reference in new issue
Block a user