Spaces:
No application file
No application file
BinZhang
commited on
Commit
·
0354509
1
Parent(s):
165237e
dftmsg
Browse files- .env +0 -1
- app.py +0 -52
- requirements.txt +0 -7
.env
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
MY_API_KEY="eyJ0eXBlIjoiSldUIiwiYWxnIjoiSFM1MTIifQ.eyJqdGkiOiIxMTIwNDk3OSIsInJvbCI6IlJPTEVfUkVHSVNURVIiLCJpc3MiOiJPcGVuWExhYiIsImlhdCI6MTczMzQxMjU1NCwiY2xpZW50SWQiOiJlYm1ydm9kNnlvMG5semFlazF5cCIsInBob25lIjoiMTUxMzcxMTY1MzEiLCJ1dWlkIjoiYmVlYTk0NTQtNWE5OS00OGNkLTgxNzctZDdjZWYzNmQwNTAxIiwiZW1haWwiOiIiLCJleHAiOjE3NDg5NjQ1NTR9.0-DNSkviINNJhGmx49-kUfTSRvyXNrT4LXU1sB01FprErwGCVinJStN5aNsaHjF2K95Pl7B15SQ_fa2l8cIT3Q"
|
|
|
|
app.py
DELETED
@@ -1,52 +0,0 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
|
3 |
-
from llama_index.core.settings import Settings
|
4 |
-
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
|
5 |
-
from llama_index.llms.openai_like import OpenAILike
|
6 |
-
import os
|
7 |
-
from dotenv import load_dotenv
|
8 |
-
|
9 |
-
# 加载环境变量
|
10 |
-
load_dotenv()
|
11 |
-
|
12 |
-
# 设置 API 参数
|
13 |
-
base_url = "https://internlm-chat.intern-ai.org.cn/puyu/api/v1/"
|
14 |
-
api_key = os.getenv("MY_API_KEY")
|
15 |
-
model = "internlm2.5-latest"
|
16 |
-
|
17 |
-
# 初始化 LLM
|
18 |
-
llm = OpenAILike(model=model, api_base=base_url, api_key=api_key, is_chat_model=True)
|
19 |
-
|
20 |
-
# 初始化一个 HuggingFaceEmbedding 对象,用于将文本转换为向量表示
|
21 |
-
embed_model = HuggingFaceEmbedding(
|
22 |
-
model_name="sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2"
|
23 |
-
)
|
24 |
-
|
25 |
-
# 将创建的嵌入模型赋值给全局设置的 embed_model 属性
|
26 |
-
Settings.embed_model = embed_model
|
27 |
-
|
28 |
-
# 将创建的 LLM 赋值给全局设置的 llm 属性
|
29 |
-
Settings.llm = llm
|
30 |
-
|
31 |
-
# 从指定目录读取所有文档,并加载数据到内存中
|
32 |
-
documents = SimpleDirectoryReader("./data").load_data()
|
33 |
-
|
34 |
-
# 创建一个 VectorStoreIndex,并使用之前加载的文档来构建索引
|
35 |
-
index = VectorStoreIndex.from_documents(documents)
|
36 |
-
|
37 |
-
# 创建一个查询引擎,这个引擎可以接收查询并返回相关文档的响应
|
38 |
-
query_engine = index.as_query_engine()
|
39 |
-
|
40 |
-
# 设置页面标题
|
41 |
-
st.title("LlamaIndex Chat")
|
42 |
-
|
43 |
-
# 创建一个文本输入框供用户输入问题
|
44 |
-
user_input = st.text_input("请输入你的问题:")
|
45 |
-
|
46 |
-
# 按钮用于提交问题
|
47 |
-
if st.button("发送"):
|
48 |
-
# 使用查询引擎获取回复
|
49 |
-
response = query_engine.query(user_input)
|
50 |
-
|
51 |
-
# 显示回复
|
52 |
-
st.write(f"回复: {response}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requirements.txt
DELETED
@@ -1,7 +0,0 @@
|
|
1 |
-
llama-index
|
2 |
-
llama-index-llms-replicate
|
3 |
-
llama-index-llms-openai-like
|
4 |
-
llama-index-embeddings-huggingface
|
5 |
-
llama-index-embeddings-instructor
|
6 |
-
llama-index-core
|
7 |
-
python-dotenv
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|