How can I integrate Ollama server with Nextjs?

I am currently working on a project that involves setting up the Ollama server with LLMs like Mistral and Llama2, along with a Next.js server to interact with it. This project is aimed at helping me learn more about Docker, but I've run into a problem.

To begin, I've created a Dockerfile for Nextjs as follows:

FROM node:18-alpine

WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install

COPY . .
RUN npm run build
CMD ["npm", "start"]    

In addition to this, I want to run a llama server with cached dependencies. To accomplish this, I tried creating a docker-compose file:

version: '3.8'
services:
  ollama:
    image: ollama/ollama
    ports:
      - "11434:11434"
    volumes:
      - ollama:/root/.ollama
    command: ollama pull llama2

  ollama-ui:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "3000:3000"

The aim here is to execute a command called ollama pull llama2, with the intention of pulling llama2 before starting the Next.js server. However, an error occurs:

ollama-1     | Error: unknown command "ollama" for "ollama"
.

The goal of this project is to have a combined container running the ollama server with certain LLMs, alongside my Next.js server, and I want the process of pulling LLMs to be cached. Is my approach correct? If not, what should I do instead?

I'm sure this issue may seem minor, but I would appreciate any guidance on how to resolve it.

Thank you!

Answer №1

If you're still on the hunt for a more effective solution, it seems like the problem lies in the fact that the docker image already has the ollama command as its entrypoint. This means you can simply execute pull llama2 without including the ollama part.

UPDATE: However, this approach presents a new challenge, as docker-compose doesn't make it straightforward to start the server first and then initiate the pull command. Therefore, utilizing an API method remains the optimal route for achieving your desired objective.

Answer №2

After encountering a similar issue, I discovered that even though located in /bin, compose was unable to locate the ollama command when running the image. A workaround I came up with is to execute a script after docker compose starts in order to fetch llama2.

#!/usr/bin/bash

curl -X POST \
-H "Content-Type: application/json" \
-d '{"name":"llama2"}' \
 http://localhost:11434/api/pull

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it possible to transfer data between pages by utilizing state in the Next.js 13 App directory?

Can Nextjs 13 App Router be used to efficiently pass previewData from MainComponent.jsx to Preview.jsx as a State, without involving query parameters or props? I want to transfer the data as state from MainComponent.jsx, then navigate to the Result.jsx com ...

Unlocking the synergy between Python and React through the seamless integration of component-based

I am attempting to containerize the workflow of an isomorphic app using Docker. This is the Dockerfile I used: FROM python:3.5-slim RUN apt-get update && \ apt-get -y install gcc mono-mcs && \ apt-get -y install vim ...

Trouble encountered while trying to animate an SVG path

My attempt to animate an SVG is not working for some reason. https://i.stack.imgur.com/atTg3.png This is the component where I'm trying to load the SVG: import { JapanMap } from "../illustrations/japanMap"; export default function Home() ...

NextJS useEffect does not pause for API response

I'm having trouble fetching the "lovedList" values when the page loads initially. The list gets updated correctly on re-rendering. How can I ensure that it waits for the list values to render the first objects from useEffect? import { Post, PostPro ...

Explore various queries and paths within MongoDB Atlas Search

I am currently working on developing an API that can return search results based on multiple parameters. So far, I have been able to successfully query one parameter. For example, here is a sample URL: http://localhost:3000/api/search?term=javascript& ...

Deploy a Vue.js application using Docker containerization technique

I am looking to dockerize my VueJS application. While I can successfully install and run my application on localhost using npm install and npm run serve commands on my local machine. To containerize the application, I have created a Dockerfile as follows: ...

Leveraging NextJS to preload Redux data with getServerSideProps

After reviewing the information in the official NextJS docs, it is recommended to utilize getServerSidedProps and getStaticProps rather than getInitialProps. The goal is to preload some data into the Redux state on the server side. Note: I am implementin ...

Error encountered: TypeError - The function formData.set is not supported. Unable to resolve this issue

Whenever I try to update the blog, an error occurs after reloading the browser. This error gets resolved when I refresh the browser before updating the blog. I have used formData.set in handleToggle and handleTagsToggle and it works fine there. However, ...

Encountering the error message "Unable to locate module '.nextserverpages-manifest.json'" while attempting to include `babel.config.js` in a Next.js application

During the process of setting up testing for my current next app, we incorporated some new dependencies including jest, babel-jest, @babel/preset-env, @babel/preset-react, and react-test-renderer. We also created a babel.config.js file to configure Babel s ...

The Angular2 app and NodeJs in the Docker container are unresponsive

After creating a new Angular2 app using angular-cli and running it in Docker, I encountered an issue where I could not connect to it from localhost. First, I initialized the app on my local machine: ng new project && cd project && "put m ...

Is it possible to create custom input fields using the Stripes Payment-Element?

I recently integrated Stripe into my next.js application to facilitate one-time payments. Following the standard tutorial for Stripe Elements, I created a PaymentIntent on initial render: useEffect(() => { // Create PaymentIntent as soon as the ...

Next.js is throwing an error about attempting to read a property of undefined while building

Currently, I am developing a comment component using Next.js for server-side rendering. Everything seems to be working perfectly fine in development mode. However, whenever I attempt to build the optimized production version, Next.js throws an error statin ...

Step-by-step guide on how to display a single button within the 'Component' section in React

I recently created a button within a .ts file located in the 'components' folder using the React framework. I am curious to know the fastest method to preview this button that I have designed. Since I am still learning, it wouldn't be feasi ...

How can I display all categories in a Radar chart using amcharts 5

I'm currently using React with amcharts to generate a Radar chart. The data I have is structured as an array of objects like this: { category: 'Something', value: 5 }. There are a total of 12 items in the data set. However, when plotting t ...

tips for accessing the useState value once it has been initialized

When using the state hook in my code, I have: const [features, setFeatures] = useState([]) const [medicalProblem, setMedicalProblem] = useState([]) The medicalProblem variable will be initially populated with a response from an API call: useEf ...

The clerk encountered difficulty retrieving the publishable key from the environment variables within Next.js version 13

I recently developed a website using Next 13 (an experimental app directory) and integrated authentication with Clerk. While everything runs smoothly on my local environment, once deployed to Netlify, the site fails to load. Upon checking the console, I e ...

Import a Module in Next.js with FileSystem (Fs) Dependency

When attempting to import glsl (import glsl from "babel-plugin-glsl/macro";), I encountered an issue where I received a "Module not found: Can't resolve 'fs'" error, or after configuring my next.config.js file with module ...

Execute JavaScript function on click event in NextJS

Is it possible to execute a JavaScript function on the client side without using addEventListener? This situation works with addEventListener. MyComponent.js import Script from 'next/script' export default function MyComponent({ props }) { ...

Issue: React child must be a valid object - Runtime Error Detected

As I delve into the world of React, NextJs, and TypeScript, I stumbled upon a tutorial on creating a navbar inspired by the 'Strip' style menu. It has been quite a learning journey for me as a newbie in these technologies. After seeking help for ...

What is the best way to serve an ".html" file at a specific URL in a Next.js application?

I'm trying to serve an ".html" file in a specific route within my Next.js app. Essentially, I want the file to be accessible at /pages/custom-route-name/my-html-file.html so that when someone visits http://example.com/custom-route-name/my-html-file.ht ...