Skip to content

Commit

Permalink
[CLEANUP]
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Nov 19, 2024
1 parent d4014d5 commit 28b8e87
Show file tree
Hide file tree
Showing 5 changed files with 890 additions and 171 deletions.
Binary file removed agorabanner.png
Binary file not shown.
114 changes: 78 additions & 36 deletions v2.py → experimental/v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,35 +50,57 @@ def from_dataset(cls, entry) -> "Persona":
try:
# Print entry for debugging
logger.debug(f"Raw entry: {entry}")

# Extract fields directly from the dataset entry
synthesized_text = str(entry['synthesized_text']) if 'synthesized_text' in entry else ""
input_persona = str(entry['input_persona']) if 'input_persona' in entry else ""
description = str(entry['description']) if 'description' in entry else ""

synthesized_text = (
str(entry["synthesized_text"])
if "synthesized_text" in entry
else ""
)
input_persona = (
str(entry["input_persona"])
if "input_persona" in entry
else ""
)
description = (
str(entry["description"])
if "description" in entry
else ""
)

# Extract name from synthesized text
name_match = re.search(r"Name:\s*([^,\n]+)", synthesized_text)
name = name_match.group(1).strip() if name_match else "Unknown"

logger.debug(f"""
name_match = re.search(
r"Name:\s*([^,\n]+)", synthesized_text
)
name = (
name_match.group(1).strip()
if name_match
else "Unknown"
)

logger.debug(
f"""
Creating persona with:
- Name: {name}
- Description length: {len(description)}
- Input persona length: {len(input_persona)}
- Synthesized text length: {len(synthesized_text)}
""")

"""
)

return cls(
name=name,
description=description,
input_persona=input_persona,
synthesized_text=synthesized_text
synthesized_text=synthesized_text,
)

except Exception as e:
logger.error(f"Error creating persona: {e}")
logger.error(f"Entry that caused error: {entry}")
raise ValueError(f"Failed to create persona from entry: {e}")
raise ValueError(
f"Failed to create persona from entry: {e}"
)


class LocalVectorStore:
Expand Down Expand Up @@ -307,55 +329,75 @@ def _load_personas(self, num_agents: int) -> List[Persona]:
"""Load specified number of personas from PersonaHub"""
try:
# Load the dataset
dataset = load_dataset("proj-persona/PersonaHub", "npc") # Changed to "npc" split
dataset = load_dataset(
"proj-persona/PersonaHub", "npc"
) # Changed to "npc" split
personas = []

# Debug print the dataset structure
logger.debug("Dataset Structure:")
logger.debug(f"Available splits: {dataset.keys()}")
logger.debug(f"First entry structure: {dataset['train'][0]}")
logger.debug(f"First entry keys: {dataset['train'][0].keys() if hasattr(dataset['train'][0], 'keys') else 'No keys method'}")

logger.debug(
f"First entry structure: {dataset['train'][0]}"
)
logger.debug(
f"First entry keys: {dataset['train'][0].keys() if hasattr(dataset['train'][0], 'keys') else 'No keys method'}"
)

# Process entries
for i, entry in enumerate(dataset['train'][:num_agents]):
for i, entry in enumerate(dataset["train"][:num_agents]):
try:
# Convert entry to dictionary if it's not already
if not isinstance(entry, dict):
entry = dict(entry)

logger.debug(f"Processing entry {i}:")
logger.debug(f"Entry type: {type(entry)}")
logger.debug(f"Entry content: {entry}")

# Create persona with proper field access
persona = Persona(
name="Unknown", # Will be updated from synthesized_text
description=str(entry.get('description', '')),
input_persona=str(entry.get('input_persona', '')),
synthesized_text=str(entry.get('synthesized_text', ''))
description=str(entry.get("description", "")),
input_persona=str(
entry.get("input_persona", "")
),
synthesized_text=str(
entry.get("synthesized_text", "")
),
)

# Try to extract name from synthesized text
name_match = re.search(r"Name:\s*([^,\n]+)", persona.synthesized_text)
name_match = re.search(
r"Name:\s*([^,\n]+)", persona.synthesized_text
)
if name_match:
persona.name = name_match.group(1).strip()
else:
persona.name = f"Persona_{i}"

personas.append(persona)
logger.info(f"Successfully loaded persona: {persona.name}")

logger.info(
f"Successfully loaded persona: {persona.name}"
)

except Exception as e:
logger.error(f"Error loading individual persona {i}: {e}")
logger.error(
f"Error loading individual persona {i}: {e}"
)
logger.error(f"Entry that caused error: {entry}")
continue

if not personas:
logger.warning("No personas were successfully loaded!")

logger.info(f"Successfully loaded {len(personas)} personas")
logger.warning(
"No personas were successfully loaded!"
)

logger.info(
f"Successfully loaded {len(personas)} personas"
)
return personas

except Exception as e:
logger.error(f"Error loading personas from dataset: {e}")
raise
Expand Down
Loading

0 comments on commit 28b8e87

Please sign in to comment.