Skip to content

Gayoon1234/ollamaGraphQLWrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ollama GraphQL Wrapper

A simple Express server that wraps the Ollama REST API (localhost:11434) with GraphQL. Supports both streaming and non-streaming for the generate endpoint.

Prerequisites

  • Node.js 18+
  • Ollama running locally (ollama serve)

Setup

npm install

Running

Development (with hot reload):

npm run dev

Production:

npm run build
npm start

The server runs at http://localhost:4000/graphql by default. GraphiQL Playground is available for testing.

Configuration

  • OLLAMA_BASE_URL - Ollama API base URL (default: http://localhost:11434)
  • PORT - Server port (default: 4000)

GraphQL Operations

List models (Query)

query {
  listModels {
    models {
      name
      size
      digest
      details {
        family
        parameter_size
      }
    }
  }
}

Generate - non-streaming (Mutation)

mutation {
  generate(input: {
    model: "gemma3"
    prompt: "Why is the sky blue?"
    stream: false
  }) {
    model
    response
    done
    eval_count
  }
}

Generate - streaming (Subscription)

subscription {
  generateStream(input: {
    model: "gemma3"
    prompt: "Why is the sky blue?"
  }) {
    ... on GenerateChunk {
      response
      done
    }
    ... on GenerateError {
      error
    }
  }
}

Sanity Check

Run a script that hits all endpoints using model phi3:

# Ensure the server is running (npm run dev) and Ollama has phi3 (ollama pull phi3)
npm run sanity-check

Uses GRAPHQL_URL env var (default: http://localhost:4000/graphql).

API Reference

GraphQL REST Equivalent
query listModels GET /api/tags
mutation generate POST /api/generate with stream: false
subscription generateStream POST /api/generate (default stream)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors