File tree Expand file tree Collapse file tree 5 files changed +11
-10
lines changed Expand file tree Collapse file tree 5 files changed +11
-10
lines changed Original file line number Diff line number Diff line change 5
5
os .chdir (os .path .dirname (os .path .abspath (__file__ )))
6
6
os .environ ['SERPAPI_API_KEY' ] = ''
7
7
8
- import langchain
9
8
import streamlit as st
10
- from langchain .cache import InMemoryCache
11
9
from streamlit import logger
12
10
from streamlit_chat import message
13
11
14
12
from docGPT import GPT4Free , create_doc_gpt
15
13
from model import DocumentLoader
16
14
17
- langchain .llm_cache = InMemoryCache ()
18
-
19
15
OPENAI_API_KEY = ''
20
16
SERPAPI_API_KEY = ''
21
17
model = None
Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ def create_doc_gpt(
39
39
docGPT .create_qa_chain (chain_type = 'refine' , verbose = False )
40
40
docGPT_tool = agent_ .create_doc_chat (docGPT )
41
41
calculate_tool = agent_ .get_calculate_chain
42
- llm_tool = agent_ .create_llm_chain ()
42
+ # llm_tool = agent_.create_llm_chain()
43
43
44
44
if SerpAPI .is_valid ():
45
45
search_tool = agent_ .get_searp_chain
Original file line number Diff line number Diff line change 2
2
from typing import Optional
3
3
4
4
import openai
5
- from langchain import LLMMathChain , SerpAPIWrapper
6
5
from langchain .agents import AgentType , Tool , initialize_agent
7
6
from langchain .callbacks import get_openai_callback
8
7
from langchain .chains import LLMChain
@@ -29,6 +28,8 @@ def llm(self, llm) -> None:
29
28
30
29
@property
31
30
def get_calculate_chain (self ) -> Tool :
31
+ from langchain import LLMMathChain
32
+
32
33
llm_math_chain = LLMMathChain .from_llm (llm = self .llm , verbose = True )
33
34
tool = Tool (
34
35
name = 'Calculator' ,
@@ -39,6 +40,8 @@ def get_calculate_chain(self) -> Tool:
39
40
40
41
@property
41
42
def get_searp_chain (self ) -> Tool :
43
+ from langchain import SerpAPIWrapper
44
+
42
45
search = SerpAPIWrapper ()
43
46
tool = Tool (
44
47
name = 'Search' ,
Original file line number Diff line number Diff line change 3
3
4
4
import openai
5
5
import streamlit as st
6
- from langchain import SerpAPIWrapper
7
6
8
7
9
8
class ApiKey (ABC ):
@@ -45,6 +44,7 @@ def is_valid(cls) -> str:
45
44
if not st .session_state ['serpapi_api_key' ]:
46
45
st .warning ('⚠️ You have not pass SerpAPI key. (You cannot ask current events.)' )
47
46
return
47
+ from langchain import SerpAPIWrapper
48
48
49
49
os .environ ['SERPAPI_API_KEY' ] = os .getenv ('SERPAPI_API_KEY' )
50
50
try :
Original file line number Diff line number Diff line change 7
7
import openai
8
8
from langchain .callbacks import get_openai_callback
9
9
from langchain .callbacks .manager import CallbackManagerForLLMRun
10
- from langchain .chains import ConversationalRetrievalChain , RetrievalQA
10
+ from langchain .chains import RetrievalQA
11
11
from langchain .embeddings import HuggingFaceEmbeddings
12
12
from langchain .embeddings .openai import OpenAIEmbeddings
13
13
from langchain .llms .base import LLM
14
- from langchain .memory import ConversationBufferMemory
15
14
from langchain .prompts import PromptTemplate
16
15
from langchain .vectorstores import FAISS
17
16
from streamlit import logger
@@ -68,8 +67,11 @@ def __init__(
68
67
super ().__init__ (chain_type , retriever , llm )
69
68
70
69
@property
71
- def create_qa_chain (self ) -> ConversationalRetrievalChain :
70
+ def create_qa_chain (self ):
72
71
# TODO: cannot use conversation qa chain
72
+ from langchain .chains import ConversationalRetrievalChain
73
+ from langchain .memory import ConversationBufferMemory
74
+
73
75
memory = ConversationBufferMemory (
74
76
memory_key = 'chat_history' ,
75
77
return_messages = True
You can’t perform that action at this time.
0 commit comments