Spaces:
Runtime error
Runtime error
csabakecskemeti
commited on
Commit
•
54929aa
1
Parent(s):
6fc5da1
Update app.py
Browse files
app.py
CHANGED
@@ -6,7 +6,9 @@ import json
|
|
6 |
sbc_host_url = os.environ['URL']
|
7 |
|
8 |
def get_completion(prompt:str, messages:str = '', n_predict=128):
|
9 |
-
|
|
|
|
|
10 |
headers = {
|
11 |
"Content-Type": "application/json"
|
12 |
}
|
@@ -16,18 +18,20 @@ def get_completion(prompt:str, messages:str = '', n_predict=128):
|
|
16 |
"stop": ["### HUMAN:", "### ASSISTANT:", "HUMAN"],
|
17 |
"stream": "True"
|
18 |
}
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
26 |
|
27 |
|
28 |
def chatty(prompt, messages):
|
29 |
-
print(prompt)
|
30 |
-
print(f'messages: {messages}')
|
31 |
past_messages = ''
|
32 |
if len(messages) > 0:
|
33 |
for idx, message in enumerate(messages):
|
@@ -37,7 +41,7 @@ def chatty(prompt, messages):
|
|
37 |
|
38 |
|
39 |
# past_messages = messages[0][0]
|
40 |
-
print(f'past_messages: {past_messages}')
|
41 |
messages = get_completion(prompt, past_messages)
|
42 |
return messages.split('### ASSISTANT:')[-1]
|
43 |
|
|
|
6 |
sbc_host_url = os.environ['URL']
|
7 |
|
8 |
def get_completion(prompt:str, messages:str = '', n_predict=128):
|
9 |
+
system = "### System: You are a helpful assistant helps to brainstorm ideas.\n"
|
10 |
+
prompt_templated = f'{system} {messages}\n ### HUMAN:\n{prompt} \n ### ASSISTANT:'
|
11 |
+
|
12 |
headers = {
|
13 |
"Content-Type": "application/json"
|
14 |
}
|
|
|
18 |
"stop": ["### HUMAN:", "### ASSISTANT:", "HUMAN"],
|
19 |
"stream": "True"
|
20 |
}
|
21 |
+
try:
|
22 |
+
response = requests.post(sbc_host_url, headers=headers, data=json.dumps(data))
|
23 |
+
|
24 |
+
if response.status_code == 200:
|
25 |
+
return response.json()['content']
|
26 |
+
else:
|
27 |
+
response.raise_for_status()
|
28 |
+
except:
|
29 |
+
raise gr.Warning("Apologies for the inconvenience! Our model is currently self-hosted and unavailable at the moment.")
|
30 |
|
31 |
|
32 |
def chatty(prompt, messages):
|
33 |
+
# print(prompt)
|
34 |
+
# print(f'messages: {messages}')
|
35 |
past_messages = ''
|
36 |
if len(messages) > 0:
|
37 |
for idx, message in enumerate(messages):
|
|
|
41 |
|
42 |
|
43 |
# past_messages = messages[0][0]
|
44 |
+
# print(f'past_messages: {past_messages}')
|
45 |
messages = get_completion(prompt, past_messages)
|
46 |
return messages.split('### ASSISTANT:')[-1]
|
47 |
|