Skip to content

Commit

Permalink
Merge pull request #37 from gschmutz/support-for-env-variables
Browse files Browse the repository at this point in the history
Support if environment variables to configure the app
  • Loading branch information
rlancemartin authored Feb 24, 2025
2 parents 11163f1 + ad502e3 commit d0bc60d
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 8 deletions.
8 changes: 8 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
OLLAMA_BASE_URL= # the endpoint of the Ollama service, defaults to http://localhost:11434 if not set
OLLAMA_MODEL= # the name of the model to use, defaults to 'llama3.2' if not set

# Which search service to use, either 'duckduckgo' or 'tavily' or 'perplexity'
SEARCH_API=
# Web Search API Keys (choose one or both)
TAVILY_API_KEY=tvly-xxxxx # Get your key at https://tavily.com
PERPLEXITY_API_KEY=pplx-xxxxx # Get your key at https://www.perplexity.ai

MAX_WEB_RESEARCH_LOOPS=
FETCH_FULL_PAGE=
63 changes: 63 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Docker Image CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

# Setup QEMU for multi-platform build support
# https://docs.docker.com/build/ci/github-actions/multi-platform/
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

# Set up BuildKit Docker container builder to be able to build
# multi-platform images and export cache
# https://github.com/docker/setup-buildx-action
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v3

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GH_TOKEN }}

# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
labels: ${{ steps.meta.outputs.labels }}

16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,17 @@ By default, it will use [DuckDuckGo](https://duckduckgo.com/) for web search, wh
```bash
cp .env.example .env
```


The following environment variables are supported:

* `OLLAMA_BASE_URL` - the endpoint of the Ollama service, defaults to `http://localhost:11434` if not set
* `OLLAMA_MODEL` - the model to use, defaults to `llama3.2` if not set
* `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.
* `TAVILY_API_KEY` - the tavily API key to use
* `PERPLEXITY_API_KEY` - the perplexity API key to use
* `MAX_WEB_RESEARCH_LOOPS` - the maximum number of research loop steps, defaults to `3`
* `FETCH_FULL_PAGE` - fetch the full page content if using `duckduckgo` for the search API, defaults to `false`

5. (Recommended) Create a virtual environment:
```bash
python -m venv .venv
Expand Down Expand Up @@ -172,7 +182,7 @@ https://github.com/PacoVK/ollama-deep-researcher-ts

## Running as a Docker container

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.
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.

Clone the repo and build an image:
```
Expand All @@ -182,8 +192,10 @@ $ docker build -t ollama-deep-researcher .
Run the container:
```
$ docker run --rm -it -p 2024:2024 \
-e SEARCH_API="tavily" \
-e TAVILY_API_KEY="tvly-***YOUR_KEY_HERE***" \
-e OLLAMA_BASE_URL="http://host.docker.internal:11434/" \
-e OLLAMA_MODEL="llama3.2" \
ollama-deep-researcher
```

Expand Down
10 changes: 5 additions & 5 deletions src/assistant/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ class SearchAPI(Enum):
@dataclass(kw_only=True)
class Configuration:
"""The configurable fields for the research assistant."""
max_web_research_loops: int = 3
local_llm: str = "llama3.2"
search_api: SearchAPI = SearchAPI.DUCKDUCKGO # Default to DUCDUCKGO
fetch_full_page: bool = False # Default to False
ollama_base_url: str = "http://localhost:11434/"
max_web_research_loops: int = int(os.environ.get("MAX_WEB_RESEARCH_LOOPS", "3"))
local_llm: str = os.environ.get("OLLAMA_MODEL", "llama3.2")
search_api: SearchAPI = SearchAPI(os.environ.get("SEARCH_API", SearchAPI.DUCKDUCKGO.value)) # Default to DUCKDUCKGO
fetch_full_page: bool = os.environ.get("FETCH_FULL_PAGE", "False").lower() in ("true", "1", "t")
ollama_base_url: str = os.environ.get("OLLAMA_BASE_URL", "http://localhost:11434/")

@classmethod
def from_runnable_config(
Expand Down
5 changes: 4 additions & 1 deletion src/assistant/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ def tavily_search(query, include_raw_content=True, max_results=3):
- content (str): Snippet/summary of the content
- raw_content (str): Full content of the page if available"""

tavily_client = TavilyClient()
api_key = os.getenv("TAVILY_API_KEY")
if not api_key:
raise ValueError("TAVILY_API_KEY environment variable is not set")
tavily_client = TavilyClient(api_key=api_key)
return tavily_client.search(query,
max_results=max_results,
include_raw_content=include_raw_content)
Expand Down

0 comments on commit d0bc60d

Please sign in to comment.