Prerequisite:
- Open-webui, Ollama 세팅
- 2025.03.25 - [컴퓨터/머신러닝 (Machine Learning)] - Ubuntu, AMD GPU, Ollama, open-webui setting
참고
https://github.com/open-webui/open-webui
GitHub - open-webui/open-webui: User-friendly AI Interface (Supports Ollama, OpenAI API, ...)
User-friendly AI Interface (Supports Ollama, OpenAI API, ...) - open-webui/open-webui
github.com
https://docs.openwebui.com/pipelines/
⚡ Pipelines | Open WebUI
DO NOT USE PIPELINES!
docs.openwebui.com
목표: 연구 개발 과정에서 사용되는 command들을 모아서 넣어주면 적절하게 자동으로 markdown 형식으로 documentation.
순서:
- Open WebUI 환경에서 문서화 정리를 요청
- LangChain과 Open WebUI의 pipeline 을 통해 ollama 에게 문서화 정리 prompt 전달
- Markdown 형식의 문서를 Open WebUI에 출력
Open WebUI (port:30000)
│
├── Ollama (port:11434)
│
└── Pipelines (port:9099)
└── LangChain API (port:8000, host.docker.internal)
1. Langchain Setting
필요 패키지 설치
pip install fastapi uvicorn langchain ollama python-multipart
langchain을 구동할 app.py 작성
from fastapi import FastAPI, Form
from fastapi.middleware.cors import CORSMiddleware
from langchain.llms import Ollama
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_methods=["*"],
allow_headers=["*"],
)
prompt_template = PromptTemplate(
input_variables=["commands"],
template="""
You are a documentation assistant. Convert the given commands or scripts into clear, structured documentation in Markdown format.
Commands or scripts:
{commands}
Documentation:
"""
)
@app.post("/generate-docs/")
async def generate_docs(commands: str = Form(...), model: str = Form(...)):
llm = Ollama(base_url="http://localhost:11434", model="gemma3:12b")
chain = LLMChain(llm=llm, prompt=prompt_template)
result = chain.run(commands=commands)
return {"documentation": result.strip()}
langchain 구동
uvicorn app:app --host 0.0.0.0 --port 8000
2. open-webui의 pipeline 기능과 langchain을 연결할 langchain.py 작성
*LANGCHAIN_API_URL의 주소를 위에서 구동한 langchain 이 구동된 ip주소와 포트 입력
"""
title: LangChain Documentation Generator
description: Sends commands to LangChain API for documentation generation.
version: 1.0
author: Your Name
"""
from typing import List, Union, Generator, Iterator
from schemas import OpenAIChatMessage
from pydantic import BaseModel, Field
import requests
import os
class Pipeline:
class Valves(BaseModel):
LANGCHAIN_API_URL: str = Field(
default="http://192.168.0.41:8000/generate-docs/",
description="LangChain API endpoint URL"
)
def __init__(self):
self.valves = self.Valves(
LANGCHAIN_API_URL=os.getenv("LANGCHAIN_API_URL", "http://192.168.0.41:8000/generate-docs/")
)
async def on_startup(self):
# 서버 시작 시 호출되는 메서드 (필요시 초기화)
pass
async def on_shutdown(self):
# 서버 종료 시 호출되는 메서드 (자원 정리 등)
pass
def pipe(
self,
user_message: str,
model_id: str,
messages: List[dict],
body: dict
) -> Union[str, Generator, Iterator]:
if not user_message.strip():
return "No commands provided for documentation."
payload = {
"commands": user_message,
"model": model_id
}
try:
response = requests.post(self.valves.LANGCHAIN_API_URL, data=payload)
response.raise_for_status()
documentation = response.json().get("documentation", "No documentation generated.")
return documentation
except requests.RequestException as e:
return f"Error communicating with LangChain API: {str(e)}"
3. Open-webui의 pipeline 컨테이너 부분 docker-compose.yml 파일 추가 및 구동
*위에서 준비한 langchain.py 파일이 담긴 폴더 마운트 필요 - "./data/pipelines:/app/pipelines" 부분
services:
open-webui:
image: 'ghcr.io/open-webui/open-webui:main'
restart: always
environment:
OLLAMA_BASE_URL: "http://ollama:11434" # <- 이 부분을 추가
container_name: open-webui
ports:
- '30000:8080'
volumes:
- './data/open-webui:/app/backend/data'
- './data/open-webui-plugins:/app/backend/data/plugins'
extra_hosts:
- "host.docker.internal:host-gateway"
networks:
- webui-network
ollama:
image: 'ollama/ollama:rocm'
restart: always
volumes:
- './data/ollama:/root/.ollama'
ports:
- '11434:11434'
devices:
- "/dev/kfd"
- "/dev/dri"
group_add:
- "${RENDER_GROUP_ID:-992}"
- "video"
networks:
- webui-network
## pipeline 서비스를 위해 추가
pipelines:
image: 'ghcr.io/open-webui/pipelines:main'
restart: always
container_name: pipelines
ports:
- '9100:9099'
volumes:
- './data/pipelines:/app/pipelines'
extra_hosts:
- "host.docker.internal:host-gateway"
networks:
- webui-network
networks:
webui-network:
driver: bridge
이후 compose up
sudo docker compose up
4. Open-Webui 에서 pipeline API 연결
- Setting - Connections - OpenAI API 항목 추가 - URL 항목, http://pipelines:9099 입력 - Key 항목, 0p3n-w3bu! 입력
- 참조 https://docs.openwebui.com/pipelines/
- connection test를 진행, 통과필수 (refresh 버튼)
- connection fail의 경우 api 통신 문제
5. Open-Webui 에서 Pipelines 세팅
- Setting - Pipelines 에서 Pipelines Valves 드랍박스에서 langchain (pipe) 선택후 save
- pipeline이 없는 경우 mount 문제 또는 api 통신 문제
- 8000번 포트 방화벽 세팅 확인
6. 사용
- Prompt 입력 화면 모델 드랍박스에서 langchain 선택
- 테스트로 세팅에 사용된 docker-compose.yml 파일 입력
- output:
- Markdown viwer에서 확인