Spaces:
Runtime error
Runtime error
0.2
Browse files
app.py
CHANGED
|
@@ -17,9 +17,9 @@ I am capable of ( slowly ) responding to any query you may have, as I am a LLM a
|
|
| 17 |
"""
|
| 18 |
|
| 19 |
INITIAL_STATE = json.dumps({
|
| 20 |
-
"path": "
|
| 21 |
-
"filename": "
|
| 22 |
-
"context":
|
| 23 |
"messages": [
|
| 24 |
{
|
| 25 |
"role": "assistant",
|
|
@@ -94,11 +94,7 @@ def markdownify_chats(chats):
|
|
| 94 |
"""
|
| 95 |
print(chats)
|
| 96 |
nl = "\n"
|
| 97 |
-
return f"
|
| 98 |
-
|
| 99 |
-
{format_greeting(current_settings['path'], current_settings['filename'], current_settings['context'])}
|
| 100 |
-
|
| 101 |
-
---\n\n\n\n""" + "\n".join([f"### {'R3BC' if msg['role'] == 'assistant' else 'Human'}\n{msg['content'].strip()}\n\n{'---' + nl*2 if msg['role'] == 'assistant' else ''}" for msg in chats['messages']])
|
| 102 |
|
| 103 |
def llm_chat(inpt: str, state_raw: str):
|
| 104 |
"""
|
|
@@ -107,18 +103,18 @@ def llm_chat(inpt: str, state_raw: str):
|
|
| 107 |
print("llm_chat called", inpt, state_raw)
|
| 108 |
global llm, current_settings
|
| 109 |
if not llm:
|
| 110 |
-
return
|
| 111 |
|
| 112 |
# Assuming inpt is a list of messages to process
|
| 113 |
if inpt is None or not inpt:
|
| 114 |
-
return state_raw
|
| 115 |
try:
|
| 116 |
state = json.loads(state_raw)
|
| 117 |
except Exception as e:
|
| 118 |
-
return INITIAL_STATE
|
| 119 |
|
| 120 |
if not "messages" in state:
|
| 121 |
-
return INITIAL_STATE
|
| 122 |
|
| 123 |
# If the last message is the same as the last message in the state, pretend they sent "...".
|
| 124 |
state['messages'].append({
|
|
@@ -146,7 +142,11 @@ def llm_chat(inpt: str, state_raw: str):
|
|
| 146 |
},
|
| 147 |
]
|
| 148 |
run_messages.extend(state['messages'])
|
| 149 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
# Generate a response using the language model
|
| 151 |
response = llm.create_chat_completion(messages=run_messages, max_tokens=current_settings['context'], top_k=16, top_p=0.85, temperature=0.369, presence_penalty=1.12, stop=["</s>", "<|im_end|>", "\n\n", "< | im_start | >", "< | im_end | >", "<user>"])['choices'][0]['message']['content']
|
| 152 |
print(f"Request: {inpt}\nResponse: {response}")
|
|
@@ -180,7 +180,8 @@ def main():
|
|
| 180 |
mdn = gr.Markdown(markdownify_chats(json.loads(INITIAL_STATE)))
|
| 181 |
with gr.Row():
|
| 182 |
inp = gr.Textbox(placeholder="Enter your message ( Shift+Enter to Send )", lines=2, max_lines=32, label=None, show_label=False, show_copy_button=True)
|
| 183 |
-
inp.submit(llm_chat, inputs=[inp, inv['jsn']], outputs=[inv['jsn'], inp
|
|
|
|
| 184 |
blk.launch(debug=True, show_api=False)
|
| 185 |
|
| 186 |
if __name__ == "__main__":
|
|
|
|
| 17 |
"""
|
| 18 |
|
| 19 |
INITIAL_STATE = json.dumps({
|
| 20 |
+
"path": "Qwen/Qwen1.5-0.5B-Chat-GGUF",
|
| 21 |
+
"filename": "qwen1_5-0_5b-chat-q8_0.gguf",
|
| 22 |
+
"context": 32786,
|
| 23 |
"messages": [
|
| 24 |
{
|
| 25 |
"role": "assistant",
|
|
|
|
| 94 |
"""
|
| 95 |
print(chats)
|
| 96 |
nl = "\n"
|
| 97 |
+
return f"# R3BC - Simple. Clean. Chat.\n\n" + "\n".join([f"### {'R3BC' if msg['role'] == 'assistant' else 'Human'}\n{msg['content'].strip()}\n\n{'---' + nl*2 if msg['role'] == 'assistant' else ''}" for msg in chats['messages']])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
|
| 99 |
def llm_chat(inpt: str, state_raw: str):
|
| 100 |
"""
|
|
|
|
| 103 |
print("llm_chat called", inpt, state_raw)
|
| 104 |
global llm, current_settings
|
| 105 |
if not llm:
|
| 106 |
+
return state_raw, ""
|
| 107 |
|
| 108 |
# Assuming inpt is a list of messages to process
|
| 109 |
if inpt is None or not inpt:
|
| 110 |
+
return state_raw, ""
|
| 111 |
try:
|
| 112 |
state = json.loads(state_raw)
|
| 113 |
except Exception as e:
|
| 114 |
+
return INITIAL_STATE, ""
|
| 115 |
|
| 116 |
if not "messages" in state:
|
| 117 |
+
return INITIAL_STATE, ""
|
| 118 |
|
| 119 |
# If the last message is the same as the last message in the state, pretend they sent "...".
|
| 120 |
state['messages'].append({
|
|
|
|
| 142 |
},
|
| 143 |
]
|
| 144 |
run_messages.extend(state['messages'])
|
| 145 |
+
if not state['messages'][-1]['role'] == "assistant":
|
| 146 |
+
run_messages.append({
|
| 147 |
+
"role": "user",
|
| 148 |
+
"content": "Continue as though I have not spoken."
|
| 149 |
+
})
|
| 150 |
# Generate a response using the language model
|
| 151 |
response = llm.create_chat_completion(messages=run_messages, max_tokens=current_settings['context'], top_k=16, top_p=0.85, temperature=0.369, presence_penalty=1.12, stop=["</s>", "<|im_end|>", "\n\n", "< | im_start | >", "< | im_end | >", "<user>"])['choices'][0]['message']['content']
|
| 152 |
print(f"Request: {inpt}\nResponse: {response}")
|
|
|
|
| 180 |
mdn = gr.Markdown(markdownify_chats(json.loads(INITIAL_STATE)))
|
| 181 |
with gr.Row():
|
| 182 |
inp = gr.Textbox(placeholder="Enter your message ( Shift+Enter to Send )", lines=2, max_lines=32, label=None, show_label=False, show_copy_button=True)
|
| 183 |
+
inp.submit(llm_chat, inputs=[inp, inv['jsn']], outputs=[inv['jsn'], inp])
|
| 184 |
+
inv['jsn'].change(lambda ijn: markdownify_chats(json.loads(ijn)), inputs=[inv['jsn']], outputs=[mdn])
|
| 185 |
blk.launch(debug=True, show_api=False)
|
| 186 |
|
| 187 |
if __name__ == "__main__":
|