Skip to content

cwelch1070/contextd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

contextd

contextd is a small Go proxy that sits in front of an Ollama server and injects additional system context into chat requests before forwarding them upstream.

The current target use case is Continue in VS Code. Instead of pointing Continue directly at Ollama, you point it at contextd. The proxy reads a local markdown file, prepends that content as a system message, sends the modified payload to Ollama, and returns Ollama's response back to the client.

How It Works

For requests sent to /api/chat, contextd: `

  1. Accepts the JSON request from the client.
  2. Unmarshals the request into Go structs.
  3. Reads a local context file from disk.
  4. Prepends the file contents as a system message.
  5. Marshals the modified payload back to JSON.
  6. Forwards the request to the configured Ollama endpoint.
  7. Returns the upstream response to the original caller.

This lets you centralize personality, instructions, or user-specific context without modifying each client integration.

Current Scope

The current implementation only handles:

  • POST /api/chat

It is intentionally narrow while the proxy behavior is being developed and learned in Go.

Requirements

  • Go 1.25+
  • A running Ollama server
  • A context file on disk, such as Context.md
  • A client that can target an Ollama-compatible endpoint, such as Continue

Configuration

contextd reads its configuration from environment variables.

Variable Description Example
PORT Listen address for the Go server. This must be a valid host:port style address. :8080
OLLAMA_BASE_URL Full upstream Ollama chat endpoint. http://localhost:11434/api/chat
SYSTEM_CONTEXT_FILE Path to the markdown/text file to inject as the system prompt. Context.md

Example:

export PORT=:8080
export OLLAMA_BASE_URL=http://localhost:11434/api/chat
export SYSTEM_CONTEXT_FILE=Context.md

Running Locally

Start the proxy:

go run main.go

If the server starts correctly, it will listen on the address configured by PORT.

Continue Setup

Point Continue at the proxy instead of Ollama directly.

Example Continue model configuration:

models:
  - name: local-llm
    provider: ollama
    model: llama3.2
    apiBase: http://localhost:8080

Continue will send requests like:

POST http://localhost:8080/api/chat

contextd receives that request, injects the configured context, and forwards it to:

POST http://localhost:11434/api/chat

Example Context File

Example Context.md:

Your name is (clever name for llm goes here).
You are Caleb Welch's AI assistant.
You are direct, technically rigorous, and concise.

That content is inserted into the outbound Ollama chat payload as a system message.

Example Request Flow

Client request:

{
  "model": "llama3.2",
  "messages": [
    {
      "role": "user",
      "content": "Explain slices in Go."
    }
  ]
}

Modified request sent upstream:

{
  "model": "llama3.2",
  "messages": [
    {
      "role": "system",
      "content": "<contents of Context.md>"
    },
    {
      "role": "user",
      "content": "Explain slices in Go."
    }
  ]
}

Project Goals

  • Learn idiomatic Go by building a real service
  • Centralize LLM personality and persistent context outside the client
  • Keep Ollama-compatible clients unchanged
  • Expand over time into a more capable local LLM middleware layer

Limitations

  • Only /api/chat is currently handled
  • Context is read from disk on each request
  • The current proxy flow is designed for local development and experimentation
  • Additional Ollama endpoints such as /api/generate are not yet implemented

Development Notes

This project is intentionally being built incrementally as a Go learning exercise. The implementation favors clarity and directness over abstraction while the core proxy behavior is being established.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages