Spaces:
Sleeping
Sleeping
依赖冲突太麻烦了
Browse files
.ipynb_checkpoints/download_hf-checkpoint.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
+
# 设置环境变量
|
| 4 |
+
os.environ['HF_ENDPOINT'] = 'https://hf-mirror.com'
|
| 5 |
+
|
| 6 |
+
# 下载模型
|
| 7 |
+
os.system('huggingface-cli download --resume-download sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2 --local-dir /root/model/sentence-transformer')
|
.ipynb_checkpoints/llamaindex_RAG-checkpoint.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 = os.getenv("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("Qwen2Attention是什么?")
|
| 47 |
+
|
| 48 |
+
print(response)
|
.ipynb_checkpoints/requirements-checkpoint.txt
CHANGED
|
@@ -1,119 +1,6 @@
|
|
| 1 |
-
aiohappyeyeballs==2.4.3
|
| 2 |
-
aiohttp==3.11.7
|
| 3 |
-
aiosignal==1.3.1
|
| 4 |
-
altair==5.5.0
|
| 5 |
-
annotated-types==0.7.0
|
| 6 |
-
anyio==4.6.2.post1
|
| 7 |
-
async-timeout==5.0.1
|
| 8 |
-
attrs==24.2.0
|
| 9 |
-
beautifulsoup4==4.12.3
|
| 10 |
-
blinker==1.9.0
|
| 11 |
-
cachetools==5.5.0
|
| 12 |
-
certifi==2024.8.30
|
| 13 |
-
charset-normalizer==3.4.0
|
| 14 |
-
click==8.1.7
|
| 15 |
-
dataclasses-json==0.6.7
|
| 16 |
-
deprecated==1.2.15
|
| 17 |
-
dirtyjson==1.0.8
|
| 18 |
-
distro==1.9.0
|
| 19 |
-
einops==0.7.0
|
| 20 |
-
exceptiongroup==1.2.2
|
| 21 |
-
filelock==3.16.1
|
| 22 |
-
filetype==1.2.0
|
| 23 |
-
frozenlist==1.5.0
|
| 24 |
-
fsspec==2024.10.0
|
| 25 |
-
gitdb==4.0.11
|
| 26 |
-
gitpython==3.1.43
|
| 27 |
-
greenlet==3.1.1
|
| 28 |
-
h11==0.14.0
|
| 29 |
-
httpcore==1.0.7
|
| 30 |
-
httpx==0.27.2
|
| 31 |
-
huggingface-hub==0.26.2
|
| 32 |
-
idna==3.10
|
| 33 |
-
instructorembedding==1.0.1
|
| 34 |
-
jinja2==3.1.4
|
| 35 |
-
jiter==0.7.1
|
| 36 |
-
joblib==1.4.2
|
| 37 |
-
jsonschema==4.23.0
|
| 38 |
-
jsonschema-specifications==2024.10.1
|
| 39 |
-
llama-cloud==0.1.5
|
| 40 |
llama-index==0.11.20
|
| 41 |
-
llama-index-
|
| 42 |
-
llama-index-
|
| 43 |
-
llama-index-core==0.11.23
|
| 44 |
llama-index-embeddings-huggingface==0.3.1
|
| 45 |
llama-index-embeddings-instructor==0.2.1
|
| 46 |
-
|
| 47 |
-
llama-index-indices-managed-llama-cloud==0.6.0
|
| 48 |
-
llama-index-legacy==0.9.48.post4
|
| 49 |
-
llama-index-llms-openai==0.2.16
|
| 50 |
-
llama-index-llms-openai-like==0.2.0
|
| 51 |
-
llama-index-llms-replicate==0.3.0
|
| 52 |
-
llama-index-multi-modal-llms-openai==0.2.3
|
| 53 |
-
llama-index-program-openai==0.2.0
|
| 54 |
-
llama-index-question-gen-openai==0.2.0
|
| 55 |
-
llama-index-readers-file==0.2.2
|
| 56 |
-
llama-index-readers-llama-parse==0.3.0
|
| 57 |
-
llama-parse==0.5.15
|
| 58 |
-
markdown-it-py==3.0.0
|
| 59 |
-
markupsafe==3.0.2
|
| 60 |
-
marshmallow==3.23.1
|
| 61 |
-
mdurl==0.1.2
|
| 62 |
-
mpmath==1.3.0
|
| 63 |
-
multidict==6.1.0
|
| 64 |
-
mypy-extensions==1.0.0
|
| 65 |
-
narwhals==1.14.2
|
| 66 |
-
nest-asyncio==1.6.0
|
| 67 |
-
networkx==3.4.2
|
| 68 |
-
nltk==3.9.1
|
| 69 |
-
numpy==1.26.4
|
| 70 |
-
openai==1.55.0
|
| 71 |
-
packaging==24.2
|
| 72 |
-
pandas==2.2.3
|
| 73 |
-
pillow==10.4.0
|
| 74 |
-
propcache==0.2.0
|
| 75 |
-
protobuf==5.26.1
|
| 76 |
-
pyarrow==18.0.0
|
| 77 |
-
pydantic==2.10.1
|
| 78 |
-
pydantic-core==2.27.1
|
| 79 |
-
pydeck==0.9.1
|
| 80 |
-
pygments==2.18.0
|
| 81 |
-
pypdf==4.3.1
|
| 82 |
-
python-dateutil==2.9.0.post0
|
| 83 |
-
pytz==2024.2
|
| 84 |
-
pyyaml==6.0.2
|
| 85 |
-
referencing==0.35.1
|
| 86 |
-
regex==2024.11.6
|
| 87 |
-
requests==2.32.3
|
| 88 |
-
rich==13.9.4
|
| 89 |
-
rpds-py==0.21.0
|
| 90 |
-
safetensors==0.4.5
|
| 91 |
-
scikit-learn==1.5.2
|
| 92 |
-
scipy==1.14.1
|
| 93 |
-
sentence-transformers==2.7.0
|
| 94 |
-
six==1.16.0
|
| 95 |
-
smmap==5.0.1
|
| 96 |
-
sniffio==1.3.1
|
| 97 |
-
soupsieve==2.6
|
| 98 |
-
sqlalchemy==2.0.36
|
| 99 |
-
streamlit==1.39.0
|
| 100 |
-
striprtf==0.0.26
|
| 101 |
-
sympy==1.13.1
|
| 102 |
-
tenacity==8.5.0
|
| 103 |
-
threadpoolctl==3.5.0
|
| 104 |
-
tiktoken==0.8.0
|
| 105 |
-
tokenizers==0.13.3
|
| 106 |
-
torch==2.1.2
|
| 107 |
-
torchaudio==2.1.2
|
| 108 |
-
torchvision==0.16.0
|
| 109 |
-
tornado==6.4.2
|
| 110 |
-
tqdm==4.67.1
|
| 111 |
-
transformers==4.46.3
|
| 112 |
-
triton
|
| 113 |
-
typing-extensions==4.12.2
|
| 114 |
-
typing-inspect==0.9.0
|
| 115 |
-
tzdata==2024.2
|
| 116 |
-
urllib3==2.2.3
|
| 117 |
-
watchdog==5.0.3
|
| 118 |
-
wrapt==1.17.0
|
| 119 |
-
yarl==1.18.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
llama-index==0.11.20
|
| 2 |
+
llama-index-llms-replicate==0.3.0
|
| 3 |
+
llama-index-llms-openai-like==0.2.0
|
|
|
|
| 4 |
llama-index-embeddings-huggingface==0.3.1
|
| 5 |
llama-index-embeddings-instructor==0.2.1
|
| 6 |
+
streamlit==1.39.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.ipynb_checkpoints/test_internlm-checkpoint.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from openai import OpenAI
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
base_url = "https://internlm-chat.intern-ai.org.cn/puyu/api/v1/"
|
| 5 |
+
# api_key = "sk-请填写准确的 token!"
|
| 6 |
+
api_key = os.getenv("API_KEY")
|
| 7 |
+
model="internlm2.5-latest"
|
| 8 |
+
|
| 9 |
+
# base_url = "https://api.siliconflow.cn/v1"
|
| 10 |
+
# api_key = "sk-请填写准确的 token!"
|
| 11 |
+
# model="internlm/internlm2_5-7b-chat"
|
| 12 |
+
|
| 13 |
+
client = OpenAI(
|
| 14 |
+
api_key=api_key ,
|
| 15 |
+
base_url=base_url,
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
chat_rsp = client.chat.completions.create(
|
| 19 |
+
model=model,
|
| 20 |
+
messages=[{"role": "user", "content": "Qwen2Attention是什么?"}],
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
for choice in chat_rsp.choices:
|
| 24 |
+
print(choice.message.content)
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
llama-index==0.11.20
|
| 2 |
+
llama-index-llms-replicate==0.3.0
|
| 3 |
+
llama-index-llms-openai-like==0.2.0
|
| 4 |
+
llama-index-embeddings-huggingface==0.3.1
|
| 5 |
+
llama-index-embeddings-instructor==0.2.1
|
| 6 |
+
streamlit==1.39.0
|