dialectus-engine 0.1.1__tar.gz → 0.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {dialectus_engine-0.1.1/dialectus_engine.egg-info → dialectus_engine-0.1.2}/PKG-INFO +3 -3
- dialectus_engine-0.1.2/dialectus/__init__.py +7 -0
- dialectus_engine-0.1.2/dialectus/engine/config/__init__.py +1 -0
- dialectus_engine-0.1.2/dialectus/engine/config/openrouter_filters.json +153 -0
- dialectus_engine-0.1.2/dialectus/engine/config/settings.py +248 -0
- dialectus_engine-0.1.2/dialectus/engine/debate_engine/__init__.py +24 -0
- dialectus_engine-0.1.2/dialectus/engine/debate_engine/context_builder.py +161 -0
- dialectus_engine-0.1.2/dialectus/engine/debate_engine/engine.py +190 -0
- dialectus_engine-0.1.2/dialectus/engine/debate_engine/judge_coordinator.py +106 -0
- dialectus_engine-0.1.2/dialectus/engine/debate_engine/models.py +39 -0
- dialectus_engine-0.1.2/dialectus/engine/debate_engine/prompt_builder.py +177 -0
- dialectus_engine-0.1.2/dialectus/engine/debate_engine/response_handler.py +337 -0
- dialectus_engine-0.1.2/dialectus/engine/debate_engine/round_manager.py +195 -0
- dialectus_engine-0.1.2/dialectus/engine/debate_engine/types.py +21 -0
- dialectus_engine-0.1.2/dialectus/engine/debate_engine/utils.py +99 -0
- dialectus_engine-0.1.2/dialectus/engine/formats/__init__.py +34 -0
- dialectus_engine-0.1.2/dialectus/engine/formats/base.py +139 -0
- dialectus_engine-0.1.2/dialectus/engine/formats/oxford.py +149 -0
- dialectus_engine-0.1.2/dialectus/engine/formats/parliamentary.py +133 -0
- dialectus_engine-0.1.2/dialectus/engine/formats/public_forum.py +161 -0
- dialectus_engine-0.1.2/dialectus/engine/formats/registry.py +63 -0
- dialectus_engine-0.1.2/dialectus/engine/formats/socratic.py +158 -0
- dialectus_engine-0.1.2/dialectus/engine/formats/topic_themes.py +233 -0
- dialectus_engine-0.1.2/dialectus/engine/judges/__init__.py +15 -0
- dialectus_engine-0.1.2/dialectus/engine/judges/ai_judge.py +561 -0
- dialectus_engine-0.1.2/dialectus/engine/judges/base.py +146 -0
- dialectus_engine-0.1.2/dialectus/engine/judges/ensemble_utils.py +174 -0
- dialectus_engine-0.1.2/dialectus/engine/judges/factory.py +70 -0
- dialectus_engine-0.1.2/dialectus/engine/models/__init__.py +1 -0
- dialectus_engine-0.1.2/dialectus/engine/models/base_types.py +85 -0
- dialectus_engine-0.1.2/dialectus/engine/models/cache_manager.py +316 -0
- dialectus_engine-0.1.2/dialectus/engine/models/manager.py +268 -0
- dialectus_engine-0.1.2/dialectus/engine/models/openrouter/openrouter_architecture.py +8 -0
- dialectus_engine-0.1.2/dialectus/engine/models/openrouter/openrouter_capability_extractor.py +245 -0
- dialectus_engine-0.1.2/dialectus/engine/models/openrouter/openrouter_enhanced_model_info.py +95 -0
- dialectus_engine-0.1.2/dialectus/engine/models/openrouter/openrouter_filter_config.py +234 -0
- dialectus_engine-0.1.2/dialectus/engine/models/openrouter/openrouter_model.py +27 -0
- dialectus_engine-0.1.2/dialectus/engine/models/openrouter/openrouter_model_filter.py +367 -0
- dialectus_engine-0.1.2/dialectus/engine/models/openrouter/openrouter_models_response.py +6 -0
- dialectus_engine-0.1.2/dialectus/engine/models/openrouter/openrouter_pricing.py +33 -0
- dialectus_engine-0.1.2/dialectus/engine/models/openrouter/openrouter_top_provider.py +8 -0
- dialectus_engine-0.1.2/dialectus/engine/models/providers/__init__.py +15 -0
- dialectus_engine-0.1.2/dialectus/engine/models/providers/base_model_provider.py +106 -0
- dialectus_engine-0.1.2/dialectus/engine/models/providers/exceptions.py +30 -0
- dialectus_engine-0.1.2/dialectus/engine/models/providers/ollama_provider.py +369 -0
- dialectus_engine-0.1.2/dialectus/engine/models/providers/open_router_provider.py +704 -0
- dialectus_engine-0.1.2/dialectus/engine/models/providers/openrouter_generation_types.py +58 -0
- dialectus_engine-0.1.2/dialectus/engine/models/providers/providers.py +35 -0
- {dialectus_engine-0.1.1 → dialectus_engine-0.1.2/dialectus_engine.egg-info}/PKG-INFO +3 -3
- dialectus_engine-0.1.2/dialectus_engine.egg-info/SOURCES.txt +104 -0
- {dialectus_engine-0.1.1 → dialectus_engine-0.1.2}/pyproject.toml +10 -4
- dialectus_engine-0.1.1/dialectus/__init__.py +0 -3
- dialectus_engine-0.1.1/dialectus_engine.egg-info/SOURCES.txt +0 -10
- {dialectus_engine-0.1.1 → dialectus_engine-0.1.2}/LICENSE +0 -0
- {dialectus_engine-0.1.1 → dialectus_engine-0.1.2}/README.md +0 -0
- {dialectus_engine-0.1.1 → dialectus_engine-0.1.2}/dialectus/engine/__init__.py +0 -0
- {dialectus_engine-0.1.1 → dialectus_engine-0.1.2}/dialectus_engine.egg-info/dependency_links.txt +0 -0
- {dialectus_engine-0.1.1 → dialectus_engine-0.1.2}/dialectus_engine.egg-info/requires.txt +0 -0
- {dialectus_engine-0.1.1 → dialectus_engine-0.1.2}/dialectus_engine.egg-info/top_level.txt +0 -0
- {dialectus_engine-0.1.1 → dialectus_engine-0.1.2}/setup.cfg +0 -0
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dialectus-engine
|
|
3
|
-
Version: 0.1.
|
|
4
|
-
Summary: AI debate engine framework
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary: Dialectus AI debate engine framework
|
|
5
5
|
Author: Dialectus AI
|
|
6
6
|
License-Expression: MIT
|
|
7
7
|
Project-URL: Homepage, https://github.com/dialectus-ai/dialectus-engine
|
|
8
8
|
Project-URL: Repository, https://github.com/dialectus-ai/dialectus-engine
|
|
9
9
|
Project-URL: Issues, https://github.com/dialectus-ai/dialectus-engine/issues
|
|
10
|
-
Keywords: ai,debate,llm,
|
|
10
|
+
Keywords: ai,debate,llm,ollama,openrouter,artificial-intelligence
|
|
11
11
|
Classifier: Development Status :: 4 - Beta
|
|
12
12
|
Classifier: Intended Audience :: Developers
|
|
13
13
|
Classifier: Intended Audience :: Education
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Configuration management for the AI debate system."""
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "1.0",
|
|
3
|
+
"description": "OpenRouter model filtering configuration for Dialectus AI debate system",
|
|
4
|
+
"last_updated": "2025-01-13",
|
|
5
|
+
"filters": {
|
|
6
|
+
"exclude_patterns": [
|
|
7
|
+
{
|
|
8
|
+
"category": "meta_routing_models",
|
|
9
|
+
"description": "Meta/Router models that automatically select underlying models",
|
|
10
|
+
"patterns": [
|
|
11
|
+
"auto.*router",
|
|
12
|
+
"router",
|
|
13
|
+
"meta.*llama.*auto",
|
|
14
|
+
"mixture.*expert",
|
|
15
|
+
"moe",
|
|
16
|
+
"auto.*select",
|
|
17
|
+
"smart.*router",
|
|
18
|
+
"dynamic.*router"
|
|
19
|
+
]
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"category": "audio_speech_models",
|
|
23
|
+
"description": "Audio and speech processing models",
|
|
24
|
+
"patterns": [
|
|
25
|
+
"whisper",
|
|
26
|
+
"tts-",
|
|
27
|
+
"stt-",
|
|
28
|
+
"bark",
|
|
29
|
+
"speech",
|
|
30
|
+
"audio"
|
|
31
|
+
]
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"category": "image_generation_models",
|
|
35
|
+
"description": "Image/vision generation models (multimodal input models like GPT-4V are allowed)",
|
|
36
|
+
"patterns": [
|
|
37
|
+
"dall-e",
|
|
38
|
+
"stable-diffusion",
|
|
39
|
+
"midjourney",
|
|
40
|
+
"flux",
|
|
41
|
+
"sdxl",
|
|
42
|
+
"imagen",
|
|
43
|
+
"firefly"
|
|
44
|
+
]
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"category": "video_models",
|
|
48
|
+
"description": "Video processing and generation models",
|
|
49
|
+
"patterns": [
|
|
50
|
+
"video",
|
|
51
|
+
"runway",
|
|
52
|
+
"luma",
|
|
53
|
+
"pika",
|
|
54
|
+
"kling"
|
|
55
|
+
]
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"category": "code_specialized_models",
|
|
59
|
+
"description": "Code-specific models (too specialized for general debate)",
|
|
60
|
+
"patterns": [
|
|
61
|
+
"code-",
|
|
62
|
+
"-code",
|
|
63
|
+
"-coder",
|
|
64
|
+
"codestral",
|
|
65
|
+
"codegeex",
|
|
66
|
+
"codegen",
|
|
67
|
+
"starcoder",
|
|
68
|
+
"deepseek-coder",
|
|
69
|
+
"wizardcoder",
|
|
70
|
+
"phind-code"
|
|
71
|
+
]
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"category": "embedding_vector_models",
|
|
75
|
+
"description": "Embedding and vector similarity models",
|
|
76
|
+
"patterns": [
|
|
77
|
+
"embed",
|
|
78
|
+
"embedding",
|
|
79
|
+
"vector",
|
|
80
|
+
"similarity"
|
|
81
|
+
]
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"category": "moderation_safety_models",
|
|
85
|
+
"description": "Content moderation and safety models",
|
|
86
|
+
"patterns": [
|
|
87
|
+
"moderation",
|
|
88
|
+
"safety",
|
|
89
|
+
"guardrail"
|
|
90
|
+
]
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
"category": "search_rag_models",
|
|
94
|
+
"description": "Search and RAG-specific models",
|
|
95
|
+
"patterns": [
|
|
96
|
+
"search",
|
|
97
|
+
"retrieval",
|
|
98
|
+
"rag-"
|
|
99
|
+
]
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
"category": "math_science_specialized",
|
|
103
|
+
"description": "Math/Science specialized models (too narrow for general debate)",
|
|
104
|
+
"patterns": [
|
|
105
|
+
"math-",
|
|
106
|
+
"scientific-",
|
|
107
|
+
"theorem",
|
|
108
|
+
"proof-"
|
|
109
|
+
]
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
"category": "translation_only_models",
|
|
113
|
+
"description": "Translation-only models (too specific for debate)",
|
|
114
|
+
"patterns": [
|
|
115
|
+
"translate-",
|
|
116
|
+
"translation-",
|
|
117
|
+
"-translator"
|
|
118
|
+
]
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
"category": "jailbreak_variants",
|
|
122
|
+
"description": "Problematic jailbreak model variants",
|
|
123
|
+
"patterns": [
|
|
124
|
+
"jailbreak"
|
|
125
|
+
]
|
|
126
|
+
}
|
|
127
|
+
],
|
|
128
|
+
"preview_patterns": [
|
|
129
|
+
{
|
|
130
|
+
"category": "preview_anonymous_models",
|
|
131
|
+
"description": "Preview, anonymous, and experimental models",
|
|
132
|
+
"patterns": [
|
|
133
|
+
"^sonoma-",
|
|
134
|
+
"^preview-",
|
|
135
|
+
"^anonymous-",
|
|
136
|
+
"^beta-",
|
|
137
|
+
"^test-",
|
|
138
|
+
"-preview$",
|
|
139
|
+
"-beta$",
|
|
140
|
+
"-alpha$",
|
|
141
|
+
"experimental"
|
|
142
|
+
]
|
|
143
|
+
}
|
|
144
|
+
]
|
|
145
|
+
},
|
|
146
|
+
"settings": {
|
|
147
|
+
"allow_preview_models": false,
|
|
148
|
+
"exclude_free_tier_models": false,
|
|
149
|
+
"max_cost_per_1k_tokens": 0.02,
|
|
150
|
+
"min_context_length": 4096,
|
|
151
|
+
"max_models_per_tier": 8
|
|
152
|
+
}
|
|
153
|
+
}
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
"""Configuration settings and data models."""
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Literal
|
|
5
|
+
|
|
6
|
+
from pydantic import BaseModel, Field, field_validator
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class ModelConfig(BaseModel):
|
|
10
|
+
"""Configuration for a debate model."""
|
|
11
|
+
|
|
12
|
+
name: str = Field(
|
|
13
|
+
...,
|
|
14
|
+
description="Model name (e.g., 'llama3.2:3b' for Ollama, 'openai/gpt-4' for OpenRouter)",
|
|
15
|
+
)
|
|
16
|
+
provider: str = Field(
|
|
17
|
+
default="ollama", description="Model provider (ollama, openrouter, etc.)"
|
|
18
|
+
)
|
|
19
|
+
personality: str = Field(default="neutral", description="Debate personality style")
|
|
20
|
+
max_tokens: int = Field(default=300, description="Maximum tokens per response")
|
|
21
|
+
temperature: float = Field(default=0.7, description="Model temperature")
|
|
22
|
+
|
|
23
|
+
@field_validator("provider")
|
|
24
|
+
@classmethod
|
|
25
|
+
def validate_provider(cls, v: str):
|
|
26
|
+
valid_providers = {"ollama", "openrouter"}
|
|
27
|
+
if v not in valid_providers:
|
|
28
|
+
raise ValueError(f"Provider must be one of: {valid_providers}")
|
|
29
|
+
return v
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class DebateConfig(BaseModel):
|
|
33
|
+
"""Main debate configuration."""
|
|
34
|
+
|
|
35
|
+
topic: str = Field(..., description="Debate topic")
|
|
36
|
+
format: str = Field(default="oxford", description="Debate format")
|
|
37
|
+
time_per_turn: int = Field(default=120, description="Seconds per turn")
|
|
38
|
+
word_limit: int = Field(default=200, description="Word limit per turn")
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class JudgingConfig(BaseModel):
|
|
42
|
+
"""Judging system configuration."""
|
|
43
|
+
|
|
44
|
+
criteria: list[str] = Field(
|
|
45
|
+
default=["logic", "evidence", "persuasiveness"], description="Scoring criteria"
|
|
46
|
+
)
|
|
47
|
+
judge_models: list[str] = Field(
|
|
48
|
+
default=[], description="Models to use for AI judging"
|
|
49
|
+
)
|
|
50
|
+
judge_provider: str | None = Field(
|
|
51
|
+
default=None, description="Provider for the judge models"
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class OllamaConfig(BaseModel):
|
|
56
|
+
"""Ollama-specific configuration for hardware optimization."""
|
|
57
|
+
|
|
58
|
+
num_gpu_layers: int | None = Field(
|
|
59
|
+
default=None,
|
|
60
|
+
description="Number of layers to offload to GPU (-1 for all, 0 for CPU-only)",
|
|
61
|
+
)
|
|
62
|
+
gpu_memory_utilization: float | None = Field(
|
|
63
|
+
default=None, description="GPU memory utilization percentage (0.0-1.0)"
|
|
64
|
+
)
|
|
65
|
+
main_gpu: int | None = Field(
|
|
66
|
+
default=None, description="Primary GPU device ID for multi-GPU setups"
|
|
67
|
+
)
|
|
68
|
+
num_thread: int | None = Field(
|
|
69
|
+
default=None, description="Number of CPU threads for processing"
|
|
70
|
+
)
|
|
71
|
+
keep_alive: str | None = Field(
|
|
72
|
+
default="5m",
|
|
73
|
+
description="How long to keep models loaded (e.g., '5m', '1h', '0' for immediate unload)",
|
|
74
|
+
)
|
|
75
|
+
repeat_penalty: float | None = Field(
|
|
76
|
+
default=1.1, description="Penalty for repetition in responses"
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class OpenRouterConfig(BaseModel):
|
|
81
|
+
"""OpenRouter-specific configuration."""
|
|
82
|
+
|
|
83
|
+
api_key: str | None = Field(
|
|
84
|
+
default=None,
|
|
85
|
+
description="OpenRouter API key (can also be set via OPENROUTER_API_KEY env var)",
|
|
86
|
+
)
|
|
87
|
+
base_url: str = Field(
|
|
88
|
+
default="https://openrouter.ai/api/v1", description="OpenRouter API base URL"
|
|
89
|
+
)
|
|
90
|
+
site_url: str | None = Field(
|
|
91
|
+
default=None, description="Your site URL for OpenRouter referrer tracking"
|
|
92
|
+
)
|
|
93
|
+
app_name: str | None = Field(
|
|
94
|
+
default="Dialectus AI Debate System",
|
|
95
|
+
description="App name for OpenRouter tracking",
|
|
96
|
+
)
|
|
97
|
+
max_retries: int = Field(
|
|
98
|
+
default=3, description="Maximum number of API call retries"
|
|
99
|
+
)
|
|
100
|
+
timeout: int = Field(default=60, description="API request timeout in seconds")
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
class SystemConfig(BaseModel):
|
|
104
|
+
"""System-wide configuration."""
|
|
105
|
+
|
|
106
|
+
# Ollama configuration (backward compatibility)
|
|
107
|
+
ollama_base_url: str = Field(
|
|
108
|
+
default="http://localhost:11434", description="Ollama API URL"
|
|
109
|
+
)
|
|
110
|
+
ollama: OllamaConfig = Field(
|
|
111
|
+
default_factory=OllamaConfig, description="Ollama-specific settings"
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
# Provider configurations
|
|
115
|
+
openrouter: OpenRouterConfig = Field(
|
|
116
|
+
default_factory=OpenRouterConfig, description="OpenRouter-specific settings"
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
# System settings
|
|
120
|
+
log_level: Literal["DEBUG", "INFO", "WARNING", "ERROR"] = Field(default="INFO")
|
|
121
|
+
|
|
122
|
+
# Topic generation settings
|
|
123
|
+
debate_topic_source: Literal["ollama", "openrouter"] = Field(
|
|
124
|
+
default="openrouter", description="Provider for topic generation model"
|
|
125
|
+
)
|
|
126
|
+
debate_topic_model: str = Field(
|
|
127
|
+
default="anthropic/claude-3-haiku",
|
|
128
|
+
description="Model name for topic generation",
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
@field_validator("debate_topic_source")
|
|
132
|
+
@classmethod
|
|
133
|
+
def validate_topic_source(cls, v: str):
|
|
134
|
+
valid_sources = {"ollama", "openrouter"}
|
|
135
|
+
if v not in valid_sources:
|
|
136
|
+
raise ValueError(f"debate_topic_source must be one of: {valid_sources}")
|
|
137
|
+
return v
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
class AppConfig(BaseModel):
|
|
141
|
+
"""Complete application configuration."""
|
|
142
|
+
|
|
143
|
+
debate: DebateConfig
|
|
144
|
+
models: dict[str, ModelConfig]
|
|
145
|
+
judging: JudgingConfig
|
|
146
|
+
system: SystemConfig
|
|
147
|
+
|
|
148
|
+
@classmethod
|
|
149
|
+
def load_from_file(cls, config_path: Path) -> "AppConfig":
|
|
150
|
+
"""Load configuration from JSON file."""
|
|
151
|
+
if not config_path.exists():
|
|
152
|
+
raise FileNotFoundError(f"Config file not found: {config_path}")
|
|
153
|
+
|
|
154
|
+
import json
|
|
155
|
+
|
|
156
|
+
with open(config_path, encoding="utf-8") as f:
|
|
157
|
+
data = json.load(f)
|
|
158
|
+
|
|
159
|
+
# Validate required sections
|
|
160
|
+
required_sections = ["debate", "models", "judging", "system"]
|
|
161
|
+
missing_sections = [
|
|
162
|
+
section for section in required_sections if section not in data
|
|
163
|
+
]
|
|
164
|
+
if missing_sections:
|
|
165
|
+
raise ValueError(f"Missing required config sections: {missing_sections}")
|
|
166
|
+
|
|
167
|
+
# Validate models section has at least one model
|
|
168
|
+
if not data.get("models") or len(data["models"]) == 0:
|
|
169
|
+
raise ValueError(
|
|
170
|
+
"Config must include at least one model in 'models' section"
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
return cls(**data)
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def get_default_config() -> AppConfig:
|
|
177
|
+
"""Load default configuration from debate_config.json, creating it if needed."""
|
|
178
|
+
config_path = Path("debate_config.json")
|
|
179
|
+
if not config_path.exists():
|
|
180
|
+
# Auto-create from debate_config.example.json if it exists
|
|
181
|
+
example_path = Path("debate_config.example.json")
|
|
182
|
+
if example_path.exists():
|
|
183
|
+
import shutil
|
|
184
|
+
|
|
185
|
+
shutil.copy2(example_path, config_path)
|
|
186
|
+
else:
|
|
187
|
+
# Fallback to template config
|
|
188
|
+
template_config = get_template_config()
|
|
189
|
+
import json
|
|
190
|
+
|
|
191
|
+
with open(config_path, "w", encoding="utf-8") as f:
|
|
192
|
+
json.dump(template_config.model_dump(exclude_unset=True), f, indent=2)
|
|
193
|
+
return AppConfig.load_from_file(config_path)
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def get_template_config() -> AppConfig:
|
|
197
|
+
"""Get template configuration for config file generation."""
|
|
198
|
+
return AppConfig(
|
|
199
|
+
debate=DebateConfig(
|
|
200
|
+
topic="Should artificial intelligence be regulated by government oversight?",
|
|
201
|
+
format="oxford",
|
|
202
|
+
time_per_turn=120,
|
|
203
|
+
word_limit=100,
|
|
204
|
+
),
|
|
205
|
+
models={
|
|
206
|
+
"model_a": ModelConfig(
|
|
207
|
+
name="qwen2.5:7b",
|
|
208
|
+
provider="ollama",
|
|
209
|
+
personality="analytical",
|
|
210
|
+
max_tokens=300,
|
|
211
|
+
temperature=0.7,
|
|
212
|
+
),
|
|
213
|
+
"model_b": ModelConfig(
|
|
214
|
+
name="openai/gpt-4",
|
|
215
|
+
provider="openrouter",
|
|
216
|
+
personality="passionate",
|
|
217
|
+
max_tokens=300,
|
|
218
|
+
temperature=0.8,
|
|
219
|
+
),
|
|
220
|
+
},
|
|
221
|
+
judging=JudgingConfig(
|
|
222
|
+
criteria=["logic", "evidence", "persuasiveness"],
|
|
223
|
+
judge_models=["openthinker:7b"],
|
|
224
|
+
judge_provider="ollama",
|
|
225
|
+
),
|
|
226
|
+
system=SystemConfig(
|
|
227
|
+
ollama_base_url="http://localhost:11434",
|
|
228
|
+
ollama=OllamaConfig(
|
|
229
|
+
num_gpu_layers=-1, # Use all GPU layers by default
|
|
230
|
+
gpu_memory_utilization=None,
|
|
231
|
+
main_gpu=None,
|
|
232
|
+
num_thread=None,
|
|
233
|
+
keep_alive="5m",
|
|
234
|
+
repeat_penalty=1.1,
|
|
235
|
+
),
|
|
236
|
+
openrouter=OpenRouterConfig(
|
|
237
|
+
api_key=None, # Set your OpenRouter API key here or use OPENROUTER_API_KEY env var
|
|
238
|
+
base_url="https://openrouter.ai/api/v1",
|
|
239
|
+
site_url=None, # Your site URL for referrer tracking (optional)
|
|
240
|
+
app_name="Dialectus AI Debate System",
|
|
241
|
+
max_retries=3,
|
|
242
|
+
timeout=60,
|
|
243
|
+
),
|
|
244
|
+
log_level="INFO",
|
|
245
|
+
debate_topic_source="openrouter",
|
|
246
|
+
debate_topic_model="anthropic/claude-3-haiku",
|
|
247
|
+
),
|
|
248
|
+
)
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"""Debate orchestration and flow management."""
|
|
2
|
+
|
|
3
|
+
from .context_builder import ContextBuilder
|
|
4
|
+
from .engine import DebateEngine
|
|
5
|
+
from .judge_coordinator import JudgeCoordinator
|
|
6
|
+
from .models import DebateContext, DebateMessage
|
|
7
|
+
from .prompt_builder import PERSONALITY_TYPES, PromptBuilder
|
|
8
|
+
from .response_handler import ResponseHandler
|
|
9
|
+
from .round_manager import RoundManager
|
|
10
|
+
from .types import DebatePhase, Position
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
"DebateEngine",
|
|
14
|
+
"DebatePhase",
|
|
15
|
+
"Position",
|
|
16
|
+
"DebateContext",
|
|
17
|
+
"DebateMessage",
|
|
18
|
+
"PromptBuilder",
|
|
19
|
+
"PERSONALITY_TYPES",
|
|
20
|
+
"ContextBuilder",
|
|
21
|
+
"ResponseHandler",
|
|
22
|
+
"RoundManager",
|
|
23
|
+
"JudgeCoordinator",
|
|
24
|
+
]
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"""Conversation context building for debate participants."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import TYPE_CHECKING
|
|
6
|
+
|
|
7
|
+
from dialectus.engine.config.settings import AppConfig
|
|
8
|
+
|
|
9
|
+
from .models import DebateContext
|
|
10
|
+
from .prompt_builder import PromptBuilder
|
|
11
|
+
from .types import DebatePhase
|
|
12
|
+
|
|
13
|
+
if TYPE_CHECKING:
|
|
14
|
+
from dialectus.engine.formats import DebateFormat, FormatPhase
|
|
15
|
+
|
|
16
|
+
class ContextBuilder:
|
|
17
|
+
"""Builds conversation context for model prompts during debates."""
|
|
18
|
+
|
|
19
|
+
def __init__(
|
|
20
|
+
self,
|
|
21
|
+
config: AppConfig,
|
|
22
|
+
debate_format: DebateFormat,
|
|
23
|
+
prompt_builder: PromptBuilder,
|
|
24
|
+
):
|
|
25
|
+
"""Initialize the context builder.
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
config: Application configuration
|
|
29
|
+
debate_format: The debate format being used
|
|
30
|
+
prompt_builder: PromptBuilder instance for accessing system prompts
|
|
31
|
+
"""
|
|
32
|
+
self.config = config
|
|
33
|
+
self.format = debate_format
|
|
34
|
+
self.prompt_builder = prompt_builder
|
|
35
|
+
|
|
36
|
+
def build_conversation_context(
|
|
37
|
+
self,
|
|
38
|
+
speaker_id: str,
|
|
39
|
+
phase: DebatePhase,
|
|
40
|
+
context: DebateContext,
|
|
41
|
+
) -> list[dict[str, str]]:
|
|
42
|
+
"""Build conversation context for the model.
|
|
43
|
+
|
|
44
|
+
Args:
|
|
45
|
+
speaker_id: ID of the speaking model
|
|
46
|
+
phase: Current debate phase
|
|
47
|
+
context: The debate context
|
|
48
|
+
|
|
49
|
+
Returns:
|
|
50
|
+
List of message dictionaries for the model API
|
|
51
|
+
"""
|
|
52
|
+
messages: list[dict[str, str]] = []
|
|
53
|
+
|
|
54
|
+
# Add system prompt
|
|
55
|
+
if speaker_id in self.prompt_builder.system_prompts:
|
|
56
|
+
messages.append(
|
|
57
|
+
{"role": "system", "content": self.prompt_builder.system_prompts[speaker_id]}
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
# Add role-focused phase instruction
|
|
61
|
+
model_ids = list(context.participants.keys())
|
|
62
|
+
side_labels = self.format.get_side_labels(model_ids)
|
|
63
|
+
role_name = side_labels.get(speaker_id, "Speaker")
|
|
64
|
+
|
|
65
|
+
phase_instruction = PromptBuilder.get_phase_instruction(phase)
|
|
66
|
+
messages.append(
|
|
67
|
+
{
|
|
68
|
+
"role": "system",
|
|
69
|
+
"content": f"You are now speaking as {role_name}. {phase_instruction}",
|
|
70
|
+
}
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
# Add relevant debate history
|
|
74
|
+
for msg in context.messages[-6:]: # Last 6 messages for context
|
|
75
|
+
role = "assistant" if msg.speaker_id == speaker_id else "user"
|
|
76
|
+
|
|
77
|
+
# Use a cleaner format that's less likely to be repeated by small models
|
|
78
|
+
if role == "assistant":
|
|
79
|
+
# When showing the model its own previous messages, just show the content
|
|
80
|
+
messages.append({"role": role, "content": msg.content})
|
|
81
|
+
else:
|
|
82
|
+
# When showing opponent messages, use a simple format
|
|
83
|
+
messages.append(
|
|
84
|
+
{
|
|
85
|
+
"role": role,
|
|
86
|
+
"content": f"Opponent ({msg.position.value}): {msg.content}",
|
|
87
|
+
}
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
# Add current turn prompt with role focus
|
|
91
|
+
turn_prompt = f"Now speak as {role_name}. Stay under {self.config.debate.word_limit} words."
|
|
92
|
+
messages.append({"role": "user", "content": turn_prompt})
|
|
93
|
+
|
|
94
|
+
return messages
|
|
95
|
+
|
|
96
|
+
def build_format_conversation_context(
|
|
97
|
+
self,
|
|
98
|
+
speaker_id: str,
|
|
99
|
+
format_phase: FormatPhase,
|
|
100
|
+
context: DebateContext,
|
|
101
|
+
) -> list[dict[str, str]]:
|
|
102
|
+
"""Build conversation context for the model using format phase.
|
|
103
|
+
|
|
104
|
+
Args:
|
|
105
|
+
speaker_id: ID of the speaking model
|
|
106
|
+
format_phase: The format-specific phase
|
|
107
|
+
context: The debate context
|
|
108
|
+
|
|
109
|
+
Returns:
|
|
110
|
+
List of message dictionaries for the model API
|
|
111
|
+
"""
|
|
112
|
+
messages: list[dict[str, str]] = []
|
|
113
|
+
|
|
114
|
+
# Add system prompt
|
|
115
|
+
if speaker_id in self.prompt_builder.system_prompts:
|
|
116
|
+
messages.append(
|
|
117
|
+
{"role": "system", "content": self.prompt_builder.system_prompts[speaker_id]}
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
# Add role-focused phase instruction instead of procedural description
|
|
121
|
+
model_ids = list(context.participants.keys())
|
|
122
|
+
side_labels = self.format.get_side_labels(model_ids)
|
|
123
|
+
role_name = side_labels.get(speaker_id, "Speaker")
|
|
124
|
+
|
|
125
|
+
# Simplify the instruction to focus on role, not procedure
|
|
126
|
+
simplified_instruction = (
|
|
127
|
+
format_phase.instruction.replace("As the Proposition,", "")
|
|
128
|
+
.replace("As the Opposition,", "")
|
|
129
|
+
.strip()
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
messages.append(
|
|
133
|
+
{
|
|
134
|
+
"role": "system",
|
|
135
|
+
"content": f"You are now speaking as {role_name}. {simplified_instruction}",
|
|
136
|
+
}
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
# Add relevant debate history
|
|
140
|
+
for msg in context.messages[-6:]: # Last 6 messages for context
|
|
141
|
+
role = "assistant" if msg.speaker_id == speaker_id else "user"
|
|
142
|
+
|
|
143
|
+
# Use a cleaner format that's less likely to be repeated by small models
|
|
144
|
+
if role == "assistant":
|
|
145
|
+
# When showing the model its own previous messages, just show the content
|
|
146
|
+
messages.append({"role": role, "content": msg.content})
|
|
147
|
+
else:
|
|
148
|
+
# When showing opponent messages, use a simple format
|
|
149
|
+
messages.append(
|
|
150
|
+
{
|
|
151
|
+
"role": role,
|
|
152
|
+
"content": f"Opponent ({msg.position.value}): {msg.content}",
|
|
153
|
+
}
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
# Add current turn prompt with role focus
|
|
157
|
+
word_limit = int(self.config.debate.word_limit * format_phase.time_multiplier)
|
|
158
|
+
turn_prompt = f"Now speak as {role_name}. Stay under {word_limit} words."
|
|
159
|
+
messages.append({"role": "user", "content": turn_prompt})
|
|
160
|
+
|
|
161
|
+
return messages
|