Skip to main content

Intelligent Simulation Orchestration for Large Language Models

Project description

ISOPro: Pro Tools for Intelligent Simulation Orchestration for Large Language Models

ISOPRO is a powerful and flexible Python package designed for creating, managing, and analyzing simulations involving Large Language Models (LLMs). It provides a comprehensive suite of tools for reinforcement learning, conversation simulations, adversarial testing, custom environment creation, and advanced orchestration of multi-agent systems.

Features

  • Custom Environment Creation: Easily create and manage custom simulation environments for LLMs. COMING SOON
  • Conversation Simulation: Simulate and analyze conversations with AI agents using various user personas. COMING SOON
  • Adversarial Testing: Conduct adversarial simulations to test the robustness of LLM-based systems. COMING SOON
  • Reinforcement Learning: Implement and experiment with RL algorithms in LLM contexts. COMING SOON
  • Utility Functions: Analyze simulation results, calculate LLM metrics, and more.
  • Flexible Integration: Works with popular LLM platforms like OpenAI's GPT models, Claude (Anthropic), and Hugging Face models.
  • Orchestration Simulation: Manage and execute complex multi-agent simulations with different execution modes. NOW AVAILABLE

isopro

isopro is a Python package for running various types of AI simulations and experiments. It provides tools for adversarial testing, conversation simulation, reinforcement learning, and AI orchestration.

Installation

You can install isopro using pip:

pip install isopro

Usage

Adversarial Simulation

Test the robustness of AI models against adversarial attacks.

from isopro.adversarial_simulation import AdversarialSimulator, AdversarialEnvironment
from isopro.agents.ai_agent import AI_Agent
import anthropic

class ClaudeAgent(AI_Agent):
    def __init__(self, name):
        super().__init__(name)
        self.client = anthropic.Anthropic(api_key=os.getenv("ANTHROPIC_API_KEY"))

    def run(self, input_data):
        response = self.client.messages.create(
            model="claude-3-opus-20240229",
            max_tokens=100,
            messages=[{"role": "user", "content": input_data['text']}]
        )
        return response.content[0].text

# Create the AdversarialEnvironment
adv_env = AdversarialEnvironment(
    agent_wrapper=ClaudeAgent("Claude Agent"),
    num_adversarial_agents=2,
    attack_types=["textbugger", "deepwordbug"],
    attack_targets=["input", "output"]
)

# Set up the adversarial simulator
simulator = AdversarialSimulator(adv_env)

# Run the simulation
input_data = ["What is the capital of France?", "How does photosynthesis work?"]
simulation_results = simulator.run_simulation(input_data, num_steps=1)

Conversation Simulation

Simulate conversations between an AI assistant and various user personas.

from isopro.conversation_simulation.conversation_simulator import ConversationSimulator

# Initialize the ConversationSimulator
simulator = ConversationSimulator(
    ai_prompt="You are an AI assistant created to be helpful, harmless, and honest. You are a customer service agent for a tech company. Respond politely and professionally."
)

# Run a simulation with a predefined persona
conversation_history = simulator.run_simulation("upset", num_turns=3)

# Run a simulation with a custom persona
custom_persona_name = "Techie Customer"
custom_characteristics = ["tech-savvy", "impatient", "detail-oriented"]
custom_message_templates = [
    "I've tried rebooting my device, but the error persists. Can you help?",
    "What's the latest update on the cloud service outage?",
    "I need specifics on the API rate limits for the enterprise plan."
]

custom_conversation = simulator.run_custom_simulation(
    custom_persona_name,
    custom_characteristics,
    custom_message_templates,
    num_turns=3
)

Reinforcement Learning with LLM

Integrate Large Language Models with reinforcement learning environments.

import gymnasium as gym
from isopro.rl.rl_agent import RLAgent
from isopro.rl.rl_environment import LLMRLEnvironment
from stable_baselines3 import PPO

class LLMCartPoleWrapper(LLMRLEnvironment):
    def __init__(self, agent_prompt):
        super().__init__(agent_prompt, None)
        self.cartpole_env = gym.make('CartPole-v1')
        self.action_space = self.cartpole_env.action_space
        self.observation_space = self.cartpole_env.observation_space

    def step(self, action):
        observation, reward, terminated, truncated, info = self.cartpole_env.step(action)
        self._update_llm(observation, reward, terminated or truncated)
        return observation, reward, terminated, truncated, info

agent_prompt = """You are an AI trained to play the CartPole game. 
Your goal is to balance a pole on a moving cart for as long as possible. 
You will receive observations about the cart's position, velocity, pole angle, and angular velocity. 
Based on these, you should decide whether to move the cart left or right."""

env = LLMCartPoleWrapper(agent_prompt)
model = PPO("MlpPolicy", env, verbose=1)

# Train the model
model.learn(total_timesteps=10000)

# Test the model
obs, _ = env.reset()
for _ in range(1000):
    action, _ = model.predict(obs, deterministic=True)
    obs, reward, done, _, _ = env.step(action)
    if done:
        obs, _ = env.reset()

AI Orchestration

Orchestrate multiple AI agents to work together on complex tasks.

from isopro.orchestration_simulation import OrchestrationEnv
from isopro.orchestration_simulation.components import LLaMAAgent, AnalysisAgent, WritingAgent
from isopro.orchestration_simulation.evaluator import Evaluator

# Create the orchestration environment
env = OrchestrationEnv()

# Add agents to the environment
env.add_component(LLaMAAgent("Research", "conduct thorough research on the impact of artificial intelligence on job markets"))
env.add_component(AnalysisAgent("Analysis"))
env.add_component(WritingAgent("Writing"))

# Define the task
task = "Prepare a comprehensive report on the impact of artificial intelligence on job markets in the next decade."

# Run simulations in different modes
modes = ['parallel', 'sequence', 'node']
results = {}

for mode in modes:
    result = env.run_simulation(mode=mode, input_data={'task': task, 'run_order': 'first'})
    results[mode] = result

# Evaluate the results
evaluator = Evaluator()
best_mode = evaluator.evaluate(results)
print(f"The best execution mode for this task was: {best_mode}")

Documentation

For more detailed information on each module and its usage, please refer to the full documentation.

Examples

The isopro examples repository in the repository contains Jupyter notebooks with more detailed examples:

  • adversarial_example.ipynb: Demonstrates adversarial testing of language models.
  • conversation_simulation_example.ipynb: Shows how to simulate conversations with various user personas.
  • run_cartpole_example.ipynb: Illustrates the integration of LLMs with reinforcement learning.
  • orchestrator_example.ipynb: Provides a tutorial on using the AI orchestration capabilities.

Contributing

We welcome contributions! Please see our Contributing Guide for more details.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

If you encounter any problems or have any questions, please open an issue on our GitHub repository.

Citation

If you use ISOPRO in your research, please cite it as follows:

@software{isopro2024,
  author = {Jazmia Henry},
  title = {ISOPRO: Intelligent Simulation Orchestration for Large Language Models},
  year = {2024},
  publisher = {GitHub},
  journal = {GitHub repository},
  howpublished = {\url{https://github.com/iso-ai/isopro}}
}

Contact

For questions or support, please open an issue on our GitHub issue tracker.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

isopro-0.1.1.tar.gz (44.3 kB view details)

Uploaded Source

Built Distribution

isopro-0.1.1-py3-none-any.whl (60.4 kB view details)

Uploaded Python 3

File details

Details for the file isopro-0.1.1.tar.gz.

File metadata

  • Download URL: isopro-0.1.1.tar.gz
  • Upload date:
  • Size: 44.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.8

File hashes

Hashes for isopro-0.1.1.tar.gz
Algorithm Hash digest
SHA256 9d45ac23b5a652ac0a67d3d70ef937188d0b08e22663d320b7c44e7225c44ed9
MD5 ff8b78867d89fab09fec901a3077d3fc
BLAKE2b-256 23aa8c65f5cc3952b55b9d3cacd5a7fef2355da854209c97b48ab22316c6ecad

See more details on using hashes here.

File details

Details for the file isopro-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: isopro-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 60.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.8

File hashes

Hashes for isopro-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 57b85131357236a2f673b47bfdb4d0b926d84de9fb4c2ac1be77ea23fafc0537
MD5 e7f0a92c657917a392e1f79cf99a30c8
BLAKE2b-256 4bd5125bf387366b1e02afd09b0114ca77d8a7ec16562cda724971e9ed6b8c7f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page