BinZhang commited on
Commit
165237e
·
1 Parent(s): 3e029de
Files changed (5) hide show
  1. a.py +0 -48
  2. bank_app.py +0 -31
  3. bank_requirements.txt +0 -1
  4. ok_bank_app.py +0 -85
  5. ok_bank_requirements.txt +0 -112
a.py DELETED
@@ -1,48 +0,0 @@
1
- import os
2
- os.environ['NLTK_DATA'] = '/root/nltk_data'
3
-
4
- from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
5
- from llama_index.core.settings import Settings
6
- from llama_index.embeddings.huggingface import HuggingFaceEmbedding
7
- from llama_index.legacy.callbacks import CallbackManager
8
- from llama_index.llms.openai_like import OpenAILike
9
-
10
-
11
- # Create an instance of CallbackManager
12
- callback_manager = CallbackManager()
13
-
14
- api_base_url = "https://internlm-chat.intern-ai.org.cn/puyu/api/v1/"
15
- model = "internlm2.5-latest"
16
- api_key = "请填写 API Key"
17
-
18
- # api_base_url = "https://api.siliconflow.cn/v1"
19
- # model = "internlm/internlm2_5-7b-chat"
20
- # api_key = "请填写 API Key"
21
-
22
-
23
-
24
- llm =OpenAILike(model=model, api_base=api_base_url, api_key=api_key, is_chat_model=True,callback_manager=callback_manager)
25
-
26
-
27
- #初始化一个HuggingFaceEmbedding对象,用于将文本转换为向量表示
28
- embed_model = HuggingFaceEmbedding(
29
- #指定了一个预训练的sentence-transformer模型的路径
30
- model_name="/root/model/sentence-transformer"
31
- )
32
- #将创建的嵌入模型赋值给全局设置的embed_model属性,
33
- #这样在后续的索引构建过程中就会使用这个模型。
34
- Settings.embed_model = embed_model
35
-
36
- #初始化llm
37
- Settings.llm = llm
38
-
39
- #从指定目录读取所有文档,并加载数据到内存中
40
- documents = SimpleDirectoryReader("/root/llamaindex_demo/data").load_data()
41
- #创建一个VectorStoreIndex,并使用之前加载的文档来构建索引。
42
- # 此索引将文档转换为向量,并存储这些向量以便于快速检索。
43
- index = VectorStoreIndex.from_documents(documents)
44
- # 创建一个查询引擎,这个引擎可以接收查询并返回相关文档的响应。
45
- query_engine = index.as_query_engine()
46
- response = query_engine.query("xtuner是什么?")
47
-
48
- print(response)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bank_app.py DELETED
@@ -1,31 +0,0 @@
1
- import streamlit as st
2
- from openai import OpenAI
3
-
4
- # 设置 API 参数
5
- base_url = "https://internlm-chat.intern-ai.org.cn/puyu/api/v1/"
6
- api_key = "eyJ0eXBlIjoiSldUIiwiYWxnIjoiSFM1MTIifQ.eyJqdGkiOiIxMTIwNDk3OSIsInJvbCI6IlJPTEVfUkVHSVNURVIiLCJpc3MiOiJPcGVuWExhYiIsImlhdCI6MTczMzQxMjU1NCwiY2xpZW50SWQiOiJlYm1ydm9kNnlvMG5semFlazF5cCIsInBob25lIjoiMTUxMzcxMTY1MzEiLCJ1dWlkIjoiYmVlYTk0NTQtNWE5OS00OGNkLTgxNzctZDdjZWYzNmQwNTAxIiwiZW1haWwiOiIiLCJleHAiOjE3NDg5NjQ1NTR9.0-DNSkviINNJhGmx49-kUfTSRvyXNrT4LXU1sB01FprErwGCVinJStN5aNsaHjF2K95Pl7B15SQ_fa2l8cIT3Q"
7
- model = "internlm2.5-latest"
8
-
9
- # 创建 OpenAI 客户端
10
- client = OpenAI(
11
- api_key=api_key,
12
- base_url=base_url,
13
- )
14
-
15
- # 设置页面标题
16
- st.title("Chat with InternLM")
17
-
18
- # 创建一个文本输入框供用户输入问题
19
- user_input = st.text_input("请输入你的问题:")
20
-
21
- # 按钮用于提交问题
22
- if st.button("发送"):
23
- # 调用 OpenAI API 获取回复
24
- chat_rsp = client.chat.completions.create(
25
- model=model,
26
- messages=[{"role": "user", "content": user_input}],
27
- )
28
-
29
- # 显示回复
30
- for choice in chat_rsp.choices:
31
- st.write(f"回复: {choice.message.content}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bank_requirements.txt DELETED
@@ -1 +0,0 @@
1
- openai
 
 
ok_bank_app.py DELETED
@@ -1,85 +0,0 @@
1
- import streamlit as st
2
- 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
- from dotenv import load_dotenv
7
- import os
8
- load_dotenv()
9
- # Create an instance of CallbackManager
10
- callback_manager = CallbackManager()
11
-
12
- api_base_url = "https://internlm-chat.intern-ai.org.cn/puyu/api/v1/"
13
- model = "internlm2.5-latest"
14
- api_key = os.getenv("MY_API_KEY")
15
-
16
- # api_base_url = "https://api.siliconflow.cn/v1"
17
- # model = "internlm/internlm2_5-7b-chat"
18
- # api_key = "请填写 API Key"
19
-
20
- llm =OpenAILike(model=model, api_base=api_base_url, api_key=api_key, is_chat_model=True,callback_manager=callback_manager)
21
-
22
-
23
-
24
- st.set_page_config(page_title="llama_index_demo", page_icon="🦜🔗")
25
- st.title("llama_index_demo")
26
-
27
- # 初始化模型
28
- @st.cache_resource
29
- def init_models():
30
- embed_model = HuggingFaceEmbedding(
31
- model_name="sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2"
32
- )
33
- Settings.embed_model = embed_model
34
-
35
- #用初始化llm
36
- Settings.llm = llm
37
-
38
- documents = SimpleDirectoryReader("./data").load_data()
39
- index = VectorStoreIndex.from_documents(documents)
40
- query_engine = index.as_query_engine()
41
-
42
- return query_engine
43
-
44
- # 检查是否需要初始化模型
45
- if 'query_engine' not in st.session_state:
46
- st.session_state['query_engine'] = init_models()
47
-
48
- def greet2(question):
49
- response = st.session_state['query_engine'].query(question)
50
- return response
51
-
52
-
53
- # Store LLM generated responses
54
- if "messages" not in st.session_state.keys():
55
- st.session_state.messages = [{"role": "assistant", "content": "你好,我是你的助手,有什么我可以帮助你的吗?"}]
56
-
57
- # Display or clear chat messages
58
- for message in st.session_state.messages:
59
- with st.chat_message(message["role"]):
60
- st.write(message["content"])
61
-
62
- def clear_chat_history():
63
- st.session_state.messages = [{"role": "assistant", "content": "你好,我是你的助手,有什么我可以帮助你的吗?"}]
64
-
65
- st.sidebar.button('Clear Chat History', on_click=clear_chat_history)
66
-
67
- # Function for generating LLaMA2 response
68
- def generate_llama_index_response(prompt_input):
69
- return greet2(prompt_input)
70
-
71
- # User-provided prompt
72
- if prompt := st.chat_input():
73
- st.session_state.messages.append({"role": "user", "content": prompt})
74
- with st.chat_message("user"):
75
- st.write(prompt)
76
-
77
- # Gegenerate_llama_index_response last message is not from assistant
78
- if st.session_state.messages[-1]["role"] != "assistant":
79
- with st.chat_message("assistant"):
80
- with st.spinner("Thinking..."):
81
- response = generate_llama_index_response(prompt)
82
- placeholder = st.empty()
83
- placeholder.markdown(response)
84
- message = {"role": "assistant", "content": response}
85
- st.session_state.messages.append(message)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ok_bank_requirements.txt DELETED
@@ -1,112 +0,0 @@
1
- aiohappyeyeballs==2.4.3
2
- aiohttp==3.11.8
3
- aiosignal==1.3.1
4
- annotated-types==0.7.0
5
- anyio==4.6.2.post1
6
- async-timeout==5.0.1
7
- attrs==24.2.0
8
- beautifulsoup4==4.12.3
9
- certifi==2024.8.30
10
- charset-normalizer==3.4.0
11
- click==8.1.7
12
- dataclasses-json==0.6.7
13
- Deprecated==1.2.15
14
- dirtyjson==1.0.8
15
- distro==1.9.0
16
- einops==0.7.0
17
- exceptiongroup==1.2.2
18
- filelock==3.16.1
19
- filetype==1.2.0
20
- frozenlist==1.5.0
21
- fsspec==2024.10.0
22
- greenlet==3.1.1
23
- h11==0.14.0
24
- httpcore==1.0.7
25
- httpx==0.28.0
26
- huggingface-hub==0.26.3
27
- idna==3.10
28
- InstructorEmbedding==1.0.1
29
- Jinja2==3.1.4
30
- jiter==0.8.0
31
- joblib==1.4.2
32
- llama-cloud==0.1.5
33
- llama-index==0.11.20
34
- llama-index-agent-openai==0.3.4
35
- llama-index-cli==0.3.1
36
- llama-index-core==0.11.23
37
- llama-index-embeddings-huggingface==0.3.1
38
- llama-index-embeddings-instructor==0.2.1
39
- llama-index-embeddings-openai==0.2.5
40
- llama-index-indices-managed-llama-cloud==0.6.0
41
- llama-index-legacy==0.9.48.post4
42
- llama-index-llms-openai==0.2.16
43
- llama-index-llms-openai-like==0.2.0
44
- llama-index-llms-replicate==0.3.0
45
- llama-index-multi-modal-llms-openai==0.2.3
46
- llama-index-program-openai==0.2.0
47
- llama-index-question-gen-openai==0.2.0
48
- llama-index-readers-file==0.2.2
49
- llama-index-readers-llama-parse==0.3.0
50
- llama-parse==0.5.15
51
- MarkupSafe==3.0.2
52
- marshmallow==3.23.1
53
- mpmath==1.3.0
54
- multidict==6.1.0
55
- mypy-extensions==1.0.0
56
- nest-asyncio==1.6.0
57
- networkx==3.4.2
58
- nltk==3.9.1
59
- numpy==1.26.4
60
- # nvidia-cublas-cu12==12.1.3.1
61
- # nvidia-cuda-cupti-cu12==12.1.105
62
- # nvidia-cuda-nvrtc-cu12==12.1.105
63
- # nvidia-cuda-runtime-cu12==12.1.105
64
- # nvidia-cudnn-cu12==9.1.0.70
65
- # nvidia-cufft-cu12==11.0.2.54
66
- # nvidia-curand-cu12==10.3.2.106
67
- # nvidia-cusolver-cu12==11.4.5.107
68
- # nvidia-cusparse-cu12==12.1.0.106
69
- # nvidia-nccl-cu12==2.21.5
70
- # nvidia-nvjitlink-cu12==12.4.127
71
- # nvidia-nvtx-cu12==12.1.105
72
- openai==1.55.3
73
- packaging==24.2
74
- pandas==2.2.3
75
- pillow==11.0.0
76
- propcache==0.2.0
77
- protobuf==5.26.1
78
- pydantic==2.10.2
79
- pydantic_core==2.27.1
80
- pypdf==4.3.1
81
- python-dateutil==2.9.0.post0
82
- python-dotenv==1.0.1
83
- pytz==2024.2
84
- PyYAML==6.0.2
85
- regex==2024.11.6
86
- requests==2.32.3
87
- safetensors==0.4.5
88
- scikit-learn==1.5.2
89
- scipy==1.14.1
90
- sentence-transformers==2.7.0
91
- six==1.16.0
92
- sniffio==1.3.1
93
- soupsieve==2.6
94
- SQLAlchemy==2.0.36
95
- striprtf==0.0.26
96
- sympy==1.13.1
97
- tenacity==8.5.0
98
- threadpoolctl==3.5.0
99
- tiktoken==0.8.0
100
- tokenizers==0.20.3
101
- torch==2.5.0
102
- torchaudio==2.5.0
103
- torchvision==0.20.0
104
- tqdm==4.67.1
105
- transformers==4.46.3
106
- triton==3.1.0
107
- typing-inspect==0.9.0
108
- typing_extensions==4.12.2
109
- tzdata==2024.2
110
- urllib3==2.2.3
111
- wrapt==1.17.0
112
- yarl==1.18.0