Halo
commited on
Commit
•
f609c59
1
Parent(s):
e22d962
Update app
Browse files
app.py
CHANGED
@@ -99,11 +99,11 @@ def load_recommender(path, start_page=1):
|
|
99 |
return 'Corpus Loaded.'
|
100 |
|
101 |
|
102 |
-
def generate_text(openAI_key,prompt,
|
103 |
openai.api_key = openAI_key
|
104 |
-
if
|
105 |
completions = openai.ChatCompletion.create(
|
106 |
-
model=
|
107 |
messages=[
|
108 |
{"role": "system", "content": prompt},
|
109 |
{"role": "user", "content": question},
|
@@ -112,7 +112,7 @@ def generate_text(openAI_key,prompt, engine="text-davinci-003"):
|
|
112 |
message = completions['choices'][0]['message']['content']
|
113 |
else:
|
114 |
completions = openai.Completion.create(
|
115 |
-
engine=
|
116 |
prompt=prompt,
|
117 |
max_tokens=512,
|
118 |
n=1,
|
@@ -140,7 +140,7 @@ def generate_answer(question, openAI_key, model_name):
|
|
140 |
"answer should be short and concise. \n\nQuery: {question}\nAnswer: "
|
141 |
|
142 |
prompt += f"Query: {question}\nAnswer:"
|
143 |
-
answer = generate_text(openAI_key, prompt,
|
144 |
return answer
|
145 |
|
146 |
|
@@ -200,4 +200,4 @@ with gr.Blocks() as demo:
|
|
200 |
|
201 |
btn.click(question_answer, inputs=[url, file, question, openAI_key, model_name], outputs=[answer])
|
202 |
#openai.api_key = os.getenv('Your_Key_Here')
|
203 |
-
demo.launch()
|
|
|
99 |
return 'Corpus Loaded.'
|
100 |
|
101 |
|
102 |
+
def generate_text(openAI_key, prompt, model_name="text-davinci-003"):
|
103 |
openai.api_key = openAI_key
|
104 |
+
if model_name.startswith('gpt'):
|
105 |
completions = openai.ChatCompletion.create(
|
106 |
+
model=model_name,
|
107 |
messages=[
|
108 |
{"role": "system", "content": prompt},
|
109 |
{"role": "user", "content": question},
|
|
|
112 |
message = completions['choices'][0]['message']['content']
|
113 |
else:
|
114 |
completions = openai.Completion.create(
|
115 |
+
engine=model_name,
|
116 |
prompt=prompt,
|
117 |
max_tokens=512,
|
118 |
n=1,
|
|
|
140 |
"answer should be short and concise. \n\nQuery: {question}\nAnswer: "
|
141 |
|
142 |
prompt += f"Query: {question}\nAnswer:"
|
143 |
+
answer = generate_text(openAI_key, prompt, model_name)
|
144 |
return answer
|
145 |
|
146 |
|
|
|
200 |
|
201 |
btn.click(question_answer, inputs=[url, file, question, openAI_key, model_name], outputs=[answer])
|
202 |
#openai.api_key = os.getenv('Your_Key_Here')
|
203 |
+
demo.launch(share=True)
|