Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
-
api_token = os.getenv("HF_TOKEN")
|
4 |
|
5 |
|
6 |
from langchain_community.vectorstores import FAISS
|
@@ -15,6 +15,15 @@ from langchain.memory import ConversationBufferMemory
|
|
15 |
from langchain_community.llms import HuggingFaceEndpoint
|
16 |
import torch
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
list_llm = ["meta-llama/Meta-Llama-3-8B-Instruct", "mistralai/Mistral-7B-Instruct-v0.2"]
|
19 |
list_llm_simple = [os.path.basename(llm) for llm in list_llm]
|
20 |
|
@@ -46,14 +55,14 @@ def initialize_llmchain(llm_model, temperature, max_tokens, top_k, vector_db, pr
|
|
46 |
if llm_model == "meta-llama/Meta-Llama-3-8B-Instruct":
|
47 |
llm = HuggingFaceEndpoint(
|
48 |
repo_id=llm_model,
|
49 |
-
huggingfacehub_api_token =
|
50 |
temperature = temperature,
|
51 |
max_new_tokens = max_tokens,
|
52 |
top_k = top_k,
|
53 |
)
|
54 |
else:
|
55 |
llm = HuggingFaceEndpoint(
|
56 |
-
huggingfacehub_api_token =
|
57 |
repo_id=llm_model,
|
58 |
temperature = temperature,
|
59 |
max_new_tokens = max_tokens,
|
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
+
#api_token = os.getenv("HF_TOKEN")
|
4 |
|
5 |
|
6 |
from langchain_community.vectorstores import FAISS
|
|
|
15 |
from langchain_community.llms import HuggingFaceEndpoint
|
16 |
import torch
|
17 |
|
18 |
+
|
19 |
+
# 獲取 OpenAI API 密鑰(初始不使用固定密鑰)
|
20 |
+
api_key_env = os.getenv("OPENAI_API")
|
21 |
+
if api_key_env:
|
22 |
+
openai.api_key = api_key_env
|
23 |
+
logger.info("OpenAI API 密鑰已設置。")
|
24 |
+
else:
|
25 |
+
logger.info("未設置固定的 OpenAI API 密鑰。將使用使用者提供的密鑰。")
|
26 |
+
|
27 |
list_llm = ["meta-llama/Meta-Llama-3-8B-Instruct", "mistralai/Mistral-7B-Instruct-v0.2"]
|
28 |
list_llm_simple = [os.path.basename(llm) for llm in list_llm]
|
29 |
|
|
|
55 |
if llm_model == "meta-llama/Meta-Llama-3-8B-Instruct":
|
56 |
llm = HuggingFaceEndpoint(
|
57 |
repo_id=llm_model,
|
58 |
+
huggingfacehub_api_token = api_key_env,
|
59 |
temperature = temperature,
|
60 |
max_new_tokens = max_tokens,
|
61 |
top_k = top_k,
|
62 |
)
|
63 |
else:
|
64 |
llm = HuggingFaceEndpoint(
|
65 |
+
huggingfacehub_api_token = api_key_env,
|
66 |
repo_id=llm_model,
|
67 |
temperature = temperature,
|
68 |
max_new_tokens = max_tokens,
|