Update app.py
Browse files
app.py
CHANGED
@@ -54,7 +54,8 @@ def invoke(openai_api_key, prompt, rag_option):
|
|
54 |
else:
|
55 |
completion, chain, callback = llm_chain(config, prompt)
|
56 |
|
57 |
-
if (completion.generations[0] != None and
|
|
|
58 |
result = completion.generations[0][0].text
|
59 |
except Exception as e:
|
60 |
err_msg = e
|
@@ -63,32 +64,34 @@ def invoke(openai_api_key, prompt, rag_option):
|
|
63 |
finally:
|
64 |
end_time_ms = round(time.time() * 1000)
|
65 |
|
66 |
-
trace_wandb(
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
|
|
75 |
|
76 |
return result
|
77 |
|
78 |
gr.close_all()
|
79 |
|
80 |
-
demo = gr.Interface(
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
|
|
93 |
|
94 |
demo.launch()
|
|
|
54 |
else:
|
55 |
completion, chain, callback = llm_chain(config, prompt)
|
56 |
|
57 |
+
if (completion.generations[0] != None and
|
58 |
+
completion.generations[0][0] != None):
|
59 |
result = completion.generations[0][0].text
|
60 |
except Exception as e:
|
61 |
err_msg = e
|
|
|
64 |
finally:
|
65 |
end_time_ms = round(time.time() * 1000)
|
66 |
|
67 |
+
trace_wandb(
|
68 |
+
config,
|
69 |
+
rag_option,
|
70 |
+
prompt,
|
71 |
+
completion,
|
72 |
+
result,
|
73 |
+
callback,
|
74 |
+
err_msg,
|
75 |
+
start_time_ms,
|
76 |
+
end_time_ms)
|
77 |
|
78 |
return result
|
79 |
|
80 |
gr.close_all()
|
81 |
|
82 |
+
demo = gr.Interface(
|
83 |
+
fn = invoke,
|
84 |
+
inputs = [gr.Textbox(label = "OpenAI API Key", type = "password", lines = 1),
|
85 |
+
gr.Textbox(label = "Prompt", value = "What are GPT-4's media capabilities in 5 emojis and 1 sentence?", lines = 1),
|
86 |
+
gr.Radio([RAG_OFF, RAG_LANGCHAIN, RAG_LLAMAINDEX], label = "Retrieval-Augmented Generation", value = RAG_LANGCHAIN)],
|
87 |
+
outputs = [gr.Textbox(label = "Completion", lines = 1)],
|
88 |
+
title = "Context-Aware Reasoning Application",
|
89 |
+
description = os.environ["DESCRIPTION"],
|
90 |
+
examples = [["", "What are GPT-4's media capabilities in 5 emojis and 1 sentence?", RAG_LANGCHAIN],
|
91 |
+
["", "List GPT-4's exam scores and benchmark results.", RAG_LANGCHAIN],
|
92 |
+
["", "Compare GPT-4 to GPT-3.5 in markdown table format.", RAG_LANGCHAIN],
|
93 |
+
["", "Write a Python program that calls the GPT-4 API.", RAG_LANGCHAIN],
|
94 |
+
["", "What is the GPT-4 API's cost and rate limit? Answer in English, Arabic, Chinese, Hindi, and Russian in JSON format.", RAG_LANGCHAIN]],
|
95 |
+
cache_examples = False)
|
96 |
|
97 |
demo.launch()
|