88 lines
3.7 KiB
Python
88 lines
3.7 KiB
Python
import os
|
|
import json
|
|
|
|
file_path = r"d:\py\AutoPercenty3_311\src\AI_Module\ai_client.py"
|
|
|
|
with open(file_path, 'r', encoding='utf-8') as f:
|
|
content = f.read()
|
|
|
|
# Construct the old block exactly as it appears in the file (assuming 12 spaces indentation)
|
|
# We use raw strings or careful escaping.
|
|
# The file has:
|
|
# prompt = (
|
|
# f"당신은 ... \n"
|
|
# ...
|
|
# )
|
|
|
|
# We will try to locate the start and end indices dynamically to avoid exact string matching issues
|
|
start_marker = ' prompt = ('
|
|
end_marker = ' )'
|
|
|
|
start_idx = content.find(start_marker)
|
|
if start_idx == -1:
|
|
print("Could not find start marker")
|
|
exit(1)
|
|
|
|
# Find the matching closing parenthesis for the prompt assignment
|
|
# It should be the first ' )' after start_idx
|
|
end_idx = content.find(end_marker, start_idx)
|
|
if end_idx == -1:
|
|
print("Could not find end marker")
|
|
exit(1)
|
|
|
|
end_idx += len(end_marker)
|
|
|
|
old_block = content[start_idx:end_idx]
|
|
print(f"Found block length: {len(old_block)}")
|
|
|
|
new_block = """ if is_numbering_only:
|
|
prompt = (
|
|
f"당신은 쇼핑몰 옵션명 요약 봇입니다.\\n"
|
|
f"입력값은 {{ '번호': '한국어_옵션명' }} 입니다.\\n"
|
|
f"각 번호에 해당하는 옵션명을 **심플하고 직관적인 단어**로 수정해서 반환하세요.\\n\\n"
|
|
|
|
f"### 📦 상품 정보:\\n"
|
|
f"- 상품명: {product_name}\\n\\n"
|
|
f"- 카테고리: {category}\\n\\n"
|
|
|
|
f"### ⚡ 요약 규칙:\\n"
|
|
f"1. **길이 제한 없음**: 다만 심플하고 직관적이어야 함.\\n"
|
|
f"2. **마케팅적 표현**: 한국 쇼핑몰에서 사용하는 상품옵션처럼 자연스럽게 수정.\\n"
|
|
f"3. **구어체 제거**: 불필요한 수식어나 구어체를 제거하고 명사 위주로 정리.\\n"
|
|
f"4. **형식 유지**: 입력된 번호(Key)를 그대로 유지하세요.\\n\\n"
|
|
|
|
f"### 출력 형식 (JSON):\\n"
|
|
f"{{ '1': '수정된_1번', '2': '수정된_2번', ... }}\\n\\n"
|
|
|
|
f"### 입력 데이터:\\n{json.dumps(cleaned_input, ensure_ascii=False)}"
|
|
)
|
|
else:
|
|
prompt = (
|
|
f"당신은 쇼핑몰 옵션명 요약 봇입니다.\\n"
|
|
f"입력값은 {{ '번호': '한국어_옵션명' }} 입니다.\\n"
|
|
f"각 번호에 해당하는 옵션명을 **{max_length}자 이내**로 줄여서 반환하세요.\\n\\n"
|
|
|
|
f"### 📦 상품 정보:\\n"
|
|
f"- 상품명: {product_name}\\n\\n"
|
|
f"- 카테고리: {category}\\n\\n"
|
|
|
|
f"### ⚡ 요약 규칙:\\n"
|
|
f"1. **길이 제한**: 공백 포함 {max_length}자 이하.\\n"
|
|
f"2. **형용사 삭제**: 색상/핵심명사만 남기고 수식어, 꾸며주는 말 등은 삭제.\\n"
|
|
f"3. **구성품 축약**: 'A+B+C' -> 'A 세트' 또는 'A+B 외'.\\n"
|
|
f"4. **형식 유지**: 입력된 번호(Key)를 그대로 유지하세요.\\n\\n"
|
|
|
|
f"### 출력 형식 (JSON):\\n"
|
|
f"{{ '1': '요약된_1번', '2': '요약된_2번', ... }}\\n\\n"
|
|
|
|
f"### 입력 데이터:\\n{json.dumps(cleaned_input, ensure_ascii=False)}"
|
|
)"""
|
|
|
|
# Replace
|
|
new_content = content[:start_idx] + new_block + content[end_idx:]
|
|
|
|
with open(file_path, 'w', encoding='utf-8') as f:
|
|
f.write(new_content)
|
|
|
|
print("Successfully updated ai_client.py")
|