Skill: manojrammurthy/openclaw-skill-langchain-local (version 0.1.0)

# LangChain Local — Offline AI Chains with Ollama Run LangChain pipelines locally using Ollama and phi4-mini (or any local model). No API keys, no cloud, fully private and offline. ## Requirements - Ollama installed and running (`ollama serve`) - phi4-mini pulled (`ollama pull phi4-mini`) - Python packages: `pip install langchain langchain-ollama langchain-community` ## Modes - `coding` — Python/Django code generation (low temperature, precise) - `devops` — Linux/Nginx/Docker shell commands - `chat` — General conversation - `rag` — Document-grounded answers (context-aware) ## Usage Examples - "Ask langchain-local to write a Django REST API view" - "Use langchain-local in devops mode to show how to check disk usage" - "Run langchain-local chat mode: explain what is RAG" - "Use langchain-local coding mode to write a PostgreSQL backup script" ## Implementation Execute: python3 ~/.openclaw/skills/langchain-local/main.py ## Parameters - mode: coding | devops | chat | rag (default: coding) - query: Your question or instruction ## Author Manoj — https://github.com/manoj

path: README.md
content: # langchain-local

> Run LangChain AI chains 100% locally using Ollama — no API keys needed.

## What It Does
This OpenClaw skill lets you run LangChain pipelines powered by a local Ollama
model (phi4-mini by default). All inference happens on your machine — private,
offline, and free.

## Modes
| Mode | Use Case | Temperature |
|------|----------|-------------|
| coding | Python, Django, SQL code generation | 0.1 |
| devops | Nginx, Linux, Docker commands | 0.1 |
| chat | General assistant | 0.7 |
| rag | Document-grounded answers | 0.1 |

## Requirements
- macOS or Linux
- Ollama installed: brew install ollama
- Model pulled: ollama pull phi4-mini
- Python 3.9+: pip install langchain langchain-ollama langchain-community

## Quick Test
Run: python3 ~/.openclaw/skills/langchain-local/main.py

## License
MIT


path: config.py
content: # config.py
OLLAMA_BASE_URL = "http://localhost:11434"
MODEL_NAME = "phi4-mini"

LLM_CONFIG = {
    "coding": {
        "temperature": 0.1,
        "num_predict": 512,
        "top_p": 0.9,
        "repeat_penalty": 1.1
    },
    "chat": {
        "temperature": 0.7,
        "num_predict": 1024,
        "top_p": 0.95,
        "repeat_penalty": 1.0
    },
    "devops": {
        "temperature": 0.1,
        "num_predict": 256,
        "top_p": 0.9,
        "repeat_penalty": 1.1
    }
}



path: main.py
content: import warnings
warnings.filterwarnings("ignore")

from langchain_ollama import ChatOllama
from langchain.prompts import ChatPromptTemplate
from config import OLLAMA_BASE_URL, MODEL_NAME, LLM_CONFIG
from prompts import SYSTEM_PROMPTS


def build_chain(mode: str = "coding"):
    config = LLM_CONFIG.get(mode, LLM_CONFIG["chat"])
    llm = ChatOllama(
        model=MODEL_NAME,
        base_url=OLLAMA_BASE_URL,
        **config
    )
    prompt = ChatPromptTemplate.from_messages([
        ("system", SYSTEM_PROMPTS[mode]),
        ("human", "{query}")
    ])
    return prompt | llm


def ask(query: str, mode: str = "coding") -> str:
    chain = build_chain(mode)
    full_response = ""
    for chunk in chain.stream({"query": query}):
        print(chunk.content, end="", flush=True)
        full_response += chunk.content
    print()
    return full_response


def interactive():
    """Simple interactive CLI loop."""
    print("=== LangChain phi4-mini CLI ===")
    print("Modes: coding | devops | chat | rag")
    print("Type 'exit' to quit\n")
    while True:
        mode = input("Mode (default=coding): ").strip() or "coding"
        if mode == "exit":
            break
        if mode not in LLM_CONFIG:
            print(f"Unknown mode. Choose from: {list(LLM_CONFIG.keys())}")
            continue
        query = input("Query: ").strip()
        if query == "exit":
            break
        print(f"\n[{mode.upper()}] Response:")
        ask(query, mode=mode)
        print()


if __name__ == "__main__":
    interactive()


path: prompts.py
content: # prompts.py
SYSTEM_PROMPTS = {
    "coding": """You are an expert Python and Django developer.
- Return only clean, working code
- No filler phrases like 'Certainly!' or 'Sure!'
- Minimal but useful inline comments
- If asked for explanation, be brief and direct""",

    "devops": """You are a Linux/DevOps expert specializing in Django, 
Nginx, Ubuntu, and Docker.
- Give direct shell commands only
- No lengthy explanations unless asked
- Always mention if a command needs sudo""",

    "rag": """You are a precise research assistant.
- Answer ONLY from the provided context
- If answer is not in context, say: 'Not found in documents'
- Be concise, no filler words""",

    "chat": """You are a helpful and concise assistant.
- Be direct and to the point
- No unnecessary preamble
- Keep responses under 200 words unless more is needed"""
}



Security scan verdicts — ClawScan: clean | static analysis: clean | VirusTotal: clean | SkillSpector: clean (LOW)