miniwa00 commited on
Commit
ada6925
·
1 Parent(s): 26f4002

구현방안, 기대효과, 근거 필드의 가독성을 개선하기 위해 항목별 개행 추가 로직을 수정하고, 텍스트 포맷팅 함수를 통합하여 코드의 일관성을 높임.

Browse files
Files changed (1) hide show
  1. src/openai_client.py +34 -15
src/openai_client.py CHANGED
@@ -111,9 +111,9 @@ class OpenAIClient:
111
  개요: [간단한 소개]
112
  문제의식: [해결하고자 하는 문제]
113
  솔루션: [구체적인 해결 방안]
114
- 구현방안: [기술적 구현 또는 실행 계획]
115
- 기대효과: [예상 성과 또는 효과]
116
- 근거: [위의 공모전 정보와 노드들이 어떻게 연결되어 이 아이디어가 도출되었는지, connecting the dots 관점에서 상세히 설명]
117
  """
118
 
119
  def _parse_generated_idea(
@@ -195,35 +195,54 @@ class OpenAIClient:
195
  if not idea.get("title"):
196
  idea["title"] = "제목 없음"
197
 
198
- # 구현방안 필드 가독성 개선 (항목별 개행 추가)
199
  if idea.get("implementation"):
200
- idea["implementation"] = format_implementation_text(idea["implementation"])
 
 
 
 
201
 
202
  return idea
203
 
204
 
205
- def format_implementation_text(text: str) -> str:
206
- """구현방안 텍스트의 가독성을 개선하여 각 항목별로 개행 추가"""
207
  if not text:
208
  return text
209
 
210
- # 숫자로 시작하는 항목들을 찾아서 개행 추가
211
  import re
212
 
213
- # "1. ", "2. " 등의 패턴 앞에 개행 추가 (첫 번째 항목 제외)
214
- formatted_text = re.sub(r"(\d+\.\s)", r"\n\1", text.strip())
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
215
 
216
  # 처음에 개행이 추가된 경우 제거
217
  if formatted_text.startswith("\n"):
218
  formatted_text = formatted_text[1:]
219
 
220
- # "- " 로 시작하는 항목들도 처리
221
- formatted_text = re.sub(r"([^.\n])\s*(-\s)", r"\1\n\2", formatted_text)
222
 
223
- # "• " 로 시작하는 항목들도 처리
224
- formatted_text = re.sub(r"([^.\n])\s*(•\s)", r"\1\n\2", formatted_text)
225
 
226
- return formatted_text
 
 
227
 
228
 
229
  # 사용 예시
 
111
  개요: [간단한 소개]
112
  문제의식: [해결하고자 하는 문제]
113
  솔루션: [구체적인 해결 방안]
114
+ 구현방안: [기술적 구현 또는 실행 계획을 단계별로 나열 (1. 2. 3. 형태 또는 - 형태로)]
115
+ 기대효과: [예상 성과 또는 효과를 항목별로 나열 (- 형태로 작성)]
116
+ 근거: [위의 공모전 정보와 노드들이 어떻게 연결되어 이 아이디어가 도출되었는지 connecting the dots 관점에서 논리적 단계별로 설명 (- 형태로 작성)]
117
  """
118
 
119
  def _parse_generated_idea(
 
195
  if not idea.get("title"):
196
  idea["title"] = "제목 없음"
197
 
198
+ # 구현방안, 기대효과, 근거 필드 가독성 개선 (항목별 개행 추가)
199
  if idea.get("implementation"):
200
+ idea["implementation"] = format_list_text(idea["implementation"])
201
+ if idea.get("expected_effect"):
202
+ idea["expected_effect"] = format_list_text(idea["expected_effect"])
203
+ if idea.get("rationale"):
204
+ idea["rationale"] = format_list_text(idea["rationale"])
205
 
206
  return idea
207
 
208
 
209
+ def format_list_text(text: str) -> str:
210
+ """텍스트의 가독성을 개선하여 각 항목별로 개행 추가"""
211
  if not text:
212
  return text
213
 
 
214
  import re
215
 
216
+ # 먼저 텍스트를 정리
217
+ text = text.strip()
218
+
219
+ # "- " 패턴이 있으면 우선 처리
220
+ if "- " in text and not text.startswith("- "):
221
+ # "- " 앞에 개행 추가 (첫 번째 항목 제외)
222
+ formatted_text = re.sub(r"([^.\n])\s*(-\s)", r"\1\n\2", text)
223
+ else:
224
+ # "- " 패턴이 없거나 이미 첫 번째가 "- "로 시작하면 숫자 패턴도 처리
225
+ formatted_text = text
226
+
227
+ # "1. ", "2. " 등의 패턴 앞에 개행 추가 (첫 번째 항목 제외)
228
+ formatted_text = re.sub(r"([^.\n])(\d+\.\s)", r"\1\n\2", formatted_text)
229
+
230
+ # "- " 로 시작하는 항목들 처리
231
+ formatted_text = re.sub(r"([^.\n])\s*(-\s)", r"\1\n\2", formatted_text)
232
+
233
+ # "• " 로 시작하는 항목들 처리
234
+ formatted_text = re.sub(r"([^.\n])\s*(•\s)", r"\1\n\2", formatted_text)
235
 
236
  # 처음에 개행이 추가된 경우 제거
237
  if formatted_text.startswith("\n"):
238
  formatted_text = formatted_text[1:]
239
 
240
+ return formatted_text
 
241
 
 
 
242
 
243
+ def format_implementation_text(text: str) -> str:
244
+ """구현방안 텍스트의 가독성을 개선하여 각 항목별로 개행 추가 (하위 호환성)"""
245
+ return format_list_text(text)
246
 
247
 
248
  # 사용 예시