maccmaccmaccc
commited on
Commit
•
18971d1
1
Parent(s):
300e5ab
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ from llama_index.core import VectorStoreIndex, SimpleDirectoryReader, Settings
|
|
3 |
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
|
4 |
from llama_index.legacy.callbacks import CallbackManager
|
5 |
from llama_index.llms.openai_like import OpenAILike
|
|
|
6 |
|
7 |
# Create an instance of CallbackManager
|
8 |
callback_manager = CallbackManager()
|
@@ -11,25 +12,29 @@ api_base_url = "https://internlm-chat.intern-ai.org.cn/puyu/api/v1/"
|
|
11 |
model = "internlm2.5-latest"
|
12 |
api_key = os.getenv('API_KEY')
|
13 |
|
14 |
-
llm =OpenAILike(
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
st.set_page_config(page_title="llama_index_demo", page_icon="������������")
|
19 |
st.title("llama_index_demo")
|
20 |
|
21 |
-
#
|
22 |
@st.cache_resource
|
23 |
def init_models():
|
|
|
24 |
embed_model = HuggingFaceEmbedding(
|
25 |
-
model_name="
|
26 |
)
|
27 |
Settings.embed_model = embed_model
|
28 |
-
|
29 |
-
#用初始化llm
|
30 |
Settings.llm = llm
|
31 |
|
32 |
-
|
|
|
33 |
index = VectorStoreIndex.from_documents(documents)
|
34 |
query_engine = index.as_query_engine()
|
35 |
|
|
|
3 |
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
|
4 |
from llama_index.legacy.callbacks import CallbackManager
|
5 |
from llama_index.llms.openai_like import OpenAILike
|
6 |
+
import os
|
7 |
|
8 |
# Create an instance of CallbackManager
|
9 |
callback_manager = CallbackManager()
|
|
|
12 |
model = "internlm2.5-latest"
|
13 |
api_key = os.getenv('API_KEY')
|
14 |
|
15 |
+
llm = OpenAILike(
|
16 |
+
model=model,
|
17 |
+
api_base=api_base_url,
|
18 |
+
api_key=api_key,
|
19 |
+
is_chat_model=True,
|
20 |
+
callback_manager=callback_manager
|
21 |
+
)
|
22 |
|
23 |
+
st.set_page_config(page_title="llama_index_demo", page_icon="🦙")
|
|
|
|
|
24 |
st.title("llama_index_demo")
|
25 |
|
26 |
+
# 修改初始化模型函数
|
27 |
@st.cache_resource
|
28 |
def init_models():
|
29 |
+
# 使用 Hugging Face Hub 上的模型
|
30 |
embed_model = HuggingFaceEmbedding(
|
31 |
+
model_name="sentence-transformers/all-MiniLM-L6-v2"
|
32 |
)
|
33 |
Settings.embed_model = embed_model
|
|
|
|
|
34 |
Settings.llm = llm
|
35 |
|
36 |
+
# 使用相对路径加载数据
|
37 |
+
documents = SimpleDirectoryReader("data").load_data()
|
38 |
index = VectorStoreIndex.from_documents(documents)
|
39 |
query_engine = index.as_query_engine()
|
40 |
|