Spaces:
Sleeping
Sleeping
We now use a global Together client and history is now a list
Browse files
app.py
CHANGED
|
@@ -9,6 +9,8 @@ from helper import load_world, save_world
|
|
| 9 |
# Global variable to allow demo restart
|
| 10 |
demo = None
|
| 11 |
|
|
|
|
|
|
|
| 12 |
# Moderate Content Policy
|
| 13 |
# Set the content policy
|
| 14 |
mature_content_policy = {
|
|
@@ -116,8 +118,6 @@ Inventory Updates:
|
|
| 116 |
system_prompt_world = "You are a creative fantasy world generator. Respond only with structured text in the required format."
|
| 117 |
|
| 118 |
def generate_world():
|
| 119 |
-
client = Together()
|
| 120 |
-
|
| 121 |
# Create World
|
| 122 |
world_prompt = """
|
| 123 |
Generate a creative description for a unique fantasy world with an
|
|
@@ -324,8 +324,6 @@ def initialize_game_state():
|
|
| 324 |
character = next(iter(town['npcs'].values()))
|
| 325 |
|
| 326 |
# Generate initial story
|
| 327 |
-
client = Together()
|
| 328 |
-
|
| 329 |
system_prompt = """You are an AI Game master. Your job is to create a
|
| 330 |
start to an adventure based on the world, kingdom, town and character
|
| 331 |
a player is playing as.
|
|
@@ -390,7 +388,6 @@ Provide your safety assessment for user in the above conversation:
|
|
| 390 |
violated categories. [/INST]"""
|
| 391 |
|
| 392 |
# Build the prompt with embedded values
|
| 393 |
-
client = Together()
|
| 394 |
response = client.completions.create(
|
| 395 |
model="Meta-Llama/LlamaGuard-2-8b",
|
| 396 |
prompt=prompt,
|
|
@@ -463,14 +460,12 @@ Inventory: {json.dumps(game_state['inventory'])}"""
|
|
| 463 |
{"role": "system", "content": system_prompt},
|
| 464 |
{"role": "user", "content": world_info}
|
| 465 |
]
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
messages.append({"role": "
|
| 469 |
|
| 470 |
messages.append({"role": "user", "content": message})
|
| 471 |
|
| 472 |
-
client = Together()
|
| 473 |
-
|
| 474 |
model_output = client.chat.completions.create(
|
| 475 |
model="meta-llama/Llama-3-70b-chat-hf",
|
| 476 |
messages=messages
|
|
|
|
| 9 |
# Global variable to allow demo restart
|
| 10 |
demo = None
|
| 11 |
|
| 12 |
+
client = Together()
|
| 13 |
+
|
| 14 |
# Moderate Content Policy
|
| 15 |
# Set the content policy
|
| 16 |
mature_content_policy = {
|
|
|
|
| 118 |
system_prompt_world = "You are a creative fantasy world generator. Respond only with structured text in the required format."
|
| 119 |
|
| 120 |
def generate_world():
|
|
|
|
|
|
|
| 121 |
# Create World
|
| 122 |
world_prompt = """
|
| 123 |
Generate a creative description for a unique fantasy world with an
|
|
|
|
| 324 |
character = next(iter(town['npcs'].values()))
|
| 325 |
|
| 326 |
# Generate initial story
|
|
|
|
|
|
|
| 327 |
system_prompt = """You are an AI Game master. Your job is to create a
|
| 328 |
start to an adventure based on the world, kingdom, town and character
|
| 329 |
a player is playing as.
|
|
|
|
| 388 |
violated categories. [/INST]"""
|
| 389 |
|
| 390 |
# Build the prompt with embedded values
|
|
|
|
| 391 |
response = client.completions.create(
|
| 392 |
model="Meta-Llama/LlamaGuard-2-8b",
|
| 393 |
prompt=prompt,
|
|
|
|
| 460 |
{"role": "system", "content": system_prompt},
|
| 461 |
{"role": "user", "content": world_info}
|
| 462 |
]
|
| 463 |
+
# Process history as a list of message dictionaries
|
| 464 |
+
for msg in history:
|
| 465 |
+
messages.append({"role": msg["role"], "content": msg["content"]})
|
| 466 |
|
| 467 |
messages.append({"role": "user", "content": message})
|
| 468 |
|
|
|
|
|
|
|
| 469 |
model_output = client.chat.completions.create(
|
| 470 |
model="meta-llama/Llama-3-70b-chat-hf",
|
| 471 |
messages=messages
|