Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files- README.md +3 -0
- interactive_test.py +147 -20
README.md
CHANGED
@@ -14,7 +14,10 @@ This is a Test of the feasibility of letting an LLM generate the user part while
|
|
14 |
We won't instruct the language model to roleplay as a user. Instead, we'll instruct it to generate the bot's responses as it was trained to do. Then, we let the model complete the user text blocks. Since the model doesn't distinguish between writing bot or user parts, we should be able to leverage its full training instead of trying to get it to rp which it was not trained for. Should also make gaslighting/confusing the model harder as its not pretending to be a user but should belive it is.
|
15 |
|
16 |
## How to use
|
|
|
17 |
Press the "Open in Colab" button to open the notebook in Google Colab.
|
|
|
|
|
18 |
|
19 |
## TODO
|
20 |
- Make a chatwindow with panel to test the model interactively
|
|
|
14 |
We won't instruct the language model to roleplay as a user. Instead, we'll instruct it to generate the bot's responses as it was trained to do. Then, we let the model complete the user text blocks. Since the model doesn't distinguish between writing bot or user parts, we should be able to leverage its full training instead of trying to get it to rp which it was not trained for. Should also make gaslighting/confusing the model harder as its not pretending to be a user but should belive it is.
|
15 |
|
16 |
## How to use
|
17 |
+
For the Notebook:
|
18 |
Press the "Open in Colab" button to open the notebook in Google Colab.
|
19 |
+
For the Gradio App:
|
20 |
+
Visit: https://bldng-demo-human-gpt.hf.space/
|
21 |
|
22 |
## TODO
|
23 |
- Make a chatwindow with panel to test the model interactively
|
interactive_test.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
from typing import Dict, List
|
2 |
import gradio as gr
|
3 |
from llama_cpp import Llama
|
4 |
|
@@ -23,25 +23,121 @@ User: The capital of France
|
|
23 |
Assistant: The capital of France is Paris
|
24 |
User: <|endtile|>
|
25 |
""".strip()
|
26 |
-
llm = Llama.from_pretrained(
|
27 |
-
repo_id="ArliAI/Phi-3.5-mini-3.8B-ArliAI-RPMax-v1.1-GGUF",
|
28 |
-
filename="ArliAI-RPMax-3.8B-v1.1-fp16.gguf",
|
29 |
-
)
|
30 |
-
# llm = Llama.from_pretrained(
|
31 |
-
# repo_id="bartowski/Phi-3.5-mini-instruct-GGUF",
|
32 |
-
# filename="Phi-3.5-mini-instruct-IQ3_XS.gguf",
|
33 |
-
# n_gpu_layers=-1,
|
34 |
-
# )
|
35 |
|
36 |
def chatmsg(message, role):
|
37 |
return {"role": role, "content": message}
|
38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
#More Trivia Style Question
|
46 |
{"name":"Country","content":[{"role":"user","content":"What is the capital?"}]},
|
47 |
{"name":"Simple Math","content":[{"role":"user","content":"What is 3*4?"}]},
|
@@ -94,21 +190,53 @@ conversations=[
|
|
94 |
]
|
95 |
|
96 |
with gr.Blocks() as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
chatbot = gr.Chatbot([chatmsg("What is the capital?","user")],type="messages",show_copy_all_button=True)
|
98 |
msg = gr.Textbox()
|
99 |
submit = gr.Button("Submit")
|
100 |
-
with gr.Accordion("
|
101 |
-
|
102 |
-
|
103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
return "", next(conversation for conversation in conversations if conversation["name"] == choice)["content"]
|
105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
|
107 |
def respond(message:str, chat_history:List[Dict[str, str]],syspropmt:str):
|
|
|
108 |
if "End of conversation." in [i["content"] for i in chat_history]:
|
109 |
return "", chat_history
|
110 |
chat_history.append(chatmsg(message,"assistant"))
|
111 |
-
ret=
|
112 |
comp=ret["choices"][0]["text"]
|
113 |
print(repr(comp))
|
114 |
if("<|end" in comp):
|
@@ -117,7 +245,6 @@ with gr.Blocks() as demo:
|
|
117 |
else:
|
118 |
chat_history.append(chatmsg(comp,"user"))
|
119 |
return "", chat_history
|
120 |
-
|
121 |
submit.click(respond, [msg, chatbot,sysprompt], [msg, chatbot])
|
122 |
msg.submit(respond, [msg, chatbot,sysprompt], [msg, chatbot])
|
123 |
|
|
|
1 |
+
from typing import Any, Dict, List
|
2 |
import gradio as gr
|
3 |
from llama_cpp import Llama
|
4 |
|
|
|
23 |
Assistant: The capital of France is Paris
|
24 |
User: <|endtile|>
|
25 |
""".strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
def chatmsg(message, role):
|
28 |
return {"role": role, "content": message}
|
29 |
|
30 |
+
class Model:
|
31 |
+
def __init__(self):
|
32 |
+
pass
|
33 |
+
def __call__(self, msg:str, stop:List[str], max_tokens:int):
|
34 |
+
raise NotImplementedError
|
35 |
+
def conv(self, msgs:List[Dict[str, str]]):
|
36 |
+
raise NotImplementedError
|
37 |
+
def starttok(self, user:str):
|
38 |
+
raise NotImplementedError
|
39 |
+
def close(self):
|
40 |
+
pass
|
41 |
|
42 |
+
class Phi35RPMax(Model):
|
43 |
+
def __init__(self):
|
44 |
+
self.llm = Llama.from_pretrained(
|
45 |
+
repo_id="ArliAI/Phi-3.5-mini-3.8B-ArliAI-RPMax-v1.1-GGUF",
|
46 |
+
filename="ArliAI-RPMax-3.8B-v1.1-fp16.gguf",
|
47 |
+
)
|
48 |
+
|
49 |
+
def __call__(self, msg:str, stop:List[str], max_tokens:int):
|
50 |
+
return self.llm(msg, stop=stop, max_tokens=max_tokens)
|
51 |
+
|
52 |
+
def conv(self,msgs:List[Dict[str, str]]):
|
53 |
+
return "\n".join([f"<|{msg['role']}|>\n{msg['content']}<|end|>" for msg in msgs])
|
54 |
+
def starttok(self,user:str):
|
55 |
+
return f"<|{user}|>\n"
|
56 |
+
def close(self):
|
57 |
+
self.llm.close()
|
58 |
+
Phi35RPMax.modelname="Phi35RPMax-fp16"
|
59 |
+
class Phi35(Model):
|
60 |
+
def __init__(self):
|
61 |
+
self.llm = Llama.from_pretrained(
|
62 |
+
repo_id="bartowski/Phi-3.5-mini-instruct-GGUF",
|
63 |
+
filename="Phi-3.5-mini-instruct-IQ3_XS.gguf",
|
64 |
+
)
|
65 |
+
def __call__(self, msg:str, stop:List[str], max_tokens:int):
|
66 |
+
return self.llm(msg, stop=stop, max_tokens=max_tokens)
|
67 |
+
|
68 |
+
def conv(self,msgs:List[Dict[str, str]]):
|
69 |
+
return "\n".join([f"<|{msg['role']}|>\n{msg['content']}<|end|>" for msg in msgs])
|
70 |
+
|
71 |
+
def starttok(self,user:str):
|
72 |
+
return f"<|{user}|>\n"
|
73 |
+
def close(self):
|
74 |
+
self.llm.close()
|
75 |
+
Phi35.modelname="Phi35-IQ3_XS"
|
76 |
|
77 |
+
# TODO: Gemma2 needs license maybe try it in the future but dont think it is worth it
|
78 |
+
# class Gemma2(Model):
|
79 |
+
# def __init__(self):
|
80 |
+
# self.llm = Llama.from_pretrained(
|
81 |
+
# repo_id="google/gemma-2-2b-it-GGUF",
|
82 |
+
# filename="2b_it_v2.gguf",
|
83 |
+
# )
|
84 |
+
# def __call__(self, msg:str, stop:List[str], max_tokens:int):
|
85 |
+
# return self.llm(msg, stop=stop, max_tokens=max_tokens)
|
86 |
+
|
87 |
+
# def conv(self,msgs:List[Dict[str, str]]):#https://ai.google.dev/gemma/docs/formatting?hl=de
|
88 |
+
# return "\n".join([f"<|{msg['role']}|>\n{msg['content']}<|end|>" for msg in msgs])
|
89 |
+
# def formatmessage(self,msg:str, role:str):#https://ai.google.dev/gemma/docs/formatting?hl=de
|
90 |
+
# if(role=="system"):
|
91 |
+
# # Gemma2 does not support system messages / isnt trained for them
|
92 |
+
# # TODO: Make them Assistant messages and test if this improves the results
|
93 |
+
# return ""
|
94 |
+
# if role=="assistant":
|
95 |
+
# role="model"
|
96 |
+
# return f"<start_of_turn>{role}\n{msg}<end_of_turn>"
|
97 |
+
# def starttok(self,user:str):
|
98 |
+
# return f"<start_of_turn>{user}\n"
|
99 |
+
# def close(self):
|
100 |
+
# self.llm.close()
|
101 |
+
# Gemma2.modelname="Gemma2-2b-it-GGUF"
|
102 |
|
103 |
+
class Llama31uncensored(Model):
|
104 |
+
def __init__(self):
|
105 |
+
self.llm = Llama.from_pretrained(
|
106 |
+
repo_id="Orenguteng/Llama-3.1-8B-Lexi-Uncensored-V2-GGUF",
|
107 |
+
filename="Llama-3.1-8B-Lexi-Uncensored_V2_F16.gguf",
|
108 |
+
)
|
109 |
+
def __call__(self, msg:str, stop:List[str], max_tokens:int):
|
110 |
+
return self.llm(msg, stop=stop, max_tokens=max_tokens)
|
111 |
+
|
112 |
+
def conv(self,msgs:List[Dict[str, str]]):
|
113 |
+
return "\n".join([f"<|begin_of_text|><|start_header_id|>{msg['role']}<|end_header_id|>\n\n{msg['content']}<|eot_id|>" for msg in msgs])
|
114 |
+
def starttok(self,user:str):
|
115 |
+
return f"<|begin_of_text|><|start_header_id|>{user}<|end_header_id|>\n\n"
|
116 |
+
def close(self):
|
117 |
+
self.llm.close()
|
118 |
+
Llama31uncensored.modelname="Llama31-uncensored-fp16"
|
119 |
+
|
120 |
+
class Llama31(Model):
|
121 |
+
def __init__(self):
|
122 |
+
self.llm = Llama.from_pretrained(
|
123 |
+
repo_id="lmstudio-community/Meta-Llama-3.1-8B-Instruct-GGUF",
|
124 |
+
filename="Meta-Llama-3.1-8B-Instruct-IQ4_XS.gguf",
|
125 |
+
)
|
126 |
+
def __call__(self, msg:str, stop:List[str], max_tokens:int):
|
127 |
+
return self.llm(msg, stop=stop, max_tokens=max_tokens)
|
128 |
+
|
129 |
+
def conv(self,msgs:List[Dict[str, str]]):
|
130 |
+
return "\n".join([f"<|begin_of_text|><|start_header_id|>{msg['role']}<|end_header_id|>\n\n{msg['content']}<|eot_id|>" for msg in msgs])
|
131 |
+
def starttok(self,user:str):
|
132 |
+
return f"<|begin_of_text|><|start_header_id|>{user}<|end_header_id|>"
|
133 |
+
def close(self):
|
134 |
+
self.llm.close()
|
135 |
+
Llama31.modelname="Llama31-IQ4_XS"
|
136 |
+
|
137 |
+
|
138 |
+
models=[Phi35RPMax,Phi35,Llama31uncensored,Llama31]
|
139 |
+
currmodel=Phi35()
|
140 |
+
conversations:List[Dict[str, Any]]=[
|
141 |
#More Trivia Style Question
|
142 |
{"name":"Country","content":[{"role":"user","content":"What is the capital?"}]},
|
143 |
{"name":"Simple Math","content":[{"role":"user","content":"What is 3*4?"}]},
|
|
|
190 |
]
|
191 |
|
192 |
with gr.Blocks() as demo:
|
193 |
+
with gr.Accordion("Info"):
|
194 |
+
gr.Markdown(f"""
|
195 |
+
# HumanGPT Game Test
|
196 |
+
## Disclaimer
|
197 |
+
This is a test of feasibility and to evaluate different models, prompts, and types of conversations.
|
198 |
+
The current conversations don't represent the type of interactions the final game would have, but rather showcase various possible scenarios for playtesting and assessing model behavior.
|
199 |
+
This playground will also be used to test fine-tuned models in the future.
|
200 |
+
## How to Use
|
201 |
+
- Use the chat window to test the model interactively.
|
202 |
+
- If the model responds with "End of conversation," it means the interaction is over.
|
203 |
+
- Change the conversation by selecting a different option from the choice box.
|
204 |
+
- Change the model by selecting a different option from the model choice box.
|
205 |
+
- To modify the system prompt, edit the text in the system prompt text box.
|
206 |
+
- If you choose Custom in the conversation choice box, you can enter a custom conversation in the text box under the Custom Conversation accordion.
|
207 |
+
""")
|
208 |
chatbot = gr.Chatbot([chatmsg("What is the capital?","user")],type="messages",show_copy_all_button=True)
|
209 |
msg = gr.Textbox()
|
210 |
submit = gr.Button("Submit")
|
211 |
+
with gr.Accordion("Config"):
|
212 |
+
convchoicebox = gr.Radio(choices=[conversation["name"] for conversation in conversations]+["Custom"], value="Country", label="Conversations")
|
213 |
+
with gr.Accordion("Custom Conversation",open=False):
|
214 |
+
custom_conv=gr.Textbox(value="", label="Conversation")
|
215 |
+
def update_custom_conv(custom_conv,convchoicebox,chatbot,msg):
|
216 |
+
if(convchoicebox=="Custom"):
|
217 |
+
return "", [chatmsg(custom_conv,"user")]
|
218 |
+
return msg,chatbot
|
219 |
+
custom_conv.change(update_custom_conv, [custom_conv,convchoicebox,chatbot,msg], [msg,chatbot])
|
220 |
+
def update_choicebox(choice,custom_conv):
|
221 |
+
if(choice=="Custom"):
|
222 |
+
return "", [chatmsg(custom_conv,"user")]
|
223 |
return "", next(conversation for conversation in conversations if conversation["name"] == choice)["content"]
|
224 |
+
sysprompt=gr.Textbox(value=syspropmt, label="System Prompt")
|
225 |
+
convchoicebox.change(update_choicebox, [convchoicebox,custom_conv], [msg,chatbot])
|
226 |
+
modelchoicebox = gr.Radio(choices=[model.modelname for model in models], value=currmodel.modelname, label="Model")
|
227 |
+
def update_modelchoicebox(choice):
|
228 |
+
global currmodel
|
229 |
+
currmodel.close()
|
230 |
+
currmodel=next(model for model in models if model.modelname == choice)()
|
231 |
+
return "", []
|
232 |
+
modelchoicebox.change(update_modelchoicebox, [modelchoicebox], [msg,chatbot])
|
233 |
|
234 |
def respond(message:str, chat_history:List[Dict[str, str]],syspropmt:str):
|
235 |
+
global currmodel
|
236 |
if "End of conversation." in [i["content"] for i in chat_history]:
|
237 |
return "", chat_history
|
238 |
chat_history.append(chatmsg(message,"assistant"))
|
239 |
+
ret=currmodel(currmodel.conv([chatmsg(syspropmt,"system")])+currmodel.conv(chat_history)+"<|user|>\n", stop=[".","\n \n","?\n",".\n","tile|>"],max_tokens=100)
|
240 |
comp=ret["choices"][0]["text"]
|
241 |
print(repr(comp))
|
242 |
if("<|end" in comp):
|
|
|
245 |
else:
|
246 |
chat_history.append(chatmsg(comp,"user"))
|
247 |
return "", chat_history
|
|
|
248 |
submit.click(respond, [msg, chatbot,sysprompt], [msg, chatbot])
|
249 |
msg.submit(respond, [msg, chatbot,sysprompt], [msg, chatbot])
|
250 |
|