allinaigc commited on
Commit
e418d71
1 Parent(s): 3bd3dd2

Upload 2 files

Browse files
Files changed (2) hide show
  1. langchain_KB.py +0 -6
  2. rag_reponse_002.py +8 -8
langchain_KB.py CHANGED
@@ -18,15 +18,9 @@ import pathlib
18
  from pathlib import Path
19
  import re
20
  from re import sub
21
- import matplotlib.pyplot as plt
22
- from itertools import product
23
- from tqdm import tqdm_notebook, tqdm, trange
24
  import time
25
  from time import sleep
26
  # import pretty_errors
27
- import seaborn as sns
28
- from matplotlib.pyplot import style
29
- from rich import print
30
  import warnings
31
  import PyPDF2
32
  from openai import OpenAI
 
18
  from pathlib import Path
19
  import re
20
  from re import sub
 
 
 
21
  import time
22
  from time import sleep
23
  # import pretty_errors
 
 
 
24
  import warnings
25
  import PyPDF2
26
  from openai import OpenAI
rag_reponse_002.py CHANGED
@@ -12,18 +12,14 @@ from langchain_core.runnables import RunnableParallel
12
  import streamlit as st
13
  import re
14
  import openai
15
- from openai import OpenAI
16
  import os
17
  from langchain.llms.base import LLM
18
  from langchain.llms.utils import enforce_stop_tokens
19
  from typing import Dict, List, Optional, Tuple, Union
20
- import requests
21
- import json
22
  # import chatgpt
23
  import qwen_response
24
  from dotenv import load_dotenv
25
  import dashscope
26
- # dashscope.api_key = "sk-948adb3e65414e55961a9ad9d22d186b"
27
 
28
  load_dotenv()
29
  ### 设置openai的API key
@@ -35,11 +31,10 @@ dashscope.api_key = os.environ['dashscope_api_key']
35
 
36
  from langchain.embeddings.openai import OpenAIEmbeddings
37
 
38
- embeddings = HuggingFaceEmbeddings(model_name='GanymedeNil/text2vec-large-chinese') ## 这里是联网情况下,部署在Huggingface上后使用。
39
-
40
  # embeddings = OpenAIEmbeddings(disallowed_special=()) ## 这里是联网情况下,部署在Huggingface上后使用。
41
  # embeddings = HuggingFaceEmbeddings(model_name='/Users/yunshi/Downloads/360Data/Data Center/Working-On Task/演讲与培训/2023ChatGPT/Coding/RAG/bge-large-zh') ## 切换成BGE的embedding。
42
- vector_store = FAISS.load_local("./faiss_index/", embeddings=embeddings, allow_dangerous_deserialization=True) ## 加载vector store到本地。
43
  # vector_store = FAISS.load_local("./faiss_index/", embeddings=embeddings) ## 加载vector store到本地。 ### original code here.
44
 
45
  # ## 配置ChatGLM的类与后端api server对应。
@@ -120,8 +115,13 @@ def rag_source(docs):
120
  print('source:', source)
121
  return source
122
 
123
- def rag_response(user_input, k=3):
124
  # docs = vector_store.similarity_search('user_input', k=k) ## Original。
 
 
 
 
 
125
  docs = vector_store.similarity_search(user_input, k=k) ##TODO 'user_input' to user_input?
126
  context = [doc.page_content for doc in docs]
127
  # print('context: {}'.format(context))
 
12
  import streamlit as st
13
  import re
14
  import openai
 
15
  import os
16
  from langchain.llms.base import LLM
17
  from langchain.llms.utils import enforce_stop_tokens
18
  from typing import Dict, List, Optional, Tuple, Union
 
 
19
  # import chatgpt
20
  import qwen_response
21
  from dotenv import load_dotenv
22
  import dashscope
 
23
 
24
  load_dotenv()
25
  ### 设置openai的API key
 
31
 
32
  from langchain.embeddings.openai import OpenAIEmbeddings
33
 
34
+ # embeddings = HuggingFaceEmbeddings(model_name='GanymedeNil/text2vec-large-chinese') ## 这里是联网情况下,部署在Huggingface上后使用。
 
35
  # embeddings = OpenAIEmbeddings(disallowed_special=()) ## 这里是联网情况下,部署在Huggingface上后使用。
36
  # embeddings = HuggingFaceEmbeddings(model_name='/Users/yunshi/Downloads/360Data/Data Center/Working-On Task/演讲与培训/2023ChatGPT/Coding/RAG/bge-large-zh') ## 切换成BGE的embedding。
37
+ # vector_store = FAISS.load_local("./faiss_index/", embeddings=embeddings, allow_dangerous_deserialization=True) ## 加载vector store到本地。
38
  # vector_store = FAISS.load_local("./faiss_index/", embeddings=embeddings) ## 加载vector store到本地。 ### original code here.
39
 
40
  # ## 配置ChatGLM的类与后端api server对应。
 
115
  print('source:', source)
116
  return source
117
 
118
+ def rag_response(username, user_input, k=3):
119
  # docs = vector_store.similarity_search('user_input', k=k) ## Original。
120
+
121
+ embeddings = HuggingFaceEmbeddings(model_name='BAAI/bge-large-zh-v1.5') ## 这里是联网情况下,部署在Huggingface上后使用。
122
+ # embeddings = HuggingFaceEmbeddings(model_name='GanymedeNil/text2vec-large-chinese') ## 这里是联网情况下,部署在Huggingface上后使用。
123
+ print('embeddings:', embeddings)
124
+ vector_store = FAISS.load_local(f"./{username}/faiss_index/", embeddings=embeddings, allow_dangerous_deserialization=True) ## 加载vector store到本地。
125
  docs = vector_store.similarity_search(user_input, k=k) ##TODO 'user_input' to user_input?
126
  context = [doc.page_content for doc in docs]
127
  # print('context: {}'.format(context))