프롬프트 처리 구조 변경 및 마케팅/가사 프롬프트 최신화

This commit is contained in:
jaehwang committed 2026-01-16 10:05:29 +09:00
1 parent ba26284451
commit 4e15e44cbe
15 files changed
+2180 -1277

No files matched your search

+33 -16
View File
@@ -27,6 +27,7 @@ from app.utils.upload_blob_as_request import AzureBlobUploader
from app.utils.chatgpt_prompt import ChatgptService
from app.utils.common import generate_task_id
from app.utils.nvMapScraper import NvMapScraper, GraphQLException
from app.utils.prompts.prompts import marketing_prompt
# 로거 설정
logger = logging.getLogger(__name__)
@@ -172,34 +173,50 @@ async def crawling(request_body: CrawlingRequest):
try:
# Step 3-1: ChatGPT 서비스 초기화
step3_1_start = time.perf_counter()
chatgpt_service = ChatgptService(
customer_name=customer_name,
region=region,
detail_region_info=road_address or "",
)
chatgpt_service = ChatgptService()
step3_1_elapsed = (time.perf_counter() - step3_1_start) * 1000
print(f"[crawling] Step 3-1: 서비스 초기화 완료 ({step3_1_elapsed:.1f}ms)")
# Step 3-2: 프롬프트 생성
step3_2_start = time.perf_counter()
prompt = chatgpt_service.build_market_analysis_prompt()
step3_2_elapsed = (time.perf_counter() - step3_2_start) * 1000
print(f"[crawling] Step 3-2: 프롬프트 생성 완료 - {len(prompt)}자 ({step3_2_elapsed:.1f}ms)")
# step3_2_start = time.perf_counter()
input_marketing_data = {
"customer_name" : customer_name,
"region" : region,
"detail_region_info" : road_address or ""
}
# prompt = chatgpt_service.build_market_analysis_prompt()
# prompt1 = marketing_prompt.build_prompt(input_marketing_data)
# step3_2_elapsed = (time.perf_counter() - step3_2_start) * 1000
# print(f"[crawling] Step 3-2: 프롬프트 생성 완료 - ({step3_2_elapsed:.1f}ms)")
# Step 3-3: GPT API 호출
step3_3_start = time.perf_counter()
raw_response = await chatgpt_service.generate(prompt)
structured_report = await chatgpt_service.generate_structured_output(marketing_prompt, input_marketing_data)
step3_3_elapsed = (time.perf_counter() - step3_3_start) * 1000
logger.info(f"[crawling] Step 3-3: GPT API 호출 완료 - 응답 {len(raw_response)}자 ({step3_3_elapsed:.1f}ms)")
print(f"[crawling] Step 3-3: GPT API 호출 완료 - 응답 {len(raw_response)}자 ({step3_3_elapsed:.1f}ms)")
logger.info(f"[crawling] Step 3-3: GPT API 호출 완료 - ({step3_3_elapsed:.1f}ms)")
print(f"[crawling] Step 3-3: GPT API 호출 완료 - ({step3_3_elapsed:.1f}ms)")
# Step 3-4: 응답 파싱 (크롤링에서 가져온 facility_info 전달)
step3_4_start = time.perf_counter()
print(f"[crawling] Step 3-4: 응답 파싱 시작 - facility_info: {scraper.facility_info}")
parsed = await chatgpt_service.parse_marketing_analysis(
raw_response, facility_info=scraper.facility_info
# 요약 Deprecated / 20250115 / Selling points를 첫 prompt에서 추출 중
# parsed = await chatgpt_service.parse_marketing_analysis(
# structured_report, facility_info=scraper.facility_info
# )
# marketing_analysis = MarketingAnalysis(**parsed)
marketing_analysis = MarketingAnalysis(
report=structured_report["report"],
tags=structured_report["tags"],
facilities = list([sp['keywords'] for sp in structured_report["selling_points"]])# [json.dumps(structured_report["selling_points"])] # 나중에 Selling Points로 변수와 데이터구조 변경할 것
)
marketing_analysis = MarketingAnalysis(**parsed)
# Selling Points 구조
# print(sp['category'])
# print(sp['keywords'])
# print(sp['description'])
step3_4_elapsed = (time.perf_counter() - step3_4_start) * 1000
print(f"[crawling] Step 3-4: 응답 파싱 완료 ({step3_4_elapsed:.1f}ms)")
@@ -236,7 +253,7 @@ async def crawling(request_body: CrawlingRequest):
"image_list": scraper.image_link_list,
"image_count": len(scraper.image_link_list) if scraper.image_link_list else 0,
"processed_info": processed_info,
"marketing_analysis": marketing_analysis,
"marketing_analysis": marketing_analysis
}