Spaces:
Sleeping
Sleeping
Tuchuanhuhuhu
commited on
Commit
·
6f97306
1
Parent(s):
35eae3e
修复自定义URL Base时的bug
Browse files- modules/index_func.py +1 -1
- modules/models/ChuanhuAgent.py +1 -1
- modules/shared.py +4 -2
modules/index_func.py
CHANGED
@@ -118,7 +118,7 @@ def construct_index(
|
|
118 |
embeddings = HuggingFaceEmbeddings(model_name = "sentence-transformers/distiluse-base-multilingual-cased-v2")
|
119 |
else:
|
120 |
from langchain.embeddings import OpenAIEmbeddings
|
121 |
-
embeddings = OpenAIEmbeddings()
|
122 |
if os.path.exists(index_path):
|
123 |
logging.info("找到了缓存的索引文件,加载中……")
|
124 |
return FAISS.load_local(index_path, embeddings)
|
|
|
118 |
embeddings = HuggingFaceEmbeddings(model_name = "sentence-transformers/distiluse-base-multilingual-cased-v2")
|
119 |
else:
|
120 |
from langchain.embeddings import OpenAIEmbeddings
|
121 |
+
embeddings = OpenAIEmbeddings(openai_api_base=os.environ.get("OPENAI_API_BASE", None), openai_api_key=os.environ.get("OPENAI_EMBEDDING_API_KEY", api_key))
|
122 |
if os.path.exists(index_path):
|
123 |
logging.info("找到了缓存的索引文件,加载中……")
|
124 |
return FAISS.load_local(index_path, embeddings)
|
modules/models/ChuanhuAgent.py
CHANGED
@@ -156,7 +156,7 @@ class ChuanhuAgent_Client(BaseLLMModel):
|
|
156 |
texts = Document(page_content=text)
|
157 |
texts = self.text_splitter.split_documents([texts])
|
158 |
# use embedding
|
159 |
-
embeddings = OpenAIEmbeddings(openai_api_key=self.api_key)
|
160 |
|
161 |
# create vectorstore
|
162 |
db = FAISS.from_documents(texts, embeddings)
|
|
|
156 |
texts = Document(page_content=text)
|
157 |
texts = self.text_splitter.split_documents([texts])
|
158 |
# use embedding
|
159 |
+
embeddings = OpenAIEmbeddings(openai_api_key=self.api_key, openai_api_base=os.environ.get("OPENAI_API_BASE", None))
|
160 |
|
161 |
# create vectorstore
|
162 |
db = FAISS.from_documents(texts, embeddings)
|
modules/shared.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
from modules.presets import COMPLETION_URL, BALANCE_API_URL, USAGE_API_URL, API_HOST
|
2 |
import os
|
3 |
import queue
|
|
|
4 |
|
5 |
class State:
|
6 |
interrupted = False
|
@@ -16,6 +17,7 @@ class State:
|
|
16 |
self.interrupted = False
|
17 |
|
18 |
def set_api_host(self, api_host: str):
|
|
|
19 |
if not api_host.startswith("http"):
|
20 |
api_host = f"https://{api_host}"
|
21 |
if api_host.endswith("/v1"):
|
@@ -23,13 +25,13 @@ class State:
|
|
23 |
self.completion_url = f"{api_host}/v1/chat/completions"
|
24 |
self.balance_api_url = f"{api_host}/dashboard/billing/credit_grants"
|
25 |
self.usage_api_url = f"{api_host}/dashboard/billing/usage"
|
26 |
-
os.environ["OPENAI_API_BASE"] =
|
27 |
|
28 |
def reset_api_host(self):
|
29 |
self.completion_url = COMPLETION_URL
|
30 |
self.balance_api_url = BALANCE_API_URL
|
31 |
self.usage_api_url = USAGE_API_URL
|
32 |
-
os.environ["OPENAI_API_BASE"] = f"https://{API_HOST}
|
33 |
return API_HOST
|
34 |
|
35 |
def reset_all(self):
|
|
|
1 |
from modules.presets import COMPLETION_URL, BALANCE_API_URL, USAGE_API_URL, API_HOST
|
2 |
import os
|
3 |
import queue
|
4 |
+
import openai
|
5 |
|
6 |
class State:
|
7 |
interrupted = False
|
|
|
17 |
self.interrupted = False
|
18 |
|
19 |
def set_api_host(self, api_host: str):
|
20 |
+
api_host = api_host.rstrip("/")
|
21 |
if not api_host.startswith("http"):
|
22 |
api_host = f"https://{api_host}"
|
23 |
if api_host.endswith("/v1"):
|
|
|
25 |
self.completion_url = f"{api_host}/v1/chat/completions"
|
26 |
self.balance_api_url = f"{api_host}/dashboard/billing/credit_grants"
|
27 |
self.usage_api_url = f"{api_host}/dashboard/billing/usage"
|
28 |
+
os.environ["OPENAI_API_BASE"] = api_host
|
29 |
|
30 |
def reset_api_host(self):
|
31 |
self.completion_url = COMPLETION_URL
|
32 |
self.balance_api_url = BALANCE_API_URL
|
33 |
self.usage_api_url = USAGE_API_URL
|
34 |
+
os.environ["OPENAI_API_BASE"] = f"https://{API_HOST}"
|
35 |
return API_HOST
|
36 |
|
37 |
def reset_all(self):
|