Skip to content

Commit

Permalink
Bring back proper handling of env variables OLLAMA_HOST, OLLAMA_URL, …
Browse files Browse the repository at this point in the history
…OTERM_VERIFY_SSL after migrating to the official Ollama client

Closes ggozad#71
  • Loading branch information
ggozad committed Apr 14, 2024
1 parent b4a6b2e commit 60853b2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
=========

0.2.6 -
------------------

- Fix handling of OLLAMA_HOST, OLLAMA_URL, OTERM_VERIFY_SSL env variables.
[ggozad]

0.2.5 - 2024-04-02
------------------

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pip install oterm

## Using

In order to use `oterm` you will need to have the Ollama server running. By default it expects to find the Ollama API running on `http://0.0.0.0:11434/api`. If you are running Ollama inside docker or on a different host/port, use the `OLLAMA_HOST` environment variable to customize the host/port. Alternatively you can use `OLLAMA_URL` to specify the full http(s) url. Setting `OTERM_VERIFY_SSL` to `False` will disable SSL verification.
In order to use `oterm` you will need to have the Ollama server running. By default it expects to find the Ollama API running on `http://0.0.0.0:11434`. If you are running Ollama inside docker or on a different host/port, use the `OLLAMA_HOST` environment variable to customize the host/port. Alternatively you can use `OLLAMA_URL` to specify the full http(s) url. Setting `OTERM_VERIFY_SSL` to `False` will disable SSL verification.

```bash
OLLAMA_URL=http://host:port/api
Expand Down
2 changes: 1 addition & 1 deletion oterm/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __init__(self, env):
)
)
if self.OLLAMA_URL == "":
self.OLLAMA_URL = f"http://{self.OLLAMA_HOST}/api"
self.OLLAMA_URL = f"http://{self.OLLAMA_HOST}"

def __repr__(self):
return str(self.__dict__)
Expand Down
8 changes: 6 additions & 2 deletions oterm/ollama.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ def __init__(
self.format = format

async def completion(self, prompt: str, images: list[str] = []) -> str:
client = AsyncClient(host=envConfig.OLLAMA_HOST)
client = AsyncClient(
host=envConfig.OLLAMA_URL, verify=envConfig.OTERM_VERIFY_SSL
)
response: dict = await client.generate(
model=self.model,
prompt=prompt,
Expand All @@ -34,7 +36,9 @@ async def completion(self, prompt: str, images: list[str] = []) -> str:
async def stream(
self, prompt: str, images: list[str] = []
) -> AsyncGenerator[str, Any]:
client = AsyncClient(host=envConfig.OLLAMA_HOST)
client = AsyncClient(
host=envConfig.OLLAMA_URL, verify=envConfig.OTERM_VERIFY_SSL
)
stream: AsyncIterator[dict] = await client.generate(
model=self.model,
prompt=prompt,
Expand Down

0 comments on commit 60853b2

Please sign in to comment.