GitHub Actions commited on
Commit
29964a7
·
1 Parent(s): 0996863

Auto-deploy from GitHub Actions - 2025-12-12 06:56:50

Browse files
Files changed (1) hide show
  1. app/routes.py +45 -4
app/routes.py CHANGED
@@ -803,7 +803,7 @@ def extract_graph_from_episode(episode_content, episode_title, file_id, full_con
803
  prompt=prompt,
804
  model_name="gemini-1.5-flash",
805
  temperature=0.3,
806
- max_output_tokens=3000
807
  )
808
  if not result['error'] and result.get('response'):
809
  response_text = result['response'].strip()
@@ -834,7 +834,7 @@ def extract_graph_from_episode(episode_content, episode_title, file_id, full_con
834
  prompt=prompt,
835
  model_name=gemini_model_name,
836
  temperature=0.3,
837
- max_output_tokens=3000
838
  )
839
  if not result['error'] and result.get('response'):
840
  response_text = result['response'].strip()
@@ -900,8 +900,49 @@ def extract_graph_from_episode(episode_content, episode_title, file_id, full_con
900
  graph_data = json.loads(json_match.group(0))
901
  except json.JSONDecodeError as e:
902
  print(f"[Graph Extraction] '{episode_title}' JSON 파싱 오류: {str(e)}")
903
- print(f"[Graph Extraction] 응답 일부: {response_text[:500]}")
904
- return False
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
905
 
906
  # 기존 Graph 데이터 삭제 (같은 회차의 기존 데이터)
907
  GraphEntity.query.filter_by(file_id=file_id, episode_title=episode_title).delete()
 
803
  prompt=prompt,
804
  model_name="gemini-1.5-flash",
805
  temperature=0.3,
806
+ max_output_tokens=8192
807
  )
808
  if not result['error'] and result.get('response'):
809
  response_text = result['response'].strip()
 
834
  prompt=prompt,
835
  model_name=gemini_model_name,
836
  temperature=0.3,
837
+ max_output_tokens=8192
838
  )
839
  if not result['error'] and result.get('response'):
840
  response_text = result['response'].strip()
 
900
  graph_data = json.loads(json_match.group(0))
901
  except json.JSONDecodeError as e:
902
  print(f"[Graph Extraction] '{episode_title}' JSON 파싱 오류: {str(e)}")
903
+
904
+ # JSON 자동 복구 시도
905
+ try:
906
+ print(f"[Graph Extraction] JSON 자동 복구 시도...")
907
+ json_str = json_match.group(0).strip()
908
+
909
+ # 마지막이 닫히지 않았는지 확인
910
+ stack = []
911
+ for char in json_str:
912
+ if char == '{':
913
+ stack.append('}')
914
+ elif char == '[':
915
+ stack.append(']')
916
+ elif char == '}' or char == ']':
917
+ if stack:
918
+ stack.pop()
919
+
920
+ # 스택에 남은 괄호를 역순으로 닫아줌
921
+ if stack:
922
+ # 마지막 항목이 콤마로 끝나는 경우 콤마 제거 (단, 문자열 내부가 아닌 경우)
923
+ # 간단하게 마지막 문자가 ',' 이면 제거
924
+ if json_str.rstrip().endswith(','):
925
+ json_str = json_str.rstrip()[:-1]
926
+
927
+ # 문자열이 열려있는지 확인 (간단한 체크)
928
+ quote_count = json_str.count('"')
929
+ if quote_count % 2 != 0:
930
+ json_str += '"' # 따옴표 닫기
931
+
932
+ # 괄호 닫기
933
+ for char in reversed(stack):
934
+ json_str += char
935
+
936
+ print(f"[Graph Extraction] 복구된 JSON: {json_str[-100:]}")
937
+ graph_data = json.loads(json_str)
938
+ print(f"[Graph Extraction] JSON 복구 성공!")
939
+ else:
940
+ # 스택이 비어있으면 다른 문제이므로 실패 처리
941
+ print(f"[Graph Extraction] 응답 일부: {response_text[:500]}")
942
+ return False
943
+ except Exception as recover_error:
944
+ print(f"[Graph Extraction] JSON 복구 실패: {str(recover_error)}")
945
+ return False
946
 
947
  # 기존 Graph 데이터 삭제 (같은 회차의 기존 데이터)
948
  GraphEntity.query.filter_by(file_id=file_id, episode_title=episode_title).delete()