1 安装Ollama和Embedding模型

1
2
3
4
sudo pacman -S ollama
systemctl start ollama.service

ollama pull mofanke/acge_text_embedding

2 创建对应python环境

1
2
3
4
5
6
7
conda create -n RAGLLM
pip install -U langchain_community tiktoken langchain-openai langchainhub chromadb langchain
pip install sentence-transformers
pip install huggingface_hub
pip install ipywidgets
pip install unstructured
pip install sentencepiece

3 编写第一个RAG程序

参考链接:https://github.com/langchain-ai/rag-from-scratch/blob/main/rag_from_scratch_1_to_4.ipynb

汉化版本链接:https://techdiylife.github.io/blog/topic.html?category2=t07&blogid=0050

对于LangChain调用第三方API的方法:

1
2
3
4
5
6
from langchain import OpenAI
llm=OpenAI(
    temperature=0.7,
    openai_api_key='sk-cXdcebxeIfU9f4tG7e558fF96c35419bB3D66f4e196e8128',
    openai_api_base='https://api.bianxieai.com/v1'
)

第三方API使用: