Skip to content

Commit 146540c

Browse files
authored
feat: add perplexica module (#596)
1 parent a85436f commit 146540c

File tree

6 files changed

+264
-0
lines changed

6 files changed

+264
-0
lines changed

‎.icons/perplexica.svg‎

Lines changed: 8 additions & 0 deletions
Loading
766 KB
Loading
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
display_name: Perplexica
3+
description: Run Perplexica AI search engine in your workspace via Docker
4+
icon: ../../../../.icons/perplexica.svg
5+
verified: false
6+
tags: [ai, search, docker]
7+
---
8+
9+
# Perplexica
10+
11+
Run [Perplexica](https://github.com/ItzCrazyKns/Perplexica), a privacy-focused AI search engine, in your Coder workspace. Supports cloud providers (OpenAI, Anthropic Claude) and local LLMs via Ollama.
12+
13+
```tf
14+
module "perplexica"{
15+
count = data.coder_workspace.me.start_count
16+
source = "registry.coder.com/coder-labs/perplexica/coder"
17+
version = "1.0.0"
18+
agent_id = coder_agent.main.id
19+
}
20+
```
21+
22+
This module uses the full Perplexica image with embedded SearXNG for simpler setup with no external dependencies.
23+
24+
![Perplexica](../../.images/perplexica.png)
25+
26+
## Prerequisites
27+
28+
This module requires Docker to be available on the host.
29+
30+
## Examples
31+
32+
### With API Keys
33+
34+
```tf
35+
module "perplexica"{
36+
count = data.coder_workspace.me.start_count
37+
source = "registry.coder.com/coder-labs/perplexica/coder"
38+
version = "1.0.0"
39+
agent_id = coder_agent.main.id
40+
openai_api_key = var.openai_api_key
41+
anthropic_api_key = var.anthropic_api_key
42+
}
43+
```
44+
45+
### With Local Ollama
46+
47+
```tf
48+
module "perplexica"{
49+
count = data.coder_workspace.me.start_count
50+
source = "registry.coder.com/coder-labs/perplexica/coder"
51+
version = "1.0.0"
52+
agent_id = coder_agent.main.id
53+
ollama_api_url = "http://ollama-external-endpoint:11434"
54+
}
55+
```
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
terraform{
2+
required_version=">= 1.0"
3+
4+
required_providers{
5+
coder={
6+
source ="coder/coder"
7+
version =">= 2.5"
8+
}
9+
}
10+
}
11+
12+
variable"agent_id"{
13+
type=string
14+
description="The ID of a Coder agent."
15+
}
16+
17+
variable"docker_socket"{
18+
type=string
19+
description="(Optional) Docker socket URI"
20+
default=""
21+
}
22+
23+
variable"port"{
24+
type=number
25+
description="The port to run Perplexica on."
26+
default=3000
27+
}
28+
29+
variable"data_path"{
30+
type=string
31+
description="Host path to mount for Perplexica data persistence."
32+
default="./perplexica-data"
33+
}
34+
35+
variable"uploads_path"{
36+
type=string
37+
description="Host path to mount for Perplexica file uploads."
38+
default="./perplexica-uploads"
39+
}
40+
41+
variable"openai_api_key"{
42+
type=string
43+
description="OpenAI API key."
44+
default=""
45+
sensitive=true
46+
}
47+
48+
variable"anthropic_api_key"{
49+
type=string
50+
description="Anthropic API key for Claude models."
51+
default=""
52+
sensitive=true
53+
}
54+
55+
variable"ollama_api_url"{
56+
type=string
57+
description="Ollama API URL for local LLM support."
58+
default=""
59+
}
60+
61+
variable"share"{
62+
type=string
63+
default="owner"
64+
validation{
65+
condition=var.share=="owner"|| var.share=="authenticated"|| var.share=="public"
66+
error_message="Incorrect value. Please set either 'owner', 'authenticated', or 'public'."
67+
}
68+
}
69+
70+
variable"order"{
71+
type=number
72+
description="The order determines the position of app in the UI presentation. The lowest order is shown first and apps with equal order are sorted by name (ascending order)."
73+
default=null
74+
}
75+
76+
variable"group"{
77+
type=string
78+
description="The name of a group that this app belongs to."
79+
default=null
80+
}
81+
82+
resource"coder_script""perplexica"{
83+
agent_id=var.agent_id
84+
display_name="Perplexica"
85+
icon="/icon/perplexica.svg"
86+
script=templatefile("${path.module}/run.sh",{
87+
DOCKER_HOST : var.docker_socket,
88+
PORT : var.port,
89+
DATA_PATH : var.data_path,
90+
UPLOADS_PATH : var.uploads_path,
91+
OPENAI_API_KEY : var.openai_api_key,
92+
ANTHROPIC_API_KEY : var.anthropic_api_key,
93+
OLLAMA_API_URL : var.ollama_api_url,
94+
})
95+
run_on_start=true
96+
}
97+
98+
resource"coder_app""perplexica"{
99+
agent_id=var.agent_id
100+
slug="perplexica"
101+
display_name="Perplexica"
102+
url="http://localhost:${var.port}"
103+
icon="/icon/perplexica.svg"
104+
subdomain=true
105+
share=var.share
106+
order=var.order
107+
group=var.group
108+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
run"plan_basic"{
2+
command=plan
3+
4+
variables{
5+
agent_id="test-agent"
6+
}
7+
8+
assert{
9+
condition=resource.coder_app.perplexica.url=="http://localhost:3000"
10+
error_message="Default port should be 3000"
11+
}
12+
}
13+
14+
run"plan_custom_port"{
15+
command=plan
16+
17+
variables{
18+
agent_id="test-agent"
19+
port=8080
20+
}
21+
22+
assert{
23+
condition=resource.coder_app.perplexica.url=="http://localhost:8080"
24+
error_message="Should use custom port"
25+
}
26+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env sh
2+
3+
set -eu
4+
5+
BOLD='\033[0;1m'
6+
RESET='\033[0m'
7+
8+
printf"$${BOLD}Starting Perplexica...$${RESET}\n"
9+
10+
# Set Docker host if provided
11+
if [ -n"${DOCKER_HOST}" ];then
12+
export DOCKER_HOST="${DOCKER_HOST}"
13+
fi
14+
15+
# Wait for docker to become ready
16+
max_attempts=10
17+
delay=2
18+
attempt=1
19+
20+
while! docker ps;do
21+
if [ $attempt-ge$max_attempts ];then
22+
echo"Failed to list containers after $${max_attempts} attempts."
23+
exit 1
24+
fi
25+
echo"Attempt $${attempt} failed, retrying in $${delay}s..."
26+
sleep $delay
27+
attempt=$(expr "$attempt" + 1)
28+
delay=$(expr "$delay"\* 2)
29+
done
30+
31+
# Pull the image
32+
IMAGE="itzcrazykns1337/perplexica:latest"
33+
docker pull "$${IMAGE}"
34+
35+
# Build docker run command
36+
DOCKER_ARGS="-d --rm --name perplexica -p ${PORT}:3000"
37+
38+
# Add mounts - convert relative paths to absolute
39+
DATA_PATH="${DATA_PATH}"
40+
UPLOADS_PATH="${UPLOADS_PATH}"
41+
42+
mkdir -p "$${DATA_PATH}"
43+
mkdir -p "$${UPLOADS_PATH}"
44+
45+
DATA_PATH_ABS=$(cd "$${DATA_PATH}"&& pwd)
46+
UPLOADS_PATH_ABS=$(cd "$${UPLOADS_PATH}"&& pwd)
47+
48+
DOCKER_ARGS="$${DOCKER_ARGS} -v $${DATA_PATH_ABS}:/home/perplexica/data"
49+
DOCKER_ARGS="$${DOCKER_ARGS} -v $${UPLOADS_PATH_ABS}:/home/perplexica/uploads"
50+
51+
# Add environment variables if provided
52+
if [ -n"${OPENAI_API_KEY}" ];then
53+
DOCKER_ARGS="$${DOCKER_ARGS} -e OPENAI_API_KEY=${OPENAI_API_KEY}"
54+
fi
55+
56+
if [ -n"${ANTHROPIC_API_KEY}" ];then
57+
DOCKER_ARGS="$${DOCKER_ARGS} -e ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY}"
58+
fi
59+
60+
if [ -n"${OLLAMA_API_URL}" ];then
61+
DOCKER_ARGS="$${DOCKER_ARGS} -e OLLAMA_API_URL=${OLLAMA_API_URL}"
62+
fi
63+
64+
# Run container
65+
docker run $${DOCKER_ARGS} "$${IMAGE}"
66+
67+
printf"\n$${BOLD}Perplexica is running on port ${PORT}$${RESET}\n"

0 commit comments

Comments
(0)