kikocis/auto-code-rover public
Changesets · Branches · Tags · Compare
| Changeset | b0e6ebbd983f4da2c33fc14c4f56ba310a73eb0219b503ac92c35a76f51dd818 |
|---|---|
| Author | Zhang Yuntong <ang.unong@gmail.com> · 2024-05-07 13:50 +08:00 |
| Committer | Zhang Yuntong <ang.unong@gmail.com> · 2024-05-07 13:54 +08:00 |
| Parents | 0f4e2e4e2ecb |
2 files changed
modified README.md +10 −3
| @@ -134,8 +134,8 @@ | ||
| 134 | 134 | |
| 135 | 135 | If patch generation is successful, the path to the generated patch will be printed in the end. |
| 136 | 136 | |
| 137 | -Web UI is also provided for visualization of the issue fixing process. | |
| 138 | -In the docker shell, run the following command: | |
| 137 | +Web UI is also provided for visualization of the issue fixing process. | |
| 138 | +In the docker shell, run the following command: | |
| 139 | 139 | |
| 140 | 140 | ```bash |
| 141 | 141 | cd /opt/auto-code-rover/demo_vis/ |
| @@ -259,7 +259,14 @@ | ||
| 259 | 259 | | Meta | Llama 3 70B | --model llama3:70b | |
| 260 | 260 | | | Llama 3 8B | --model llama3 | |
| 261 | 261 | |
| 262 | -Before using the llama models, please [install ollama](https://ollama.com/download/linux) and download the corresponding models with ollama (e.g. `ollama pull llama3`). | |
| 262 | +> [!NOTE] | |
| 263 | +> Some notes on running ACR with local models such as llama3: | |
| 264 | +> 1. Before using the llama3 models, please [install ollama](https://ollama.com/download/linux) and download the corresponding models with ollama (e.g. `ollama pull llama3`). | |
| 265 | +> 2. You can run ollama server on the host machine, and ACR in its container. ACR will attempt to communicate to the ollama server on host. | |
| 266 | +> 3. If your setup is ollama in host + ACR in its container, we recommend installing [Docker Desktop](https://docs.docker.com/desktop/) on the host, in addition to the [Docker Engine](https://docs.docker.com/engine/). | |
| 267 | +> - Docker Desktop contains Docker Engine, and also has a virtual machine which makes it easier to access the host ports from within a container. With Docker Desktop, this setup will work without additional effort. | |
| 268 | +> - When the docker installation is only Docker Engine, you may need to add either `--net=host` or `--add-host host.docker.internal=host-gateway` to the `docker run` command when starting the ACR container, so that ACR can communicate with the ollama server on the host machine. | |
| 269 | + | |
| 263 | 270 | |
| 264 | 271 | ## Experiment Replication |
| 265 | 272 |
modified app/model/ollama.py +30 −3
| @@ -8,6 +8,7 @@ | ||
| 8 | 8 | from copy import deepcopy |
| 9 | 9 | from typing import Literal, cast |
| 10 | 10 | |
| 11 | +import httpx | |
| 11 | 12 | import ollama |
| 12 | 13 | import timeout_decorator |
| 13 | 14 | from ollama._types import Message, Options |
| @@ -35,6 +36,7 @@ | ||
| 35 | 36 | return |
| 36 | 37 | # local models are free |
| 37 | 38 | super().__init__(name, 0.0, 0.0) |
| 39 | + self.client: ollama.Client | None = None | |
| 38 | 40 | self._initialized = True |
| 39 | 41 | |
| 40 | 42 | def setup(self) -> None: |
| @@ -51,6 +53,9 @@ | ||
| 51 | 53 | e, |
| 52 | 54 | ) |
| 53 | 55 | sys.exit(1) |
| 56 | + except Exception as e: | |
| 57 | + print("Could not communicate with ollama server due to exception.", e) | |
| 58 | + sys.exit(1) | |
| 54 | 59 | |
| 55 | 60 | @timeout_decorator.timeout(120) # 2 min |
| 56 | 61 | def send_empty_request(self): |
| @@ -60,7 +65,27 @@ | ||
| 60 | 65 | (2) preload the model for faster response time (models will be kept in memory for 5 mins after loaded) |
| 61 | 66 | (see https://github.com/ollama/ollama/blob/main/docs/faq.md#how-can-i-pre-load-a-model-to-get-faster-response-times) |
| 62 | 67 | """ |
| 63 | - ollama.chat(model=self.name, messages=[]) | |
| 68 | + # localhost is used when (1) running both ACR and ollama on host machine; and | |
| 69 | + # (2) running ollama in host, and ACR in container with --net=host | |
| 70 | + local_client = ollama.Client(host="http://localhost:11434") | |
| 71 | + # docker_host_client is used when running ollama in host and ACR in container, and | |
| 72 | + # Docker Desktop is installed | |
| 73 | + docker_host_client = ollama.Client(host="http://host.docker.internal:11434") | |
| 74 | + try: | |
| 75 | + local_client.chat(model=self.name, messages=[]) | |
| 76 | + self.client = local_client | |
| 77 | + return | |
| 78 | + except httpx.ConnectError: | |
| 79 | + # failed to connect to client at localhost | |
| 80 | + pass | |
| 81 | + | |
| 82 | + try: | |
| 83 | + docker_host_client.chat(model=self.name, messages=[]) | |
| 84 | + self.client = docker_host_client | |
| 85 | + except httpx.ConnectError: | |
| 86 | + # also failed to connect via host.docker.internal | |
| 87 | + print("Could not connect to ollama server.") | |
| 88 | + sys.exit(1) | |
| 64 | 89 | |
| 65 | 90 | def check_api_key(self) -> str: |
| 66 | 91 | return "No key required for local models." |
| @@ -90,6 +115,8 @@ | ||
| 90 | 115 | json_stop_words.append("```") |
| 91 | 116 | json_stop_words.append(" " * 10) |
| 92 | 117 | # FIXME: ignore tools field since we don't use tools now |
| 118 | + | |
| 119 | + assert self.client is not None | |
| 93 | 120 | try: |
| 94 | 121 | # build up options for ollama |
| 95 | 122 | options = { |
| @@ -105,7 +132,7 @@ | ||
| 105 | 132 | messages.append(json_instruction) |
| 106 | 133 | # give more stop words and lower max_token for json mode |
| 107 | 134 | options.update({"stop": json_stop_words, "num_predict": 128}) |
| 108 | - response = ollama.chat( | |
| 135 | + response = self.client.chat( | |
| 109 | 136 | model=self.name, |
| 110 | 137 | messages=cast(list[Message], messages), |
| 111 | 138 | format="json", |
| @@ -114,7 +141,7 @@ | ||
| 114 | 141 | ) |
| 115 | 142 | else: |
| 116 | 143 | options.update({"stop": stop_words, "num_predict": 1024}) |
| 117 | - response = ollama.chat( | |
| 144 | + response = self.client.chat( | |
| 118 | 145 | model=self.name, |
| 119 | 146 | messages=cast(list[Message], messages), |
| 120 | 147 | options=cast(Options, options), |