fix: AIPlanner에서 GLM 모델 버전 변경 및 JSON 응답 처리 개선
- GLM 모델 버전을 "GLM-4.7"에서 "GLM-4.5-Air"로 변경 - JSON 응답 처리 시, 재시도 시 max_tokens 및 temperature 조정 로직 추가하여 JSON 포맷 준수율 향상 - README.md에 변경 사항 반영
This commit is contained in:
@@ -22,7 +22,7 @@ import traceback
|
||||
|
||||
|
||||
GLM_API_URL = "https://api.z.ai/api/coding/paas/v4/chat/completions"
|
||||
GLM_MODEL = "GLM-4.7"
|
||||
GLM_MODEL = "GLM-4.5-Air"
|
||||
|
||||
|
||||
SYSTEM_PROMPT = """당신은 팩토리오 게임을 순수하게 플레이하는 AI 에이전트입니다.
|
||||
@@ -355,9 +355,21 @@ class AIPlanner:
|
||||
def _call_glm(self, user_message: str, attempt: int) -> str:
|
||||
# attempt가 올라갈수록 "분석 텍스트"가 길어지면서 JSON이 잘리는 패턴이 있어
|
||||
# retry에서는 출력 길이를 줄인다.
|
||||
repair_mode = "JSON 요구사항을 위반했습니다" in user_message or "응답의 첫 비공백 문자는 반드시" in user_message
|
||||
|
||||
base_max_tokens = int(os.environ.get("GLM_MAX_TOKENS", "2000"))
|
||||
retry_max_tokens = int(os.environ.get("GLM_RETRY_MAX_TOKENS", "900"))
|
||||
max_tokens = base_max_tokens if attempt == 0 else min(base_max_tokens, retry_max_tokens)
|
||||
repair_max_tokens = int(os.environ.get("GLM_REPAIR_MAX_TOKENS", "600"))
|
||||
|
||||
if repair_mode:
|
||||
max_tokens = repair_max_tokens
|
||||
else:
|
||||
max_tokens = base_max_tokens if attempt == 0 else min(base_max_tokens, retry_max_tokens)
|
||||
|
||||
temperature = 0.3
|
||||
if repair_mode:
|
||||
# JSON 포맷 준수율을 높이기 위해 변동성을 낮춘다.
|
||||
temperature = float(os.environ.get("GLM_REPAIR_TEMPERATURE", "0.1"))
|
||||
|
||||
payload = json.dumps({
|
||||
"model": GLM_MODEL,
|
||||
@@ -365,7 +377,7 @@ class AIPlanner:
|
||||
{"role": "system", "content": SYSTEM_PROMPT},
|
||||
{"role": "user", "content": user_message},
|
||||
],
|
||||
"temperature": 0.3,
|
||||
"temperature": temperature,
|
||||
"max_tokens": max_tokens,
|
||||
}).encode("utf-8")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user