Skip to content
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

Ollama support issue. #635

Closed
JayQuimby opened this issue Apr 3, 2024 · 3 comments
Closed

Ollama support issue. #635

JayQuimby opened this issue Apr 3, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@JayQuimby
Copy link
Contributor

JayQuimby commented Apr 3, 2024

Describe the bug

When trying to configure OpenDevin to run with Ollama there are requests that are being sent to the ollama server like this:

image

The post request should look like this:
"POST /chat/completions HTTP/1.1"

Setup and configuration

Current version:

commit 5c640c99cafb3c718dad60f377f3a725a8bab1de (HEAD -> local-llm-flag, origin/main, origin/HEAD, main)

My config.toml and environment vars (be sure to redact API keys):

WORKSPACE_DIR="./workspace"
LLM_BASE_URL="http://localhost:8000"
LLM_MODEL="ollama/starcoder2:15b"
LLM_EMBEDDING_MODEL="ollama/starcoder2:15b"

My model and agent (you can see these settings in the UI):

  • Model: ollama/starcoder2
  • Agent: MonologueAgent

Commands I ran to install and run OpenDevin:

git clone ...
make build
make start-backend
make start-frontend

Steps to Reproduce:

  1. In opendevin/llm/llm.py in __init__ replace self.model = model if model else DEFAULT_MODEL_NAME with self.model_name = DEFAULT_MODEL_NAME
  2. Run your local model on litellm litellm --model ollama/starcoder2:15b --port 8000
  3. Run make build then make start-backend and make start-frontend
  4. Ask devin to do anything ex 'make a hello world script in python'
  5. Observe 404 errors spammed in litellm server log

Logs, error messages, and screenshots:
This is a log from the backend server running from make start-backend steps 0-99 all look the same.

==============
STEP 99

PLAN:
please make a simple flask app that says hello world.
Traceback (most recent call last):
  File "/home/quimbo/.local/share/virtualenvs/OpenDevin-thTG-Evv/lib/python3.11/site-packages/litellm/router.py", line 1436, in function_with_retries
    response = original_function(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/quimbo/.local/share/virtualenvs/OpenDevin-thTG-Evv/lib/python3.11/site-packages/litellm/router.py", line 386, in _completion
    raise e
  File "/home/quimbo/.local/share/virtualenvs/OpenDevin-thTG-Evv/lib/python3.11/site-packages/litellm/router.py", line 334, in _completion
    deployment = self.get_available_deployment(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/quimbo/.local/share/virtualenvs/OpenDevin-thTG-Evv/lib/python3.11/site-packages/litellm/router.py", line 2313, in get_available_deployment
    raise ValueError(f"No healthy deployment available, passed model={model}")
ValueError: No healthy deployment available, passed model=ollama/starcoder2:15b

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/quimbo/OpenDevin/agenthub/monologue_agent/utils/monologue.py", line 31, in condense
    resp = llm.completion(messages=messages)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/quimbo/.local/share/virtualenvs/OpenDevin-thTG-Evv/lib/python3.11/site-packages/litellm/router.py", line 328, in completion
    raise e
  File "/home/quimbo/.local/share/virtualenvs/OpenDevin-thTG-Evv/lib/python3.11/site-packages/litellm/router.py", line 325, in completion
    response = self.function_with_fallbacks(**kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/quimbo/.local/share/virtualenvs/OpenDevin-thTG-Evv/lib/python3.11/site-packages/litellm/router.py", line 1419, in function_with_fallbacks
    raise original_exception
  File "/home/quimbo/.local/share/virtualenvs/OpenDevin-thTG-Evv/lib/python3.11/site-packages/litellm/router.py", line 1344, in function_with_fallbacks
    response = self.function_with_retries(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/quimbo/.local/share/virtualenvs/OpenDevin-thTG-Evv/lib/python3.11/site-packages/litellm/router.py", line 1496, in function_with_retries
    raise e
  File "/home/quimbo/.local/share/virtualenvs/OpenDevin-thTG-Evv/lib/python3.11/site-packages/litellm/router.py", line 1462, in function_with_retries
    response = original_function(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/quimbo/.local/share/virtualenvs/OpenDevin-thTG-Evv/lib/python3.11/site-packages/litellm/router.py", line 386, in _completion
    raise e
  File "/home/quimbo/.local/share/virtualenvs/OpenDevin-thTG-Evv/lib/python3.11/site-packages/litellm/router.py", line 334, in _completion
    deployment = self.get_available_deployment(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/quimbo/.local/share/virtualenvs/OpenDevin-thTG-Evv/lib/python3.11/site-packages/litellm/router.py", line 2313, in get_available_deployment
    raise ValueError(f"No healthy deployment available, passed model={model}")
ValueError: No healthy deployment available, passed model=ollama/starcoder2:15b

ERROR:
Error condensing thoughts: No healthy deployment available, passed model=ollama/starcoder2:15b
Traceback (most recent call last):
  File "/home/quimbo/.local/share/virtualenvs/OpenDevin-thTG-Evv/lib/python3.11/site-packages/litellm/router.py", line 1436, in function_with_retries
    response = original_function(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/quimbo/.local/share/virtualenvs/OpenDevin-thTG-Evv/lib/python3.11/site-packages/litellm/router.py", line 386, in _completion
    raise e
  File "/home/quimbo/.local/share/virtualenvs/OpenDevin-thTG-Evv/lib/python3.11/site-packages/litellm/router.py", line 334, in _completion
    deployment = self.get_available_deployment(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/quimbo/.local/share/virtualenvs/OpenDevin-thTG-Evv/lib/python3.11/site-packages/litellm/router.py", line 2313, in get_available_deployment
    raise ValueError(f"No healthy deployment available, passed model={model}")
ValueError: No healthy deployment available, passed model=ollama/starcoder2:15b

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/quimbo/OpenDevin/agenthub/monologue_agent/utils/monologue.py", line 31, in condense
    resp = llm.completion(messages=messages)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/quimbo/.local/share/virtualenvs/OpenDevin-thTG-Evv/lib/python3.11/site-packages/litellm/router.py", line 328, in completion
    raise e
  File "/home/quimbo/.local/share/virtualenvs/OpenDevin-thTG-Evv/lib/python3.11/site-packages/litellm/router.py", line 325, in completion
    response = self.function_with_fallbacks(**kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/quimbo/.local/share/virtualenvs/OpenDevin-thTG-Evv/lib/python3.11/site-packages/litellm/router.py", line 1419, in function_with_fallbacks
    raise original_exception
  File "/home/quimbo/.local/share/virtualenvs/OpenDevin-thTG-Evv/lib/python3.11/site-packages/litellm/router.py", line 1344, in function_with_fallbacks
    response = self.function_with_retries(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/quimbo/.local/share/virtualenvs/OpenDevin-thTG-Evv/lib/python3.11/site-packages/litellm/router.py", line 1496, in function_with_retries
    raise e
  File "/home/quimbo/.local/share/virtualenvs/OpenDevin-thTG-Evv/lib/python3.11/site-packages/litellm/router.py", line 1462, in function_with_retries
    response = original_function(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/quimbo/.local/share/virtualenvs/OpenDevin-thTG-Evv/lib/python3.11/site-packages/litellm/router.py", line 386, in _completion
    raise e
  File "/home/quimbo/.local/share/virtualenvs/OpenDevin-thTG-Evv/lib/python3.11/site-packages/litellm/router.py", line 334, in _completion
    deployment = self.get_available_deployment(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/quimbo/.local/share/virtualenvs/OpenDevin-thTG-Evv/lib/python3.11/site-packages/litellm/router.py", line 2313, in get_available_deployment
    raise ValueError(f"No healthy deployment available, passed model={model}")
ValueError: No healthy deployment available, passed model=ollama/starcoder2:15b

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/quimbo/OpenDevin/opendevin/controller/agent_controller.py", line 112, in step
    action = self.agent.step(self.state)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/quimbo/OpenDevin/agenthub/monologue_agent/agent.py", line 153, in step
    self._add_event(prev_action.to_dict())
  File "/home/quimbo/OpenDevin/agenthub/monologue_agent/agent.py", line 96, in _add_event
    self.monologue.condense(self.llm)
  File "/home/quimbo/OpenDevin/agenthub/monologue_agent/utils/monologue.py", line 36, in condense
    raise RuntimeError(f"Error condensing thoughts: {e}")
RuntimeError: Error condensing thoughts: No healthy deployment available, passed model=ollama/starcoder2:15b

OBSERVATION:
Error condensing thoughts: No healthy deployment available, passed model=ollama/starcoder2:15b
Exited before finishing

Additional Context

Litellm for local models is expecting api calls in the following format:

image

From: http://localhost:8000/#/

I know that the problem is whatever is managing the api calls is set to call /api/generate/ because this is the convention, but for local server that is not supported. I do not know where to look to fix this, any ideas?

The server responds when I test it like this:

def query_local_llm(prompt, limit=TOKEN_LIMIT):
    # Replace with your actual server address and port
    url = "http://0.0.0.0:8000/chat/completions"
    payload = {
        "model": "ollama/mistral",
        "messages" : [{"content": prompt, "role": "user"}],
        "max_tokens": limit
    }
    response = requests.post(url, json=payload)

image

@JayQuimby JayQuimby added the bug Something isn't working label Apr 3, 2024
@stratte89
Copy link

stratte89 commented Apr 3, 2024

EDIT: a guide for ollama was added
08a2dfb


this config was working for me, before the devin update today, its not right now with the latest update, idk if its about the config tho

LLM_API_KEY="ollama"
LLM_BASE_URL="http://0.0.0.0:11434"
LLM_MODEL="ollama/mistral"
LLM_EMBEDDING_MODEL="local"
WORKSPACE_DIR="./workspace"

Also make sure to start the ollama serve after loading the mode and that you are using the correct ollama server port. If the server is already running load the model and kill the server process. I am using sudo fuser -k -n tcp 11434 to kill it but im on ubuntu. Btw I tried it on windows using wsl and i wasn't able to get it to work, since wsl is using a virtual network. There is a workaround by creating a wsl config file to mirror you host network, it didn't work for me tho for someone else it did so you have you try it yourself.

"Open wsl config file C:\Users%username%.wslconfig (create one if it doesnt exist), and add this:

[wsl2]
networkingMode=mirrored"

if your ollama server is listening on 0.0.0.0:port then change the Makefile adding --host 0.0.0.0 and --host

Start backend

start-backend:
@echo "Starting backend..."
@python -m pipenv run uvicorn opendevin.server.listen:app --port $(BACKEND_PORT) --host 0.0.0.0

Start frontend

start-frontend:
@echo "Starting frontend..."
@cd frontend && npm run start -- --port $(FRONTEND_PORT) --host

Also what i just mentioned is, that you're using the cmd, you should use a wsl terminal like anaconda command prompt in windows

JayQuimby referenced this issue Apr 3, 2024
* doc: Guide for using local LLM with Ollama
@imtpalmer
Copy link

I tested this yesterday and again this morning using Ollama local with OpenDevin patch-11 and it works. However, it fails when I switch to patch-12 and the main branch.

@JayQuimby
Copy link
Contributor Author

@imtpalmer An updated guide got merged this morning here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants