Volko
commited on
Commit
•
f6a270c
1
Parent(s):
a58f539
Added GPT-4(untested)
Browse files
app.py
CHANGED
@@ -5,19 +5,35 @@ import gradio as gr
|
|
5 |
from threading import Lock
|
6 |
|
7 |
from langchain.llms import OpenAI
|
8 |
-
from langchain.
|
|
|
9 |
from template import QA_PROMPT, CONDENSE_QUESTION_PROMPT
|
10 |
from pdf2vectorstore import convert_to_vectorstore
|
11 |
|
12 |
def get_chain(api_key, vectorstore, model_name):
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
def set_openai_api_key(api_key: str, vectorstore, model_name: str):
|
23 |
if api_key:
|
@@ -108,8 +124,8 @@ with block:
|
|
108 |
)
|
109 |
with gr.Column(width="auto"):
|
110 |
model_dropdown = gr.Dropdown(
|
111 |
-
label="Choose a model
|
112 |
-
choices=["gpt-3.5-turbo"],
|
113 |
)
|
114 |
|
115 |
chatbot = gr.Chatbot()
|
@@ -138,8 +154,9 @@ with block:
|
|
138 |
<p>ArxivGPT is a chatbot that answers questions about research papers. It uses a pretrained GPT-3.5 model to generate answers.</p>
|
139 |
<p>Currently, it can answer questions about the paper you just linked.</p>
|
140 |
<p>It's still in development, so please report any bugs you find. It can take up to a minute to start a conversation for every new paper as there is a parsing delay.</p>
|
141 |
-
<p>The answers can be quite limited as there is a 4096 token limit for GPT-3.5, hence
|
142 |
-
<p>
|
|
|
143 |
</div>
|
144 |
<style>
|
145 |
p {
|
|
|
5 |
from threading import Lock
|
6 |
|
7 |
from langchain.llms import OpenAI
|
8 |
+
from langchain.chat_models import ChatOpenAI
|
9 |
+
from langchain.chains import ChatVectorDBChain, ConversationalRetrievalChain
|
10 |
from template import QA_PROMPT, CONDENSE_QUESTION_PROMPT
|
11 |
from pdf2vectorstore import convert_to_vectorstore
|
12 |
|
13 |
def get_chain(api_key, vectorstore, model_name):
|
14 |
+
if model_name == "gpt-4":
|
15 |
+
llm = ChatOpenAI(model_name = model_name, temperature=0, openai_api_key=api_key)
|
16 |
+
retriever = vectorstore.as_retriever()
|
17 |
+
retriever.search_kwargs['distance_metric'] = 'cos'
|
18 |
+
retriever.search_kwargs['fetch_k'] = 100
|
19 |
+
retriever.search_kwargs['maximal_marginal_relevance'] = True
|
20 |
+
retriever.search_kwargs['k'] = 10
|
21 |
+
qa_chain = ConversationalRetrievalChain.from_llm(
|
22 |
+
llm,
|
23 |
+
retriever,
|
24 |
+
qa_prompt=QA_PROMPT,
|
25 |
+
condense_question_prompt=CONDENSE_QUESTION_PROMPT,
|
26 |
+
)
|
27 |
+
return qa_chain
|
28 |
+
else:
|
29 |
+
llm = OpenAI(model_name = model_name, temperature=0, openai_api_key=api_key)
|
30 |
+
qa_chain = ChatVectorDBChain.from_llm(
|
31 |
+
llm,
|
32 |
+
vectorstore,
|
33 |
+
qa_prompt=QA_PROMPT,
|
34 |
+
condense_question_prompt=CONDENSE_QUESTION_PROMPT,
|
35 |
+
)
|
36 |
+
return qa_chain
|
37 |
|
38 |
def set_openai_api_key(api_key: str, vectorstore, model_name: str):
|
39 |
if api_key:
|
|
|
124 |
)
|
125 |
with gr.Column(width="auto"):
|
126 |
model_dropdown = gr.Dropdown(
|
127 |
+
label="Choose a model",
|
128 |
+
choices=["gpt-3.5-turbo", "gpt-4"],
|
129 |
)
|
130 |
|
131 |
chatbot = gr.Chatbot()
|
|
|
154 |
<p>ArxivGPT is a chatbot that answers questions about research papers. It uses a pretrained GPT-3.5 model to generate answers.</p>
|
155 |
<p>Currently, it can answer questions about the paper you just linked.</p>
|
156 |
<p>It's still in development, so please report any bugs you find. It can take up to a minute to start a conversation for every new paper as there is a parsing delay.</p>
|
157 |
+
<p>The answers can be quite limited as there is a 4096 token limit for GPT-3.5, hence wait for GPT-4 access for better quality.</p>
|
158 |
+
<p>If you don't get a response for GPT-4, it is likely that you don't have API access, try 3.5</p>
|
159 |
+
<p>Possible upgrades coming up: faster parsing, status messages, other research paper hubs.</p>
|
160 |
</div>
|
161 |
<style>
|
162 |
p {
|