Update app.py
Browse files
app.py
CHANGED
|
@@ -19,6 +19,7 @@ def get_answer(
|
|
| 19 |
messages.append({"role": "assistant", "content": answer})
|
| 20 |
messages.append({"role": "user", "content": user_query})
|
| 21 |
|
|
|
|
| 22 |
thread = client.beta.threads.create(
|
| 23 |
messages=messages
|
| 24 |
)
|
|
@@ -30,6 +31,18 @@ def get_answer(
|
|
| 30 |
model=model
|
| 31 |
)
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
while True:
|
| 34 |
run = client.beta.threads.runs.retrieve(
|
| 35 |
thread_id=thread.id,
|
|
@@ -66,6 +79,12 @@ def get_answer(
|
|
| 66 |
if file_url.endswith('.txt'):
|
| 67 |
file_url = file_url[:len(file_url) - 4]
|
| 68 |
citations.append(f'[{index + 1}] {file_url}')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
text_reply += '\n' + '\n'.join(citations)
|
| 71 |
|
|
@@ -74,7 +93,7 @@ def get_answer(
|
|
| 74 |
# TODO delete thread / messages
|
| 75 |
|
| 76 |
return "", chat_history
|
| 77 |
-
|
| 78 |
|
| 79 |
if __name__ == '__main__':
|
| 80 |
|
|
@@ -148,13 +167,44 @@ if __name__ == '__main__':
|
|
| 148 |
examples=example_questions,
|
| 149 |
inputs=[msg],
|
| 150 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
|
| 152 |
msg.submit(
|
| 153 |
-
get_answer, [msg, chatbot], [msg, chatbot],
|
| 154 |
show_progress='minimal',
|
| 155 |
show_api=False
|
| 156 |
)
|
| 157 |
-
go_btn.click(fn=get_answer, inputs=[msg, chatbot], outputs=[msg, chatbot],
|
| 158 |
api_name="qa")
|
| 159 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
demo.launch(auth=(os.getenv("APPUSER"), os.getenv("APPPW")), share=True)
|
|
|
|
| 19 |
messages.append({"role": "assistant", "content": answer})
|
| 20 |
messages.append({"role": "user", "content": user_query})
|
| 21 |
|
| 22 |
+
|
| 23 |
thread = client.beta.threads.create(
|
| 24 |
messages=messages
|
| 25 |
)
|
|
|
|
| 31 |
model=model
|
| 32 |
)
|
| 33 |
|
| 34 |
+
"""
|
| 35 |
+
run = client.beta.threads.create_and_run(
|
| 36 |
+
assistant_id=assistant.id,
|
| 37 |
+
model=model,
|
| 38 |
+
thread={
|
| 39 |
+
"messages": [
|
| 40 |
+
{"role": "user", "content": user_query}
|
| 41 |
+
]
|
| 42 |
+
}
|
| 43 |
+
)
|
| 44 |
+
"""
|
| 45 |
+
|
| 46 |
while True:
|
| 47 |
run = client.beta.threads.runs.retrieve(
|
| 48 |
thread_id=thread.id,
|
|
|
|
| 79 |
if file_url.endswith('.txt'):
|
| 80 |
file_url = file_url[:len(file_url) - 4]
|
| 81 |
citations.append(f'[{index + 1}] {file_url}')
|
| 82 |
+
"""
|
| 83 |
+
if file_citation.quote:
|
| 84 |
+
citations.append(f'[{index + 1}] {file_citation.quote} from {file_url}')
|
| 85 |
+
else:
|
| 86 |
+
citations.append(f'[{index + 1}] {file_url}')
|
| 87 |
+
"""
|
| 88 |
|
| 89 |
text_reply += '\n' + '\n'.join(citations)
|
| 90 |
|
|
|
|
| 93 |
# TODO delete thread / messages
|
| 94 |
|
| 95 |
return "", chat_history
|
| 96 |
+
#return text_reply
|
| 97 |
|
| 98 |
if __name__ == '__main__':
|
| 99 |
|
|
|
|
| 167 |
examples=example_questions,
|
| 168 |
inputs=[msg],
|
| 169 |
)
|
| 170 |
+
model = gr.Radio(
|
| 171 |
+
choices=['gpt-4o-mini'],
|
| 172 |
+
value='gpt-4o-mini',
|
| 173 |
+
label='Model choice'
|
| 174 |
+
)
|
| 175 |
|
| 176 |
msg.submit(
|
| 177 |
+
get_answer, [msg, chatbot, model], [msg, chatbot],
|
| 178 |
show_progress='minimal',
|
| 179 |
show_api=False
|
| 180 |
)
|
| 181 |
+
go_btn.click(fn=get_answer, inputs=[msg, chatbot, model], outputs=[msg, chatbot],
|
| 182 |
api_name="qa")
|
| 183 |
|
| 184 |
+
"""
|
| 185 |
+
with gr.Row():
|
| 186 |
+
|
| 187 |
+
with gr.Column():
|
| 188 |
+
user_query = gr.Textbox(label="Frage")
|
| 189 |
+
examples = gr.Examples(
|
| 190 |
+
examples=example_questions,
|
| 191 |
+
inputs=[user_query],
|
| 192 |
+
)
|
| 193 |
+
gr.ClearButton(components=[user_query])
|
| 194 |
+
model = gr.Radio(
|
| 195 |
+
choices=['gpt-3.5-turbo', 'gpt-4o', 'gpt-4-turbo'],
|
| 196 |
+
value='gpt-3.5-turbo',
|
| 197 |
+
label='Model choice'
|
| 198 |
+
)
|
| 199 |
+
go_btn = gr.Button("Los!", variant='primary')
|
| 200 |
+
|
| 201 |
+
with gr.Column():
|
| 202 |
+
output = gr.Textbox(label="Antwort",
|
| 203 |
+
placeholder="(Hier wird die Antwort angezeigt.)")
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
go_btn.click(fn=get_answer, inputs=[user_query, model], outputs=output,
|
| 207 |
+
api_name="qa")
|
| 208 |
+
"""
|
| 209 |
+
|
| 210 |
demo.launch(auth=(os.getenv("APPUSER"), os.getenv("APPPW")), share=True)
|