Spaces:
Running
Running
Gopala Krishna
commited on
Commit
·
0e45d15
1
Parent(s):
80cde48
Added try except
Browse files- .vs/MyChatGPTDavinci/v17/.wsuo +0 -0
- .vs/slnx.sqlite +0 -0
- app.py +23 -10
.vs/MyChatGPTDavinci/v17/.wsuo
CHANGED
Binary files a/.vs/MyChatGPTDavinci/v17/.wsuo and b/.vs/MyChatGPTDavinci/v17/.wsuo differ
|
|
.vs/slnx.sqlite
CHANGED
Binary files a/.vs/slnx.sqlite and b/.vs/slnx.sqlite differ
|
|
app.py
CHANGED
@@ -3,22 +3,35 @@ import os
|
|
3 |
import openai
|
4 |
import gradio as gr
|
5 |
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
messages = [
|
9 |
{"role": "system", "content": ""},
|
10 |
]
|
11 |
|
12 |
def chatbot(input):
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
22 |
|
23 |
inputs = gr.inputs.Textbox(lines=7, label="Query")
|
24 |
outputs = gr.outputs.Textbox(label="Response")
|
|
|
3 |
import openai
|
4 |
import gradio as gr
|
5 |
|
6 |
+
try:
|
7 |
+
openai.api_key = os.environ["OPENAPI_API_KEY"]
|
8 |
+
except KeyError:
|
9 |
+
error_message = "System is at capacity right now.Please try again later"
|
10 |
+
print(error_message)
|
11 |
+
def chatbot(input):
|
12 |
+
return error_message
|
13 |
+
else:
|
14 |
+
messages = [
|
15 |
+
{"role": "system", "content": "My AI Assistant"},
|
16 |
+
]
|
17 |
|
18 |
messages = [
|
19 |
{"role": "system", "content": ""},
|
20 |
]
|
21 |
|
22 |
def chatbot(input):
|
23 |
+
try:
|
24 |
+
if input:
|
25 |
+
messages.append({"role": "user", "content": input})
|
26 |
+
prompt = "\n".join([f"{m['role']}: {m['content']}" for m in messages])
|
27 |
+
chat = openai.Completion.create(
|
28 |
+
engine="text-davinci-003", prompt=prompt, max_tokens=1024, n=1, stop=None, temperature=0.7
|
29 |
+
)
|
30 |
+
reply = chat.choices[0].text.strip()
|
31 |
+
messages.append({"role": "assistant", "content": reply})
|
32 |
+
return reply
|
33 |
+
except openai.error.OpenAIError as e:
|
34 |
+
return "System is at capacity right now.Please try again later"
|
35 |
|
36 |
inputs = gr.inputs.Textbox(lines=7, label="Query")
|
37 |
outputs = gr.outputs.Textbox(label="Response")
|