Skip to content

Commit

Permalink
feat: Add model selection support for Anthropic handler #124 (#125)
Browse files Browse the repository at this point in the history
* feat: Add model selection support for Anthropic handler

The Anthropic handler currently uses a hardcoded model (claude-3-opus-20240229).
This change allows model selection through configuration, matching the behavior
of the OpenAI handler.

Changes:
- Remove hardcoded model string
- Use config loader to get model name from configuration
- Update model settings initialization

* Fix anthropic tests
  • Loading branch information
diekotto authored Dec 29, 2024
1 parent bc31a9b commit 0ae4a8f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion readmeai/models/anthropic.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def __init__(
) -> None:
super().__init__(config_loader, context)
self.client: Optional[Any] = None
self.model: str = "claude-3-opus-20240229"
if ANTHROPIC_AVAILABLE:
self._model_settings()
else:
Expand All @@ -63,6 +62,7 @@ def _model_settings(self):
return

self.client = anthropic.AsyncAnthropic(api_key=api_key)
self.model = self.config.llm.model

async def _build_payload(self, prompt: str, tokens: int) -> dict[str, Any]:
"""Build payload for POST request to the Anthropic API."""
Expand Down
2 changes: 2 additions & 0 deletions tests/models/test_anthropic.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from unittest.mock import AsyncMock, MagicMock, patch

import anthropic
Expand All @@ -22,6 +23,7 @@ def anthropic_handler(repository_context_fixture: RepositoryContext):
pytest.skip("Anthropic library is not available")
config_loader = ConfigLoader()
context = repository_context_fixture
os.environ["ANTHROPIC_API_KEY"] = "test"
return AnthropicHandler(config_loader, context)


Expand Down

0 comments on commit 0ae4a8f

Please sign in to comment.