Skip to content

Commit

Permalink
Revert the use of Router, good ole completion works. (All-Hands-AI#910)
Browse files Browse the repository at this point in the history
* Revert the use of Router, good ole completion works.

* Stopgap exception message

* Get the updated dependencies.
  • Loading branch information
enyst authored Apr 9, 2024
1 parent 3c4b3ed commit 8ab9c6f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 41 deletions.
2 changes: 1 addition & 1 deletion opendevin/controller/agent_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ async def step(self, i: int):
print_with_color(observation, 'ERROR')
traceback.print_exc()
# TODO Change to more robust error handling
if 'The api_key client option must be set' in observation.content:
if 'The api_key client option must be set' or 'Incorrect API key provided:' in observation.content:
raise
self.update_state_after_step()

Expand Down
26 changes: 2 additions & 24 deletions opendevin/llm/llm.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from datetime import datetime

from litellm.router import Router
from litellm import completion as litellm_completion
from functools import partial

from opendevin import config
Expand All @@ -24,28 +23,8 @@ def __init__(self,
self.model_name = model if model else DEFAULT_MODEL_NAME
self.api_key = api_key if api_key else DEFAULT_API_KEY
self.base_url = base_url if base_url else DEFAULT_BASE_URL
self.num_retries = num_retries if num_retries else DEFAULT_LLM_NUM_RETRIES
self.cooldown_time = cooldown_time if cooldown_time else DEFAULT_LLM_COOLDOWN_TIME
self._debug_id = datetime.now().strftime('%Y-%m-%d-%H-%M-%S')

# We use litellm's Router in order to support retries (especially rate limit backoff retries).
# Typically you would use a whole model list, but it's unnecessary with our implementation's structure
self._router = Router(
model_list=[{
'model_name': self.model_name,
'litellm_params': {
'model': self.model_name,
'api_key': self.api_key,
'api_base': self.base_url
}
}],
num_retries=self.num_retries,
# We allow all retries to fail, so they can retry instead of going into "cooldown"
allowed_fails=self.num_retries,
cooldown_time=self.cooldown_time
)
self._completion = partial(
self._router.completion, model=self.model_name)
self._completion = partial(litellm_completion, model=self.model_name, api_key=self.api_key, base_url=self.base_url)

completion_unwrapped = self._completion

Expand All @@ -67,4 +46,3 @@ def completion(self):
Decorator for the litellm completion function.
"""
return self._completion

32 changes: 16 additions & 16 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8ab9c6f

Please sign in to comment.