Update app.py
Browse files
app.py
CHANGED
|
@@ -192,11 +192,54 @@ def fetch_personalized_data(session_index):
|
|
| 192 |
print(f"Error: {err}")
|
| 193 |
return None
|
| 194 |
|
| 195 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
@spaces.GPU
|
| 197 |
def generate(
|
| 198 |
request: gr.Request, # In order to fetch query params
|
| 199 |
message: str,
|
|
|
|
| 200 |
chat_history: list[tuple[str, str]],
|
| 201 |
max_new_tokens: int = 1024,
|
| 202 |
temperature: float = 0.6,
|
|
@@ -280,52 +323,10 @@ examples=[
|
|
| 280 |
)
|
| 281 |
|
| 282 |
with gr.Blocks(css="style.css") as demo:
|
| 283 |
-
#session_index = get_session_index(url_params)
|
| 284 |
-
session_index = 'eb3636167d3a63fbeee32934610e5b2f'
|
| 285 |
-
personalized_data = fetch_personalized_data(session_index)
|
| 286 |
-
|
| 287 |
-
## trust-game-llama-2-7b-chat
|
| 288 |
-
# app.py
|
| 289 |
-
def get_default_system_prompt():
|
| 290 |
-
#BOS, EOS = "<s>", "</s>"
|
| 291 |
-
#BINST, EINST = "[INST]", "[/INST]"
|
| 292 |
-
BSYS, ESYS = "<<SYS>>\n", "\n<</SYS>>\n\n"
|
| 293 |
-
|
| 294 |
-
DEFAULT_SYSTEM_PROMPT = f""" You are an intelligent and fair game guide in a 2-player trust game.
|
| 295 |
-
You are assisting players in making decisions to win.
|
| 296 |
-
Answer in a consistent style. Each of your answers should be maximum 2 sentences long.
|
| 297 |
-
The players are called The Investor and The Dealer and keep their role throughout the whole game.
|
| 298 |
-
Both start with 10€ in round 1. The game consists of 3 rounds. In round 1, The Investor invests between 0€ and 10€.
|
| 299 |
-
This amount is tripled automatically, and The Dealer can then distribute the tripled amount. After that, round 1 is over.
|
| 300 |
-
Both go into the next round with their current asset: The Investor with 10€ minus what he invested plus what he received back from The Dealer.
|
| 301 |
-
The Dealer with 10€ plus what he kept from the tripled amount.
|
| 302 |
-
You will receive a JSON with information on who trusted whom with how much money after each round as context.
|
| 303 |
-
Your goal is to guide players through the game, providing clear instructions and explanations.
|
| 304 |
-
If any question or action seems unclear, explain it rather than providing inaccurate information.
|
| 305 |
-
If you're unsure about an answer, it's better not to guess.
|
| 306 |
-
|
| 307 |
-
Example JSON context after a round: {personalized_data}
|
| 308 |
-
|
| 309 |
-
Few-shot training examples
|
| 310 |
-
{BSYS} Give an overview of the trust game. {ESYS}
|
| 311 |
-
{BSYS} Explain how trust amounts are calculated. {ESYS}
|
| 312 |
-
{BSYS} What happens if a player doesn't trust in a round? {ESYS}
|
| 313 |
-
"""
|
| 314 |
-
print(DEFAULT_SYSTEM_PROMPT)
|
| 315 |
-
return DEFAULT_SYSTEM_PROMPT
|
| 316 |
-
|
| 317 |
-
## trust-game-llama-2-7b-chat
|
| 318 |
-
# app.py
|
| 319 |
-
def construct_input_prompt(chat_history, message):
|
| 320 |
-
input_prompt = f"<s>[INST] <<SYS>>\n{get_default_system_prompt()}\n<</SYS>>\n\n "
|
| 321 |
-
for user, assistant in chat_history:
|
| 322 |
-
input_prompt += f"{user} [/INST] {assistant} <s>[INST] "
|
| 323 |
-
input_prompt += f"{message} [/INST] "
|
| 324 |
-
return input_prompt
|
| 325 |
-
|
| 326 |
-
chat_interface.render()
|
| 327 |
#gr.Markdown(LICENSE)
|
| 328 |
-
|
|
|
|
|
|
|
| 329 |
if __name__ == "__main__":
|
| 330 |
#demo.queue(max_size=20).launch()
|
| 331 |
demo.queue(max_size=20)
|
|
|
|
| 192 |
print(f"Error: {err}")
|
| 193 |
return None
|
| 194 |
|
| 195 |
+
#session_index = get_session_index(url_params)
|
| 196 |
+
session_index = 'eb3636167d3a63fbeee32934610e5b2f'
|
| 197 |
+
personalized_data = fetch_personalized_data(session_index)
|
| 198 |
+
|
| 199 |
+
## trust-game-llama-2-7b-chat
|
| 200 |
+
# app.py
|
| 201 |
+
def get_default_system_prompt():
|
| 202 |
+
#BOS, EOS = "<s>", "</s>"
|
| 203 |
+
#BINST, EINST = "[INST]", "[/INST]"
|
| 204 |
+
BSYS, ESYS = "<<SYS>>\n", "\n<</SYS>>\n\n"
|
| 205 |
+
|
| 206 |
+
DEFAULT_SYSTEM_PROMPT = f""" You are an intelligent and fair game guide in a 2-player trust game.
|
| 207 |
+
You are assisting players in making decisions to win.
|
| 208 |
+
Answer in a consistent style. Each of your answers should be maximum 2 sentences long.
|
| 209 |
+
The players are called The Investor and The Dealer and keep their role throughout the whole game.
|
| 210 |
+
Both start with 10€ in round 1. The game consists of 3 rounds. In round 1, The Investor invests between 0€ and 10€.
|
| 211 |
+
This amount is tripled automatically, and The Dealer can then distribute the tripled amount. After that, round 1 is over.
|
| 212 |
+
Both go into the next round with their current asset: The Investor with 10€ minus what he invested plus what he received back from The Dealer.
|
| 213 |
+
The Dealer with 10€ plus what he kept from the tripled amount.
|
| 214 |
+
You will receive a JSON with information on who trusted whom with how much money after each round as context.
|
| 215 |
+
Your goal is to guide players through the game, providing clear instructions and explanations.
|
| 216 |
+
If any question or action seems unclear, explain it rather than providing inaccurate information.
|
| 217 |
+
If you're unsure about an answer, it's better not to guess.
|
| 218 |
+
|
| 219 |
+
Example JSON context after a round: {personalized_data}
|
| 220 |
+
|
| 221 |
+
Few-shot training examples
|
| 222 |
+
{BSYS} Give an overview of the trust game. {ESYS}
|
| 223 |
+
{BSYS} Explain how trust amounts are calculated. {ESYS}
|
| 224 |
+
{BSYS} What happens if a player doesn't trust in a round? {ESYS}
|
| 225 |
+
"""
|
| 226 |
+
print(DEFAULT_SYSTEM_PROMPT)
|
| 227 |
+
return DEFAULT_SYSTEM_PROMPT
|
| 228 |
+
|
| 229 |
+
## trust-game-llama-2-7b-chat
|
| 230 |
+
# app.py
|
| 231 |
+
def construct_input_prompt(chat_history, message):
|
| 232 |
+
input_prompt = f"<s>[INST] <<SYS>>\n{get_default_system_prompt()}\n<</SYS>>\n\n "
|
| 233 |
+
for user, assistant in chat_history:
|
| 234 |
+
input_prompt += f"{user} [/INST] {assistant} <s>[INST] "
|
| 235 |
+
input_prompt += f"{message} [/INST] "
|
| 236 |
+
return input_prompt
|
| 237 |
+
|
| 238 |
@spaces.GPU
|
| 239 |
def generate(
|
| 240 |
request: gr.Request, # In order to fetch query params
|
| 241 |
message: str,
|
| 242 |
+
input_prompt: str,
|
| 243 |
chat_history: list[tuple[str, str]],
|
| 244 |
max_new_tokens: int = 1024,
|
| 245 |
temperature: float = 0.6,
|
|
|
|
| 323 |
)
|
| 324 |
|
| 325 |
with gr.Blocks(css="style.css") as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 326 |
#gr.Markdown(LICENSE)
|
| 327 |
+
#gr.Markdown(DESCRIPTION)
|
| 328 |
+
chat_interface.render()
|
| 329 |
+
|
| 330 |
if __name__ == "__main__":
|
| 331 |
#demo.queue(max_size=20).launch()
|
| 332 |
demo.queue(max_size=20)
|