Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion optillm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os

# Version information
__version__ = "0.1.14"
__version__ = "0.1.15"

# Get the path to the root optillm.py
spec = util.spec_from_file_location(
Expand Down
62 changes: 31 additions & 31 deletions optillm/plugins/deepthink_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
for enhanced reasoning in large language models.
"""

import os
import sys
import importlib.util
import logging
from typing import Tuple, Dict, Any
from optillm.plugins.deepthink.self_discover import SelfDiscover
from optillm.plugins.deepthink.uncertainty_cot import UncertaintyRoutedCoT

# Plugin identifier for optillm
SLUG = "deepthink"
Expand Down Expand Up @@ -40,18 +41,38 @@ def run(
"""
logger.info("Starting Deep Think reasoning process")

# Extract configuration parameters
config = _parse_config(request_config or {})
# Get the directory where this plugin is located
plugin_dir = os.path.dirname(os.path.abspath(__file__))
deepthink_dir = os.path.join(plugin_dir, 'deepthink')

# Add the deepthink directory to the Python path temporarily
if deepthink_dir not in sys.path:
sys.path.insert(0, deepthink_dir)

try:
# Load the modules dynamically
self_discover_file = os.path.join(deepthink_dir, 'self_discover.py')
uncertainty_cot_file = os.path.join(deepthink_dir, 'uncertainty_cot.py')

spec1 = importlib.util.spec_from_file_location("self_discover", self_discover_file)
self_discover_module = importlib.util.module_from_spec(spec1)
spec1.loader.exec_module(self_discover_module)

spec2 = importlib.util.spec_from_file_location("uncertainty_cot", uncertainty_cot_file)
uncertainty_cot_module = importlib.util.module_from_spec(spec2)
spec2.loader.exec_module(uncertainty_cot_module)

# Extract configuration parameters
config = _parse_config(request_config or {})

# Initialize components
self_discover = SelfDiscover(
self_discover = self_discover_module.SelfDiscover(
client=client,
model=model,
max_tokens=config["max_tokens"]
)

uncertainty_cot = UncertaintyRoutedCoT(
uncertainty_cot = uncertainty_cot_module.UncertaintyRoutedCoT(
client=client,
model=model,
max_tokens=config["max_tokens"]
Expand Down Expand Up @@ -108,31 +129,10 @@ def run(

return final_response, total_tokens

except Exception as e:
logger.error(f"Error in Deep Think plugin: {str(e)}")
logger.debug(f"Exception traceback:", exc_info=True)

# Fallback to simple generation
try:
logger.info("Attempting fallback to simple generation")
response = client.chat.completions.create(
model=model,
messages=[
{"role": "system", "content": system_prompt},
{"role": "user", "content": initial_query}
],
max_tokens=config["max_tokens"],
temperature=config["temperature"],
top_p=config["top_p"]
)

logger.info("Fallback generation successful")
return response.choices[0].message.content.strip(), response.usage.completion_tokens

except Exception as fallback_error:
logger.error(f"Fallback generation also failed: {str(fallback_error)}")
logger.debug(f"Fallback exception traceback:", exc_info=True)
return f"Error in Deep Think plugin: {str(e)}", 0
finally:
# Remove from path after use
if deepthink_dir in sys.path:
sys.path.remove(deepthink_dir)

def _parse_config(request_config: Dict[str, Any]) -> Dict[str, Any]:
"""Parse and validate configuration parameters."""
Expand Down
26 changes: 23 additions & 3 deletions optillm/plugins/longcepo.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,31 @@
If you have any questions or want to contribute, please reach out to us on [cerebras.ai/discord](https://cerebras.ai/discord).
"""

import os
import sys
import importlib.util
from typing import Tuple
from optillm.plugins.longcepo.main import run_longcepo


SLUG = "longcepo"

def run(system_prompt: str, initial_query: str, client, model: str) -> Tuple[str, int]:
return run_longcepo(system_prompt, initial_query, client, model)
# Get the directory where this plugin is located
plugin_dir = os.path.dirname(os.path.abspath(__file__))
longcepo_dir = os.path.join(plugin_dir, 'longcepo')
main_file = os.path.join(longcepo_dir, 'main.py')

# Load the main module dynamically
spec = importlib.util.spec_from_file_location("longcepo_main", main_file)
longcepo_main = importlib.util.module_from_spec(spec)

# Add the longcepo directory to the Python path temporarily
if longcepo_dir not in sys.path:
sys.path.insert(0, longcepo_dir)

try:
spec.loader.exec_module(longcepo_main)
return longcepo_main.run_longcepo(system_prompt, initial_query, client, model)
finally:
# Remove from path after use
if longcepo_dir in sys.path:
sys.path.remove(longcepo_dir)
2 changes: 1 addition & 1 deletion optillm/plugins/longcepo/chunking.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import re
from typing import List

from optillm.plugins.longcepo.utils import logger
from .utils import logger


def get_prompt_length(prompt: str, tokenizer, no_special_tokens=False, **kwargs) -> int:
Expand Down
5 changes: 3 additions & 2 deletions optillm/plugins/longcepo/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
from typing import Tuple
from functools import partial

from optillm.plugins.longcepo.mapreduce import mapreduce
from optillm.plugins.longcepo.utils import (
# Use relative imports that work within the dynamically loaded module
from .mapreduce import mapreduce
from .utils import (
get_prompt_response,
logger,
longcepo_init,
Expand Down
4 changes: 2 additions & 2 deletions optillm/plugins/longcepo/mapreduce.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from functools import partial
from typing import Tuple, List

from optillm.plugins.longcepo.utils import (
from .utils import (
CBLog,
LongCepoConfig,
get_prompt_response,
concurrent_map,
logger,
loop_until_match,
)
from optillm.plugins.longcepo.chunking import (
from .chunking import (
chunk_context,
get_prompt_length,
)
Expand Down
2 changes: 1 addition & 1 deletion optillm/plugins/longcepo/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from concurrent.futures import ThreadPoolExecutor, as_completed

from transformers import AutoTokenizer, PreTrainedTokenizerBase
from optillm.plugins.longcepo.config import LongCepoConfig
from .config import LongCepoConfig

logger = logging.getLogger(__name__)

Expand Down
25 changes: 23 additions & 2 deletions optillm/plugins/spl.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
LLM incrementally better at solving problems by learning from its experiences.
"""

import os
import sys
import importlib.util
from typing import Tuple
from optillm.plugins.spl.main import run_spl

# Plugin identifier
SLUG = "spl"
Expand All @@ -34,4 +36,23 @@ def run(system_prompt: str, initial_query: str, client, model: str, request_conf
Returns:
Tuple[str, int]: The LLM response and token count
"""
return run_spl(system_prompt, initial_query, client, model, request_config)
# Get the directory where this plugin is located
plugin_dir = os.path.dirname(os.path.abspath(__file__))
spl_dir = os.path.join(plugin_dir, 'spl')
main_file = os.path.join(spl_dir, 'main.py')

# Load the main module dynamically
spec = importlib.util.spec_from_file_location("spl_main", main_file)
spl_main = importlib.util.module_from_spec(spec)

# Add the spl directory to the Python path temporarily
if spl_dir not in sys.path:
sys.path.insert(0, spl_dir)

try:
spec.loader.exec_module(spl_main)
return spl_main.run_spl(system_prompt, initial_query, client, model, request_config)
finally:
# Remove from path after use
if spl_dir in sys.path:
sys.path.remove(spl_dir)
10 changes: 5 additions & 5 deletions optillm/plugins/spl/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@
import logging
from typing import Tuple, Dict, List, Optional, Any

from optillm.plugins.spl.strategy import Strategy, StrategyDatabase
from optillm.plugins.spl.generation import (
from .strategy import Strategy, StrategyDatabase
from .generation import (
classify_problem,
generate_strategy,
should_create_new_strategy
)
from optillm.plugins.spl.evaluation import (
from .evaluation import (
select_relevant_strategies,
evaluate_strategy_effectiveness,
refine_strategy
)
from optillm.plugins.spl.utils import (
from .utils import (
extract_thinking,
augment_system_prompt
)
from optillm.plugins.spl.config import (
from .config import (
DEFAULT_MAX_TOKENS,
MAINTENANCE_INTERVAL,
STRATEGY_MERGING_THRESHOLD,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name="optillm",
version="0.1.14",
version="0.1.15",
packages=find_packages(include=['optillm', 'optillm.*']), # This ensures all subpackages are included
py_modules=['optillm'],
package_data={
Expand Down