Skip to content

Commit 2d2eca2

Browse files
authored
Merge pull request #26 from jakobhoeg/develop
fix: prefix OLLAMA_URL with NEXT_PUBLIC to make it accessible on client siden in production
2 parents 1472547 + 988dd70 commit 2d2eca2

File tree

9 files changed

+11
-9
lines changed

9 files changed

+11
-9
lines changed

.example.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
OLLAMA_URL="http://localhost:11434"
1+
NEXT_PUBLIC_OLLAMA_URL="http://localhost:11434"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ mv .example.env .env
6565
**4. If your instance of Ollama is NOT running on the default ip-address and port, change the variable in the .env file to fit your usecase:**
6666

6767
```
68-
OLLAMA_URL="http://localhost:11434"
68+
NEXT_PUBLIC_OLLAMA_URL="http://localhost:11434"
6969
```
7070

7171
**5. Install dependencies:**

src/app/[id]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default function Page({ params }: { params: { id: string } }) {
3232
useEffect(() => {
3333
if (env === "production") {
3434
const newOllama = new ChatOllama({
35-
baseUrl: process.env.OLLAMA_URL || "http://localhost:11434",
35+
baseUrl: process.env.NEXT_PUBLIC_OLLAMA_URL || "http://localhost:11434",
3636
model: selectedModel,
3737
});
3838
setOllama(newOllama);

src/app/api/chat/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export async function POST(req: Request) {
1010
const { messages, selectedModel } = await req.json();
1111

1212
const model = new ChatOllama({
13-
baseUrl: process.env.OLLAMA_URL,
13+
baseUrl: process.env.NEXT_PUBLIC_OLLAMA_URL || "http://localhost:11434",
1414
model: selectedModel,
1515
});
1616

src/app/api/model/route.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
export async function POST(req: Request) {
22
const { name } = await req.json();
33

4-
const response = await fetch(process.env.OLLAMA_URL + "/api/pull", {
4+
const ollamaUrl = process.env.NEXT_PUBLIC_OLLAMA_URL || "http://localhost:11434";
5+
6+
const response = await fetch(ollamaUrl + "/api/pull", {
57
method: "POST",
68
body: JSON.stringify({ name }),
79
});

src/app/api/tags/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export const dynamic = "force-dynamic";
22

33
export async function GET(req: Request) {
4-
const OLLAMA_URL = process.env.OLLAMA_URL || "http://localhost:11434";
4+
const OLLAMA_URL = process.env.NEXT_PUBLIC_OLLAMA_URL || "http://localhost:11434";
55
const res = await fetch(
66
OLLAMA_URL + "/api/tags"
77
);

src/app/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export default function Home() {
5252
useEffect(() => {
5353
if (env === "production") {
5454
const newOllama = new ChatOllama({
55-
baseUrl: process.env.OLLAMA_URL || "http://localhost:11434",
55+
baseUrl: process.env.NEXT_PUBLIC_OLLAMA_URL || "http://localhost:11434",
5656
model: selectedModel,
5757
});
5858
setOllama(newOllama);

src/components/chat/chat-topbar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export default function ChatTopbar({
4545

4646
const fetchModels = async () => {
4747
if (env === "production") {
48-
const fetchedModels = await fetch(process.env.OLLAMA_URL + "/api/tags");
48+
const fetchedModels = await fetch(process.env.NEXT_PUBLIC_OLLAMA_URL + "/api/tags");
4949
const json = await fetchedModels.json();
5050
const apiModels = json.models.map((model : any) => model.name);
5151
setModels([...apiModels]);

src/components/pull-model-form.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export default function PullModelForm() {
4040
if (env === "production") {
4141
// Make a post request to localhost
4242
const pullModel = async () => {
43-
const response = await fetch(process.env.OLLAMA_URL + "/api/pull", {
43+
const response = await fetch(process.env.NEXT_PUBLIC_OLLAMA_URL + "/api/pull", {
4444
method: "POST",
4545
headers: {
4646
"Content-Type": "application/json",

0 commit comments

Comments
 (0)