Skip to content

Commit

Permalink
Change project structure.
Browse files Browse the repository at this point in the history
Added script `poetry run run-gui`.
  • Loading branch information
Farmerobot committed Oct 24, 2024
1 parent d46d52a commit f9c8e66
Show file tree
Hide file tree
Showing 38 changed files with 166 additions and 147 deletions.
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 14 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[tool.poetry]
name = "mk-ai-agent-test"
name = "llm_postor"
version = "0.1.0"
description = ""
authors = ["Marcin Korcz, Andrii Chmutov, Vasyl Korzavatykh, Mateusz Idziejczak, Mateusz Stawicki"]
description = "This project tests and compares the persuasive abilities of large language models (LLMs) in a game-like environment simulating 'Among Us', where AI agents powered by LLMs interact, make decisions, and attempt to persuade each other."
authors = ["Marcin Korcz", "Andrii Chmutov", "Vasyl Korzavatykh", "Mateusz Idziejczak", "Mateusz Stawicki"]
readme = "README.md"
package-mode = false
package-mode = true

[tool.poetry.dependencies]
python = "^3.11"
numpy = "^1.26.4"
openai = "^1.23.1"
openai = "^1.23.1"
pandas = "^2.2.2"
torch = "^2.2.2"
torchvision = "^0.17.2"
Expand All @@ -22,22 +22,24 @@ llama-index-embeddings-huggingface = "^0.2.0"
ipykernel = "^6.29.4"
ipywidgets = "^8.1.2"
langchain = "^0.3.3"
langchain-community = "^0.3.2"
langchain-community = "^0.3.2"
langchain-openai = "^0.2.2"
langchain-google-genai = "^2.0.1"
streamlit = "^1.39.0"
pytest = "^8.3.3"
st-annotated-text = "^4.0.1"

[tool.pytest.ini_options]
pythonpath = ["src"]
testpaths = ["tests"]

[tool.poetry.group.dev.dependencies]
ipykernel = "^6.29.4"
pytest = "^8.3.3"
pytest-mock = "^3.14.0"

[tool.pytest.ini_options]
pythonpath = ["src"]
testpaths = ["tests"]

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
build-backend = "poetry.core.masonry.api"

[tool.poetry.scripts]
run-gui = "scripts.run_gui:run_gui"
19 changes: 19 additions & 0 deletions scripts/run_gui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import os
import subprocess

def run_gui():
# Define the project root directory (this assumes the script is located in the scripts/ folder)
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))

# Navigate to the project root directory
os.chdir(project_root)

# Define the path to the demo_gui.py script relative to the project root
demo_gui_path = os.path.join(project_root, "src", "llm_postor", "demo_gui.py")

# Check if the demo_gui.py file exists
if not os.path.exists(demo_gui_path):
raise FileNotFoundError(f"File does not exist: {demo_gui_path}")

# Run the Streamlit app with the correct path
subprocess.run(["poetry", "run", "streamlit", "run", demo_gui_path], check=True)
14 changes: 7 additions & 7 deletions scripts/run_gui.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/bin/bash
#!/bin/bash

# Get the directory of the current script
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Get the directory of the current script
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# Navigate to the project root (assuming this script is located inside `scripts/` directory)
cd "$SCRIPT_DIR/.."
# Navigate to the project root (assuming this script is located inside `scripts/` directory)
cd "$SCRIPT_DIR/.."

# Run the Streamlit app in the Poetry environment
poetry run streamlit run src/demo_gui.py
# Run the Streamlit app in the Poetry environment
poetry run streamlit run src/demo_gui.py
File renamed without changes.
4 changes: 2 additions & 2 deletions src/annotation.py → src/llm_postor/annotation.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import os
import json
from typing import List

from langchain_openai import ChatOpenAI
from game.llm_prompts import ANNOTATION_TEMPLATE
from langchain.schema import HumanMessage

from llm_postor.game.llm_prompts import ANNOTATION_TEMPLATE

def annotate_dialogue(dialogue: str, llm_model_name: str = "gpt-4o-mini") -> str:
"""
Annotates a dialogue with persuasion techniques using OpenAI API.
Expand Down
22 changes: 9 additions & 13 deletions src/demo_gui.py → src/llm_postor/demo_gui.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
import json
import time
from openai import OpenAIError
import streamlit as st
from game.game_engine import GameEngine
from game.players.ai import AIPlayer
from game.gui_handler import GUIHandler
from game.game_state import GameState
from openai import OpenAIError
from types import SimpleNamespace as Namespace
from game.players.fake_ai import FakeAIPlayer
from game.models.engine import GamePhase
from game.chat_analyzer import ChatAnalyzer


from llm_postor.game.game_engine import GameEngine
from llm_postor.game.players.ai import AIPlayer
from llm_postor.game.gui_handler import GUIHandler
from llm_postor.game.game_state import GameState
from llm_postor.game.players.fake_ai import FakeAIPlayer
from llm_postor.game.models.engine import GamePhase
from llm_postor.game.chat_analyzer import ChatAnalyzer

# To run this script, you need to poetry install and then run the following command:
# streamlit run src/demo_gui.py




def main():
st.title("Among Us Game - susGPT")
st.title("Among Us Game - LLMPostor")
gui_handler = GUIHandler()
game_engine = GameEngine()

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import re
from typing import List, Any

from langchain_openai import ChatOpenAI

from game.consts import ASCII_MAP
from .base_agent import Agent
from langchain.schema import HumanMessage
from game.llm_prompts import ADVENTURE_PLAN_TEMPLATE, ADVENTURE_ACTION_TEMPLATE
import re
from langchain_openai import ChatOpenAI

from llm_postor.game.agents.base_agent import Agent
from llm_postor.game.consts import ASCII_MAP
from llm_postor.game.llm_prompts import ADVENTURE_PLAN_TEMPLATE, ADVENTURE_ACTION_TEMPLATE

class AdventureAgent(Agent):
def update_state(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
from typing import Any, List
from pydantic import BaseModel, Field

from game.agents.usage_metadata import UsageMetadata
from game.consts import TOKEN_COSTS

from llm_postor.game.agents.usage_metadata import UsageMetadata
from llm_postor.game.consts import TOKEN_COSTS

class AgentState(BaseModel):
history: str = Field(default_factory=str)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from typing import List, Any
from .base_agent import Agent
from langchain.schema import HumanMessage
from game.llm_prompts import DISCUSSION_TEMPLATE, DISCUSSION_RESPONSE_TEMPLATE

from llm_postor.game.llm_prompts import DISCUSSION_TEMPLATE
from llm_postor.game.llm_prompts import DISCUSSION_RESPONSE_TEMPLATE

class DiscussionAgent(Agent):
def update_state(
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import re
from typing import List, Any
from .base_agent import Agent
from langchain.schema import HumanMessage
from game.llm_prompts import VOTING_TEMPLATE
import re

from llm_postor.game.llm_prompts import VOTING_TEMPLATE

class VotingAgent(Agent):
def update_state(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import re
from typing import List, Dict
from pydantic import BaseModel
from game.players.base_player import Player
from langchain_openai import ChatOpenAI
from game.llm_prompts import PERSUASION_TECHNIQUES
from langchain.schema import HumanMessage
import re

from llm_postor.game.players.base_player import Player
from llm_postor.game.llm_prompts import PERSUASION_TECHNIQUES

class ChatAnalyzer(BaseModel):
players: List[Player]
Expand Down
File renamed without changes.
35 changes: 17 additions & 18 deletions src/game/game_engine.py → src/llm_postor/game/game_engine.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
import random
import json
import streamlit as st
from game.game_state import GameState
from game.models.engine import (
GamePhase,
GameLocation,
DOORS,
)
from game.players.base_player import Player, PlayerRole
from game.models.history import PlayerState
from game.players.human import HumanPlayer
from game.models.action import GameAction, GameActionType
from typing import Any, List
import random
from game import consts as game_consts
from collections import Counter
from pydantic import BaseModel, Field
import json

from game.players.ai import AIPlayer
from game.players.fake_ai import FakeAIPlayer
from game.models.tasks import ShortTask, LongTask, Task
from game.agents.base_agent import Agent

from llm_postor.game import consts as game_consts
from llm_postor.game.game_state import GameState
from llm_postor.game.models.engine import (
GamePhase,
GameLocation,
DOORS,
)
from llm_postor.game.players.base_player import Player, PlayerRole
from llm_postor.game.models.history import PlayerState
from llm_postor.game.players.human import HumanPlayer
from llm_postor.game.models.action import GameAction, GameActionType
from llm_postor.game.players.ai import AIPlayer
from llm_postor.game.players.fake_ai import FakeAIPlayer
from llm_postor.game.models.tasks import ShortTask, LongTask, Task
from llm_postor.game.agents.base_agent import Agent

class GameEngine(BaseModel):
"""Manages the game logic, including player actions, game state transitions, and win conditions."""
Expand Down
7 changes: 3 additions & 4 deletions src/game/game_state.py → src/llm_postor/game/game_state.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from game.models.engine import GameLocation, GamePhase
from game.models.history import PlayerState
from game.players.base_player import Player
from typing import List
from pydantic import BaseModel, Field

from llm_postor.game.models.engine import GameLocation, GamePhase
from llm_postor.game.models.history import PlayerState
from llm_postor.game.players.base_player import Player

class GameState(BaseModel):
players: List[Player] = Field(default_factory=list)
Expand Down
11 changes: 5 additions & 6 deletions src/game/gui_handler.py → src/llm_postor/game/gui_handler.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
from typing import Any, List, Dict, Optional
import streamlit as st
from game.game_state import GameState
from typing import Any, List, Dict, Optional
from pydantic import BaseModel, Field
from game.players.base_player import Player, PlayerRole
from streamlit.delta_generator import DeltaGenerator
from annotated_text import annotated_text

from game.models.history import PlayerState
from game.chat_analyzer import ChatAnalyzer

from llm_postor.game.game_state import GameState
from llm_postor.game.players.base_player import Player, PlayerRole
from llm_postor.game.models.history import PlayerState
from llm_postor.game.chat_analyzer import ChatAnalyzer

class GUIHandler(BaseModel):
player_states_placeholders: List[DeltaGenerator] = Field(default_factory=list)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,20 +196,20 @@

PERSUASION_TECHNIQUES = """
### 1. **Appeal to Logic (Logos)**
**Description**: Using facts, evidence, or logical reasoning to convince others. This can include referencing actions, timings, or task completion to logically argue who the imposter is or isn't.
**Example**: "I was with Blue in Medbay the whole time, and I saw them scan. Therefore, they can't be the imposter."
**Description**: Using facts, evidence, or logical reasoning to convince others. This can include referencing actions, timings, or task completion to logically argue who the impostor is or isn't.
**Example**: "I was with Blue in Medbay the whole time, and I saw them scan. Therefore, they can't be the impostor."
### 2. **Appeal to Emotion (Pathos)**
**Description**: Persuading by evoking an emotional response, such as fear, sympathy, or trust.
**Example**: "If you vote me out now, the imposters will win, and it'll be your fault."
**Example**: "If you vote me out now, the impostors will win, and it'll be your fault."
### 3. **Appeal to Credibility (Ethos)**
**Description**: Convincing others based on the trustworthiness or authority of the speaker.
**Example**: "I’ve never lied in this game before, and I’ve proven myself innocent multiple times."
### 4. **Shifting the Burden of Proof**
**Description**: Forcing others to prove their innocence instead of presenting clear evidence of guilt.
**Example**: "If you’re not the imposter, prove it. What tasks have you completed?"
**Example**: "If you’re not the impostor, prove it. What tasks have you completed?"
### 5. **Bandwagon Effect**
**Description**: Convincing others to agree by emphasizing that everyone else is already on board with the idea.
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
from pydantic import Field, BaseModel, model_validator
from enum import IntEnum

from game.consts import IMPOSTOR_COOLDOWN
from game.models.engine import GameLocation
from game.models.history import PlayerState
from game.models.tasks import Task
from game.players.base_player import Player, PlayerRole

from llm_postor.game.consts import IMPOSTOR_COOLDOWN
from llm_postor.game.models.engine import GameLocation
from llm_postor.game.models.history import PlayerState
from llm_postor.game.models.tasks import Task
from llm_postor.game.players.base_player import Player, PlayerRole

class GameActionType(IntEnum):
VOTE = -1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from enum import Enum


class GamePhase(str, Enum):
MAIN_MENU = "Main Menu"
ACTION_PHASE = "Action Phase"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
from typing import List
from pydantic import BaseModel, Field

from game.models.engine import GameLocation, GamePhase
from game.models.tasks import Task
from game.agents.usage_metadata import UsageMetadata

from llm_postor.game.models.engine import GameLocation, GamePhase
from llm_postor.game.models.tasks import Task
from llm_postor.game.agents.usage_metadata import UsageMetadata

class PlayerState(str, Enum):
ALIVE = "Alive"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from abc import ABC, abstractmethod
from pydantic import BaseModel

from game.models.engine import GameLocation

from llm_postor.game.models.engine import GameLocation

class Task(BaseModel, ABC):
name: str
Expand Down
Empty file.
13 changes: 5 additions & 8 deletions src/game/players/ai.py → src/llm_postor/game/players/ai.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
from typing import List

from game.agents.adventure_agent import AdventureAgent
from game.agents.discussion_agent import DiscussionAgent
from game.agents.voting_agent import VotingAgent
from game.players.base_player import Player, PlayerRole

from langchain_openai import ChatOpenAI
from langchain_google_genai import ChatGoogleGenerativeAI

from game.agents.usage_metadata import UsageMetadata

from llm_postor.game.agents.adventure_agent import AdventureAgent
from llm_postor.game.agents.discussion_agent import DiscussionAgent
from llm_postor.game.agents.voting_agent import VotingAgent
from llm_postor.game.players.base_player import Player, PlayerRole
from llm_postor.game.agents.usage_metadata import UsageMetadata

class AIPlayer(Player):
llm_model_name: str
Expand Down
Loading

0 comments on commit f9c8e66

Please sign in to comment.