Spaces:
Running
Running
johnnygreco
commited on
Commit
β’
4c9d927
1
Parent(s):
336d893
remove model option
Browse files
app.py
CHANGED
@@ -5,7 +5,6 @@ import hpqa
|
|
5 |
from langchain.chains import RetrievalQA
|
6 |
from langchain_core.vectorstores import VectorStoreRetriever
|
7 |
from langchain_openai import OpenAI
|
8 |
-
from openai import OpenAI as OpenAIClient
|
9 |
|
10 |
os.environ["OPENAI_API_KEY"] = ""
|
11 |
index_path = "data/hpqa_faiss_index_500"
|
@@ -21,19 +20,12 @@ examples = [
|
|
21 |
]
|
22 |
|
23 |
|
24 |
-
def api(question, temperature,
|
25 |
if api_key is None or len(api_key) == 0:
|
26 |
return "You must provide an OpenAI API key to use this demo π"
|
27 |
if len(question) == 0:
|
28 |
return ""
|
29 |
document_store = hpqa.load_document_store(index_path, openai_api_key=api_key)
|
30 |
-
|
31 |
-
client = OpenAIClient(api_key=api_key)
|
32 |
-
models = [m.id for m in client.models.list().data if "gpt" in m.id if "vision" not in m.id]
|
33 |
-
if model not in models:
|
34 |
-
model_list = "\n".join(models)
|
35 |
-
return f"π¬ {model} not a valid model name. Choose from:\n\n{model_list}"
|
36 |
-
|
37 |
chain = RetrievalQA.from_llm(
|
38 |
llm=OpenAI(temperature=temperature, openai_api_key=api_key),
|
39 |
retriever=VectorStoreRetriever(vectorstore=document_store),
|
@@ -55,10 +47,8 @@ with demo:
|
|
55 |
btn = gr.Button("Submit", variant="primary")
|
56 |
with gr.Column():
|
57 |
answer = gr.Textbox(lines=4, label="Answer")
|
58 |
-
|
59 |
-
|
60 |
-
openai_api_key = gr.Textbox(type="password", label="OpenAI API key")
|
61 |
-
btn.click(api, [question, temperature, model, openai_api_key], answer)
|
62 |
clear.click(lambda _: "", question, question)
|
63 |
gr.Examples(examples, question)
|
64 |
gr.Markdown("π» Checkout the `hpqa` source code on [GitHub](https://github.com/johnnygreco/hpqa).")
|
|
|
5 |
from langchain.chains import RetrievalQA
|
6 |
from langchain_core.vectorstores import VectorStoreRetriever
|
7 |
from langchain_openai import OpenAI
|
|
|
8 |
|
9 |
os.environ["OPENAI_API_KEY"] = ""
|
10 |
index_path = "data/hpqa_faiss_index_500"
|
|
|
20 |
]
|
21 |
|
22 |
|
23 |
+
def api(question, temperature, api_key=None):
|
24 |
if api_key is None or len(api_key) == 0:
|
25 |
return "You must provide an OpenAI API key to use this demo π"
|
26 |
if len(question) == 0:
|
27 |
return ""
|
28 |
document_store = hpqa.load_document_store(index_path, openai_api_key=api_key)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
chain = RetrievalQA.from_llm(
|
30 |
llm=OpenAI(temperature=temperature, openai_api_key=api_key),
|
31 |
retriever=VectorStoreRetriever(vectorstore=document_store),
|
|
|
47 |
btn = gr.Button("Submit", variant="primary")
|
48 |
with gr.Column():
|
49 |
answer = gr.Textbox(lines=4, label="Answer")
|
50 |
+
openai_api_key = gr.Textbox(type="password", label="OpenAI API key")
|
51 |
+
btn.click(api, [question, temperature, openai_api_key], answer)
|
|
|
|
|
52 |
clear.click(lambda _: "", question, question)
|
53 |
gr.Examples(examples, question)
|
54 |
gr.Markdown("π» Checkout the `hpqa` source code on [GitHub](https://github.com/johnnygreco/hpqa).")
|