SWE-agent takes a GitHub issue and tries to automatically fix it, using your LM of choice. It can also be employed for offensive cybersecurity or competitive coding challenges. [NeurIPS 2024]
Groq Models Integration (#721)
Mohammed Nagdyec41209bb1ef
diff --git a/.devcontainer/sample_keys.cfg b/.devcontainer/sample_keys.cfgindex 7c51a6df..5b26d288 100644--- a/.devcontainer/sample_keys.cfg+++ b/.devcontainer/sample_keys.cfg@@ -8,3 +8,4 @@# AZURE_OPENAI_DEPLOYMENT: 'Azure OpenAI Deployment Here if using Azure OpenAI Model'# AZURE_OPENAI_API_VERSION: 'Azure OpenAI API Version Here if using Azure OpenAI Model'# OPENAI_API_BASE_URL: 'LM base URL here if using Local or alternative api Endpoint'+# GROQ_API_KEY: 'Groq Models API Key'\ No newline at end of filediff --git a/requirements.txt b/requirements.txtindex 93e97280..3860feed 100644--- a/requirements.txt+++ b/requirements.txt@@ -19,3 +19,4 @@ rich-argparseflaskflask-corsflask-socketio+groqdiff --git a/sweagent/agent/models.py b/sweagent/agent/models.pyindex 64d15eef..aadb09e6 100644--- a/sweagent/agent/models.py+++ b/sweagent/agent/models.py@@ -9,6 +9,7 @@ from pathlib import Pathimport togetherfrom anthropic import AI_PROMPT, HUMAN_PROMPT, Anthropic, AnthropicBedrock+from groq import Groqfrom openai import AzureOpenAI, BadRequestError, OpenAIfrom simple_parsing.helpers.serialization.serializable import FrozenSerializable, Serializablefrom tenacity import (@@ -114,6 +115,9 @@ class BaseModel:elif args.model_name.startswith("bedrock:"):self.api_model = args.model_name.split("bedrock:", 1)[1]self.model_metadata = MODELS[self.api_model]+ elif args.model_name.startswith("groq:"):+ self.api_model = args.model_name.split("groq:", 1)[1]+ self.model_metadata = MODELS[self.api_model]else:msg = f"Unregistered model ({args.model_name}). Add model name to MODELS metadata to {self.__class__}"raise ValueError(msg)@@ -327,6 +331,67 @@ class DeepSeekModel(OpenAIModel):self.client = OpenAI(api_key=keys_config["DEEPSEEK_API_KEY"], base_url=api_base_url)+class GroqModel(OpenAIModel):+ MODELS = {+ "llama3-8b-8192": {+ "max_context": 8192,+ "cost_per_input_token": 5e-08,+ "cost_per_output_token": 8e-08,+ },+ "llama3-70b-8192": {+ "max_context": 8192,+ "cost_per_input_token": 5.9e-07,+ "cost_per_output_token": 7.9e-07,+ },+ "llama-guard-3-8b": {+ "max_context": 8192,+ "cost_per_input_token": 0,+ "cost_per_output_token": 0,+ },+ "llama-3.1-8b-instant": {+ "max_context": 131_072,+ "cost_per_input_token": 0,+ "cost_per_output_token": 0,+ },+ "llama-3.1-70b-versatile": {+ "max_context": 131_072,+ "cost_per_input_token": 0,+ "cost_per_output_token": 0,+ },+ "gemma2-9b-it": {+ "max_context": 8192,+ "cost_per_input_token": 2e-07,+ "cost_per_output_token": 2e-07,+ },+ "gemma-7b-it": {+ "max_context": 8192,+ "cost_per_input_token": 5e-08,+ "cost_per_output_token": 5e-08,+ },+ "mixtral-8x7b-32768": {+ "max_context": 32_768,+ "cost_per_input_token": 2.4e-07,+ "cost_per_output_token": 2.8e-07,+ },+ }++ SHORTCUTS = {+ "groq/llama8": "llama3-8b-8192",+ "groq/llama70": "llama3-70b-8192",+ "groq/llamaguard8": "llama-guard-3-8b",+ "groq/llamainstant8": "llama-3.1-8b-instant",+ "groq/llamaversatile70": "llama-3.1-70b-versatile",+ "groq/gemma9it": "gemma2-9b-it",+ "groq/gemma7it": "gemma-7b-it",+ "groq/mixtral8x7": "mixtral-8x7b-32768",+ }++ def _setup_client(self) -> None:+ self.client = Groq(+ api_key=keys_config["GROQ_API_KEY"],+ )++class AnthropicModel(BaseModel):MODELS = {"claude-instant": {@@ -927,6 +992,8 @@ def get_model(args: ModelArguments, commands: list[Command] | None = None):return DeepSeekModel(args, commands)elif args.model_name in TogetherModel.SHORTCUTS:return TogetherModel(args, commands)+ elif args.model_name in GroqModel.SHORTCUTS:+ return GroqModel(args, commands)elif args.model_name == "instant_empty_submit":return InstantEmptySubmitTestModel(args, commands)else:diff --git a/tests/test_models.py b/tests/test_models.pyindex 9a7f83f0..4ad20986 100644--- a/tests/test_models.py+++ b/tests/test_models.py@@ -4,7 +4,7 @@ from unittest.mock import MagicMock, Mock, patchimport pytest-from sweagent.agent.models import ModelArguments, OpenAIModel, TogetherModel+from sweagent.agent.models import GroqModel, ModelArguments, OpenAIModel, TogetherModel@pytest.fixture()@@ -41,6 +41,16 @@ def test_openai_model(openai_mock_client):model.query(TEST_HISTORY)+# Test groq models+def test_groq_model(openai_mock_client):+ for model_name in list(GroqModel.MODELS) + list(GroqModel.SHORTCUTS):+ TEST_MODEL_ARGUMENTS = ModelArguments(model_name)+ with patch("sweagent.agent.models.keys_config"), patch("sweagent.agent.models.Groq"):+ model = GroqModel(TEST_MODEL_ARGUMENTS, [])+ model.client = openai_mock_client+ model.query(TEST_HISTORY)++@pytest.mark.parametrize("model_name", list(TogetherModel.MODELS) + list(TogetherModel.SHORTCUTS))def test_together_model(mock_together_response, model_name):with patch("sweagent.agent.models.keys_config"), patch("sweagent.agent.models.together") as mock_together: