Skip to content

Commit d0bc60d

Browse files
authored
Merge pull request #37 from gschmutz/support-for-env-variables
Support if environment variables to configure the app
2 parents 11163f1 + ad502e3 commit d0bc60d

File tree

5 files changed

+94
-8
lines changed

5 files changed

+94
-8
lines changed

.env.example

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
OLLAMA_BASE_URL= # the endpoint of the Ollama service, defaults to http://localhost:11434 if not set
2+
OLLAMA_MODEL= # the name of the model to use, defaults to 'llama3.2' if not set
3+
4+
# Which search service to use, either 'duckduckgo' or 'tavily' or 'perplexity'
5+
SEARCH_API=
16
# Web Search API Keys (choose one or both)
27
TAVILY_API_KEY=tvly-xxxxx # Get your key at https://tavily.com
38
PERPLEXITY_API_KEY=pplx-xxxxx # Get your key at https://www.perplexity.ai
9+
10+
MAX_WEB_RESEARCH_LOOPS=
11+
FETCH_FULL_PAGE=

.github/workflows/docker-image.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Docker Image CI
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
env:
10+
# Use docker.io for Docker Hub if empty
11+
REGISTRY: ghcr.io
12+
# github.repository as <account>/<repo>
13+
IMAGE_NAME: ${{ github.repository }}
14+
15+
jobs:
16+
build:
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@v4
22+
23+
# Setup QEMU for multi-platform build support
24+
# https://docs.docker.com/build/ci/github-actions/multi-platform/
25+
- name: Set up QEMU
26+
uses: docker/setup-qemu-action@v3
27+
28+
# Set up BuildKit Docker container builder to be able to build
29+
# multi-platform images and export cache
30+
# https://github.com/docker/setup-buildx-action
31+
- name: Setup Docker buildx
32+
uses: docker/setup-buildx-action@v3
33+
34+
# Login against a Docker registry except on PR
35+
# https://github.com/docker/login-action
36+
- name: Log into registry ${{ env.REGISTRY }}
37+
uses: docker/login-action@v3
38+
with:
39+
registry: ${{ env.REGISTRY }}
40+
username: ${{ github.actor }}
41+
password: ${{ secrets.GH_TOKEN }}
42+
43+
# Extract metadata (tags, labels) for Docker
44+
# https://github.com/docker/metadata-action
45+
- name: Extract Docker metadata
46+
id: meta
47+
uses: docker/metadata-action@v5
48+
with:
49+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
50+
51+
# Build and push Docker image with Buildx (don't push on PR)
52+
# https://github.com/docker/build-push-action
53+
- name: Build and push Docker image
54+
id: build-and-push
55+
uses: docker/build-push-action@v5
56+
with:
57+
context: .
58+
platforms: linux/amd64,linux/arm64
59+
push: true
60+
tags: |
61+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
62+
labels: ${{ steps.meta.outputs.labels }}
63+

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,17 @@ By default, it will use [DuckDuckGo](https://duckduckgo.com/) for web search, wh
3636
```bash
3737
cp .env.example .env
3838
```
39-
39+
40+
The following environment variables are supported:
41+
42+
* `OLLAMA_BASE_URL` - the endpoint of the Ollama service, defaults to `http://localhost:11434` if not set
43+
* `OLLAMA_MODEL` - the model to use, defaults to `llama3.2` if not set
44+
* `SEARCH_API` - the search API to use, either `duckduckgo` (default) or `tavily` or `perplexity`. You need to set the corresponding API key if tavily or perplexity is used.
45+
* `TAVILY_API_KEY` - the tavily API key to use
46+
* `PERPLEXITY_API_KEY` - the perplexity API key to use
47+
* `MAX_WEB_RESEARCH_LOOPS` - the maximum number of research loop steps, defaults to `3`
48+
* `FETCH_FULL_PAGE` - fetch the full page content if using `duckduckgo` for the search API, defaults to `false`
49+
4050
5. (Recommended) Create a virtual environment:
4151
```bash
4252
python -m venv .venv
@@ -172,7 +182,7 @@ https://github.com/PacoVK/ollama-deep-researcher-ts
172182

173183
## Running as a Docker container
174184

175-
The included `Dockerfile` only runs LangChain Studio with ollama-deep-researcher as a service, but does not include Ollama as a dependant service. You must run Ollama separately and configure the `OLLAMA_BASE_URL` environment variable.
185+
The included `Dockerfile` only runs LangChain Studio with ollama-deep-researcher as a service, but does not include Ollama as a dependant service. You must run Ollama separately and configure the `OLLAMA_BASE_URL` environment variable. Optionally you can also specify the Ollama model to use by providing the `OLLAMA_MODEL` environment variable.
176186

177187
Clone the repo and build an image:
178188
```
@@ -182,8 +192,10 @@ $ docker build -t ollama-deep-researcher .
182192
Run the container:
183193
```
184194
$ docker run --rm -it -p 2024:2024 \
195+
-e SEARCH_API="tavily" \
185196
-e TAVILY_API_KEY="tvly-***YOUR_KEY_HERE***" \
186197
-e OLLAMA_BASE_URL="http://host.docker.internal:11434/" \
198+
-e OLLAMA_MODEL="llama3.2" \
187199
ollama-deep-researcher
188200
```
189201

src/assistant/configuration.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ class SearchAPI(Enum):
1515
@dataclass(kw_only=True)
1616
class Configuration:
1717
"""The configurable fields for the research assistant."""
18-
max_web_research_loops: int = 3
19-
local_llm: str = "llama3.2"
20-
search_api: SearchAPI = SearchAPI.DUCKDUCKGO # Default to DUCDUCKGO
21-
fetch_full_page: bool = False # Default to False
22-
ollama_base_url: str = "http://localhost:11434/"
18+
max_web_research_loops: int = int(os.environ.get("MAX_WEB_RESEARCH_LOOPS", "3"))
19+
local_llm: str = os.environ.get("OLLAMA_MODEL", "llama3.2")
20+
search_api: SearchAPI = SearchAPI(os.environ.get("SEARCH_API", SearchAPI.DUCKDUCKGO.value)) # Default to DUCKDUCKGO
21+
fetch_full_page: bool = os.environ.get("FETCH_FULL_PAGE", "False").lower() in ("true", "1", "t")
22+
ollama_base_url: str = os.environ.get("OLLAMA_BASE_URL", "http://localhost:11434/")
2323

2424
@classmethod
2525
def from_runnable_config(

src/assistant/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,10 @@ def tavily_search(query, include_raw_content=True, max_results=3):
149149
- content (str): Snippet/summary of the content
150150
- raw_content (str): Full content of the page if available"""
151151

152-
tavily_client = TavilyClient()
152+
api_key = os.getenv("TAVILY_API_KEY")
153+
if not api_key:
154+
raise ValueError("TAVILY_API_KEY environment variable is not set")
155+
tavily_client = TavilyClient(api_key=api_key)
153156
return tavily_client.search(query,
154157
max_results=max_results,
155158
include_raw_content=include_raw_content)

0 commit comments

Comments
 (0)