-
Notifications
You must be signed in to change notification settings - Fork 4
Add new clients and update README with usage instructions #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
"""Naive DeepSeek-R1 client (with shell access) for AIOpsLab. | ||
|
||
"DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learning" arXiv preprint arXiv:2501.12948 (2025). | ||
|
||
Paper: https://arxiv.org/abs/2501.12948 | ||
""" | ||
|
||
|
||
import os | ||
import asyncio | ||
|
||
import wandb | ||
from aiopslab.orchestrator import Orchestrator | ||
from clients.utils.llm import DeepSeekClient | ||
from clients.utils.templates import DOCS_SHELL_ONLY | ||
from dotenv import load_dotenv | ||
|
||
load_dotenv() | ||
|
||
class Agent: | ||
def __init__(self): | ||
self.history = [] | ||
self.llm = DeepSeekClient() | ||
|
||
def init_context(self, problem_desc: str, instructions: str, apis: str): | ||
"""Initialize the context for the agent.""" | ||
|
||
self.shell_api = self._filter_dict( | ||
apis, lambda k, _: "exec_shell" in k) | ||
self.submit_api = self._filter_dict(apis, lambda k, _: "submit" in k) | ||
|
||
def stringify_apis(apis): return "\n\n".join( | ||
[f"{k}\n{v}" for k, v in apis.items()] | ||
) | ||
|
||
self.system_message = DOCS_SHELL_ONLY.format( | ||
prob_desc=problem_desc, | ||
shell_api=stringify_apis(self.shell_api), | ||
submit_api=stringify_apis(self.submit_api), | ||
) | ||
|
||
self.task_message = instructions | ||
|
||
self.history.append({"role": "system", "content": self.system_message}) | ||
self.history.append({"role": "user", "content": self.task_message}) | ||
self.history.append({"role": "assistant", "content": ""}) # Interleave the user/assistant messages in the message sequence. | ||
|
||
async def get_action(self, input) -> str: | ||
"""Wrapper to interface the agent with OpsBench. | ||
|
||
Args: | ||
input (str): The input from the orchestrator/environment. | ||
|
||
Returns: | ||
str: The response from the agent. | ||
""" | ||
self.history.append({"role": "user", "content": input}) | ||
response = self.llm.run(self.history) | ||
self.history.append({"role": "assistant", "content": response[0]}) | ||
return response[0] | ||
|
||
def _filter_dict(self, dictionary, filter_func): | ||
return {k: v for k, v in dictionary.items() if filter_func(k, v)} | ||
|
||
|
||
if __name__ == "__main__": | ||
# Load use_wandb from environment variable with a default of False | ||
use_wandb = os.getenv("USE_WANDB", "false").lower() == "true" | ||
|
||
if use_wandb: | ||
# Initialize wandb running | ||
wandb.init(project="AIOpsLab", entity="AIOpsLab") | ||
|
||
agent = Agent() | ||
|
||
orchestrator = Orchestrator() | ||
orchestrator.register_agent(agent, name="deepseek-r1") | ||
|
||
pid = "misconfig_app_hotel_res-mitigation-1" | ||
problem_desc, instructs, apis = orchestrator.init_problem(pid) | ||
agent.init_context(problem_desc, instructs, apis) | ||
asyncio.run(orchestrator.start_problem(max_steps=10)) | ||
|
||
if use_wandb: | ||
# Finish the wandb run | ||
wandb.finish() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
"""Naive GPT4 client (with shell access) for AIOpsLab. Uses Azure Managed Identity for authentication. | ||
"""Naive GPT client (with shell access) for AIOpsLab. Uses Azure Managed Identity for authentication. | ||
|
||
Achiam, Josh, Steven Adler, Sandhini Agarwal, Lama Ahmad, Ilge Akkaya, Florencia Leoni Aleman, Diogo Almeida et al. | ||
"Gpt-4 technical report." arXiv preprint arXiv:2303.08774 (2023). | ||
|
@@ -11,14 +11,14 @@ | |
import asyncio | ||
|
||
from aiopslab.orchestrator import Orchestrator | ||
from clients.utils.llm import GPT4Turbo | ||
from clients.utils.llm import GPTClient | ||
from clients.utils.templates import DOCS_SHELL_ONLY | ||
|
||
|
||
class Agent: | ||
def __init__(self, azure_config_file: str): | ||
self.history = [] | ||
self.llm = GPT4Turbo(auth_type="managed", azure_config_file=azure_config_file) | ||
self.llm = GPTClient(auth_type="managed", azure_config_file=azure_config_file) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new GPTClient implementation in clients/utils/llm.py does not appear to support the additional parameters (auth_type and azure_config_file). Consider updating the GPTClient constructor to handle these parameters or refactoring its usage in this file. Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
|
||
def init_context(self, problem_desc: str, instructions: str, apis: str): | ||
"""Initialize the context for the agent.""" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/bash | ||
# This script launches vLLM in the background, redirecting output to a log file. | ||
|
||
# Set the model directory/path and desired port | ||
MODEL="Qwen/Qwen2.5-3B-Instruct" | ||
|
||
# Create a safe filename by replacing slashes with underscores | ||
SAFE_MODEL_NAME=$(echo $MODEL | tr '/' '_') | ||
|
||
# Launch vLLM in background using nohup and redirect both stdout and stderr to a log file. | ||
# nohup poetry run vllm serve $MODEL --tensor-parallel-size 4 > vllm_$SAFE_MODEL_NAME.log 2>&1 & | ||
nohup poetry run vllm serve $MODEL > vllm_$SAFE_MODEL_NAME.log 2>&1 & | ||
|
||
# Print a message indicating that vLLM is running. | ||
echo "vLLM has been launched in the background with the $MODEL model. Check vllm_$SAFE_MODEL_NAME.log for output." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
"""Naive Qwen client (with shell access) for AIOpsLab. | ||
""" | ||
|
||
import os | ||
import asyncio | ||
|
||
import wandb | ||
from aiopslab.orchestrator import Orchestrator | ||
from clients.utils.llm import QwenClient | ||
from clients.utils.templates import DOCS_SHELL_ONLY | ||
|
||
|
||
class Agent: | ||
def __init__(self): | ||
self.history = [] | ||
self.llm = QwenClient() | ||
|
||
def init_context(self, problem_desc: str, instructions: str, apis: str): | ||
"""Initialize the context for the agent.""" | ||
|
||
self.shell_api = self._filter_dict( | ||
apis, lambda k, _: "exec_shell" in k) | ||
self.submit_api = self._filter_dict(apis, lambda k, _: "submit" in k) | ||
|
||
def stringify_apis(apis): return "\n\n".join( | ||
[f"{k}\n{v}" for k, v in apis.items()] | ||
) | ||
|
||
self.system_message = DOCS_SHELL_ONLY.format( | ||
prob_desc=problem_desc, | ||
shell_api=stringify_apis(self.shell_api), | ||
submit_api=stringify_apis(self.submit_api), | ||
) | ||
|
||
self.task_message = instructions | ||
|
||
self.history.append({"role": "system", "content": self.system_message}) | ||
self.history.append({"role": "user", "content": self.task_message}) | ||
|
||
async def get_action(self, input) -> str: | ||
"""Wrapper to interface the agent with OpsBench. | ||
|
||
Args: | ||
input (str): The input from the orchestrator/environment. | ||
|
||
Returns: | ||
str: The response from the agent. | ||
""" | ||
self.history.append({"role": "user", "content": input}) | ||
response = self.llm.run(self.history) | ||
self.history.append({"role": "assistant", "content": response[0]}) | ||
return response[0] | ||
|
||
def _filter_dict(self, dictionary, filter_func): | ||
return {k: v for k, v in dictionary.items() if filter_func(k, v)} | ||
|
||
|
||
if __name__ == "__main__": | ||
# Load use_wandb from environment variable with a default of False | ||
use_wandb = os.getenv("USE_WANDB", "false").lower() == "true" | ||
|
||
if use_wandb: | ||
# Initialize wandb running | ||
wandb.init(project="AIOpsLab", entity="AIOpsLab") | ||
|
||
agent = Agent() | ||
|
||
orchestrator = Orchestrator() | ||
orchestrator.register_agent(agent, name="qwq-32b") | ||
|
||
pid = "misconfig_app_hotel_res-mitigation-1" | ||
problem_desc, instructs, apis = orchestrator.init_problem(pid) | ||
agent.init_context(problem_desc, instructs, apis) | ||
asyncio.run(orchestrator.start_problem(max_steps=10)) | ||
|
||
if use_wandb: | ||
# Finish the wandb run | ||
wandb.finish() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious why this change was made. I don't think there's anything wrong with this, I'm just curious what the difference between
GPT4Turbo
andGPTClient
is.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OpenAI said they will stop GPT-4 service in their APP after April 30, although developers still could access GPT-4 API in a period of time (I'm not sure when it will be desperate, but in the future we may use stronger model released by OpenAI instead). So the 'GPT4Turbo' isn't appropriate I think.
I think for us, it's a good implementation to name this class in a more compatible way, since OpenAI releases many model recently, and in our class, we could easily change the model.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha! I remember getting some emails about that. I'll try out this update later today and try and get it merged.