ChienChung commited on
Commit
7794c9b
·
verified ·
1 Parent(s): 2b0aa21

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -10
app.py CHANGED
@@ -30,17 +30,33 @@ os.environ["LANGCHAIN_API_KEY"] = os.getenv("LANGCHAIN_API_KEY")
30
  os.environ["LANGCHAIN_PROJECT"] = os.getenv("LANGCHAIN_PROJECT")
31
 
32
 
33
- # ✅ 禁用 DeepEval 遙測功能(環境變數層級)
34
- os.environ["DEEPEVAL_TELEMETRY_OPT_OUT"] = "YES"
35
- os.environ["DEEPEVAL_DISABLE_TELEMETRY"] = "true"
36
- os.environ["DEEPEVAL_RESULTS_FOLDER"] = "/tmp/deepeval_results" # 可選:避免在 home 建目錄
37
 
38
- # ✅ 禁用 DeepEval 遙測功能(程式碼層級)
39
- try:
40
- from deepeval.telemetry import disable_telemetry
41
- disable_telemetry()
42
- except Exception as e:
43
- print(f"[WARNING] Failed to disable DeepEval telemetry: {e}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  # Load Required Modules
45
  from langchain.embeddings import HuggingFaceEmbeddings
46
  from langchain.vectorstores import Chroma, FAISS
 
30
  os.environ["LANGCHAIN_PROJECT"] = os.getenv("LANGCHAIN_PROJECT")
31
 
32
 
 
 
 
 
33
 
34
+
35
+ # 解決 DeepEval 無法寫檔問題
36
+ os.environ["DEEPEVAL_TELEMETRY_OPT_OUT"] = "YES" # 禁用遙測,避免寫 .deepeval_telemetry.txt
37
+ os.environ["DEEPEVAL_RESULTS_FOLDER"] = "/tmp/deepeval_results" # 結果寫到可寫目錄
38
+ os.makedirs("/tmp/deepeval_results", exist_ok=True)
39
+
40
+ # 最重要:避免它在當前目錄寫 temp_test_run_data.json
41
+ os.chdir("/tmp") # 切換工作目錄,讓 temp file 也寫在 /tmp 裡(可寫) # 可選:避免在 home 建目錄
42
+
43
+ SHOW_EVAL = os.getenv("SHOW_EVAL", "false").lower() == "true"
44
+ if SHOW_EVAL:
45
+ try:
46
+ test_case = LLMTestCase(
47
+ input=query,
48
+ actual_output=raw_answer,
49
+ expected_output=raw_answer,
50
+ context=[d.page_content for d in chunks[:3]]
51
+ )
52
+ metric = AnswerRelevancyMetric()
53
+ results = evaluate([test_case], [metric])
54
+ result = results[0]
55
+ print(f"[DeepEval QA] Input: {query}")
56
+ print(f"[DeepEval QA] Passed: {result.passed}, Score: {result.score:.2f}, Reason: {result.reason}")
57
+ except Exception as e:
58
+ print(f"[DeepEval QA] Evaluation failed: {e}")
59
+
60
  # Load Required Modules
61
  from langchain.embeddings import HuggingFaceEmbeddings
62
  from langchain.vectorstores import Chroma, FAISS