Spaces:
Build error
Build error
Commit ·
b0fc8f9
1
Parent(s): 3be34c2
Update app.py
Browse files
app.py
CHANGED
|
@@ -21,16 +21,19 @@ print("Model ready!")
|
|
| 21 |
def response(message, history):
|
| 22 |
#url="https://afischer1985-wizardlm-13b-v1-2-q4-0-gguf.hf.space/v1/completions"
|
| 23 |
url="http://0.0.0.0:2600/v1/completions"
|
| 24 |
-
body={"prompt":"Im Folgenden findest du eine Instruktion, die eine Aufgabe bescheibt. Schreibe eine Antwort, um die Aufgabe zu lösen.\n\n### Instruktion:\n"+message+"\n\n### Antwort:","max_tokens":500, "echo":"False","stream":"True"}
|
|
|
|
| 25 |
response=""
|
| 26 |
buffer=""
|
| 27 |
print("URL: "+url)
|
| 28 |
print("User: "+message+"\nAI: ")
|
| 29 |
for text in requests.post(url, json=body, stream=True): #-H 'accept: application/json' -H 'Content-Type: application/json'
|
| 30 |
-
|
|
|
|
|
|
|
| 31 |
text=text.decode('utf-8')
|
| 32 |
-
if(text.startswith(": ping -")==False):buffer=
|
| 33 |
-
print("\n*** Buffer: "+str(buffer)+"\n***\n")
|
| 34 |
buffer=buffer.split('"finish_reason": null}]}')
|
| 35 |
if(len(buffer)==1):
|
| 36 |
buffer="".join(buffer)
|
|
@@ -43,7 +46,8 @@ def response(message, history):
|
|
| 43 |
print(part, end="", flush=True)
|
| 44 |
response=response+part
|
| 45 |
buffer="" # reset buffer
|
| 46 |
-
except:
|
|
|
|
| 47 |
pass
|
| 48 |
yield response
|
| 49 |
|
|
|
|
| 21 |
def response(message, history):
|
| 22 |
#url="https://afischer1985-wizardlm-13b-v1-2-q4-0-gguf.hf.space/v1/completions"
|
| 23 |
url="http://0.0.0.0:2600/v1/completions"
|
| 24 |
+
#body={"prompt":"Im Folgenden findest du eine Instruktion, die eine Aufgabe bescheibt. Schreibe eine Antwort, um die Aufgabe zu lösen.\n\n### Instruktion:\n"+message+"\n\n### Antwort:","max_tokens":500, "echo":"False","stream":"True"}
|
| 25 |
+
body={"prompt":" chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions.\n\nUSER:\n"+message+"\n\nASSISTANT:","max_tokens":500, "echo":"False","stream":"True"}
|
| 26 |
response=""
|
| 27 |
buffer=""
|
| 28 |
print("URL: "+url)
|
| 29 |
print("User: "+message+"\nAI: ")
|
| 30 |
for text in requests.post(url, json=body, stream=True): #-H 'accept: application/json' -H 'Content-Type: application/json'
|
| 31 |
+
if buffer is None: buffer=""
|
| 32 |
+
buffer=str("".join(buffer))
|
| 33 |
+
#print("*** Raw String: "+str(text)+"\n***\n")
|
| 34 |
text=text.decode('utf-8')
|
| 35 |
+
if((text.startswith(": ping -")==False) & (len(text.strip("\n\r"))>0)): buffer=buffer+str(text)
|
| 36 |
+
#print("\n*** Buffer: "+str(buffer)+"\n***\n")
|
| 37 |
buffer=buffer.split('"finish_reason": null}]}')
|
| 38 |
if(len(buffer)==1):
|
| 39 |
buffer="".join(buffer)
|
|
|
|
| 46 |
print(part, end="", flush=True)
|
| 47 |
response=response+part
|
| 48 |
buffer="" # reset buffer
|
| 49 |
+
except Exception as e:
|
| 50 |
+
print("Exception:"+str(e))
|
| 51 |
pass
|
| 52 |
yield response
|
| 53 |
|