Spaces:
Sleeping
Sleeping
Samuel L Meyers commited on
Commit ·
b90a389
1
Parent(s): 5930c36
Try to fix prompts
Browse files- code/app.py +12 -3
code/app.py
CHANGED
|
@@ -12,10 +12,11 @@ mdlpath = hf_hub_download(repo_id="TheBloke/Starling-LM-7B-alpha-GGUF", filename
|
|
| 12 |
|
| 13 |
#lcpp_model = Llama(model_path=model_path, n_ctx=8192)
|
| 14 |
llm = AutoModelForCausalLM.from_pretrained(model_path_or_repo_id=model_path, local_files_only=True, model_type="mistral")
|
| 15 |
-
global otxt, txtinput, txtoutput, running, result
|
| 16 |
otxt = ""
|
| 17 |
running = False
|
| 18 |
result = None
|
|
|
|
| 19 |
|
| 20 |
def stowtext(curr, inp):
|
| 21 |
if len(curr) <= 1:
|
|
@@ -63,14 +64,15 @@ def jsn2prompt(jsn):
|
|
| 63 |
return txt
|
| 64 |
|
| 65 |
def talk(txt, jsn):
|
| 66 |
-
global running, result
|
| 67 |
if not jsn:
|
| 68 |
jsn = txt
|
| 69 |
if not running:
|
| 70 |
#result = lcpp_model.create_chat_completion(messages=txt,stream=True,stop=["GPT4 Correct User: ", "<|end_of_turn|>", "</s>"], max_tokens=64, )
|
| 71 |
#result = lcpp_model(prompt=jsn2prompt(txt), stream=True, stop=["GPT4 Correct User: ", "<|end_of_turn|>", "</s>"], max_tokens=64, echo=False)
|
| 72 |
-
result = llm(prompt=jsn2prompt(txt), stream=True, stop=["GPT4 Correct User: ", "<|end_of_turn|>", "</s>"]
|
| 73 |
running = True
|
|
|
|
| 74 |
for r in result:
|
| 75 |
print("GOT RESULT:", r)
|
| 76 |
txt2 = None
|
|
@@ -80,7 +82,14 @@ def talk(txt, jsn):
|
|
| 80 |
running = False
|
| 81 |
yield txt
|
| 82 |
if txt2 is not None:
|
|
|
|
| 83 |
txt = stowchunk(txt, txt2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
yield txt
|
| 85 |
yield txt
|
| 86 |
|
|
|
|
| 12 |
|
| 13 |
#lcpp_model = Llama(model_path=model_path, n_ctx=8192)
|
| 14 |
llm = AutoModelForCausalLM.from_pretrained(model_path_or_repo_id=model_path, local_files_only=True, model_type="mistral")
|
| 15 |
+
global otxt, txtinput, txtoutput, running, result, echoed
|
| 16 |
otxt = ""
|
| 17 |
running = False
|
| 18 |
result = None
|
| 19 |
+
echoed = False
|
| 20 |
|
| 21 |
def stowtext(curr, inp):
|
| 22 |
if len(curr) <= 1:
|
|
|
|
| 64 |
return txt
|
| 65 |
|
| 66 |
def talk(txt, jsn):
|
| 67 |
+
global running, result, echoed
|
| 68 |
if not jsn:
|
| 69 |
jsn = txt
|
| 70 |
if not running:
|
| 71 |
#result = lcpp_model.create_chat_completion(messages=txt,stream=True,stop=["GPT4 Correct User: ", "<|end_of_turn|>", "</s>"], max_tokens=64, )
|
| 72 |
#result = lcpp_model(prompt=jsn2prompt(txt), stream=True, stop=["GPT4 Correct User: ", "<|end_of_turn|>", "</s>"], max_tokens=64, echo=False)
|
| 73 |
+
result = llm(prompt=jsn2prompt(txt), stream=True, stop=["GPT4 Correct User: ", "<|end_of_turn|>", "</s>"])
|
| 74 |
running = True
|
| 75 |
+
echoed = False
|
| 76 |
for r in result:
|
| 77 |
print("GOT RESULT:", r)
|
| 78 |
txt2 = None
|
|
|
|
| 82 |
running = False
|
| 83 |
yield txt
|
| 84 |
if txt2 is not None:
|
| 85 |
+
txt3 = txt
|
| 86 |
txt = stowchunk(txt, txt2)
|
| 87 |
+
if not echoed and txt[-1]["content"].contains(jsn2prompt([txt3[-1]])):
|
| 88 |
+
echoed = True
|
| 89 |
+
yield txt
|
| 90 |
+
elif not echoed and txt[-1]["role"] != "assistant":
|
| 91 |
+
txt[-1]["content"] = "*Thinking*"
|
| 92 |
+
yield txt
|
| 93 |
yield txt
|
| 94 |
yield txt
|
| 95 |
|