OpenWebUIAI
This notebook provides a quick overview for getting started with Open WebUI. You can find how to use it in OpenWebUI.
Overviewโ
Integration detailsโ
Class | Package | Local | Serializable | JS support | Package downloads | Package latest |
---|---|---|---|---|---|---|
langchain-openwebui | langchain_community | โ | โ | โ | 0 |
Model featuresโ
Tool calling | Structured output | JSON mode | Image input | Audio input | Video input | Token-level streaming | Native async | Token usage | Logprobs |
---|---|---|---|---|---|---|---|---|---|
โ | โ | โ | โ | โ | โ | โ | โ | โ | โ |
Setupโ
To access OpenWebUI models you'll need to create an Open WebUI account, get an API key.
Credentialsโ
Head to https://docs.openwebui.com/ to sign up for Open WebUI and generate an API key. Once you've done this set the OPENWEBUI_API_KEY environment variable:
Installationโ
Install langchain-openwebui via pypi
pip install langchain-openwebui
Collecting langchain-openwebui
Obtaining dependency information for langchain-openwebui from https://files.pythonhosted.org/packages/92/4a/cdd276af319497ee0baf44ff1faeddf291c8e37c8759afd13e0ca027b4da/langchain_openwebui-0.0.1-py3-none-any.whl.metadata
Downloading langchain_openwebui-0.0.1-py3-none-any.whl.metadata (10 kB)
Downloading langchain_openwebui-0.0.1-py3-none-any.whl (5.4 kB)
[33mDEPRECATION: textract 1.6.5 has a non-standard dependency specifier extract-msg<=0.29.*. pip 23.3 will enforce this behaviour change. A possible replacement is to upgrade to a newer version of textract or contact the author to suggest that they release a version with a conforming dependency specifiers. Discussion can be found at https://github.com/pypa/pip/issues/12063[0m[33m
[0mInstalling collected packages: langchain-openwebui
Successfully installed langchain-openwebui-0.0.1
[33mWARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv[0m[33m
[0m[33mWARNING: There was an error checking the latest version of pip.[0m[33m
[0mNote: you may need to restart the kernel to use updated packages.
Instantiationโ
import os
openwebui_api_key = os.environ["OPENWEBUI_API_KEY"]
openwebui_api_base = os.environ["OPENWEBUI_API_BASE"]
from langchain_community.chat_models import OpenWebUIAI
llm = OpenWebUIAI(
temperature=0.1,
api_key=openwebui_api_key,
api_base=openwebui_api_base,
model="gemini-2.0-pro-exp-02-05",
)
API Reference:OpenWebUIAI
Invocationโ
from langchain_core.messages import HumanMessage
response = llm.invoke(input=[HumanMessage(content="Hello")])
response
API Reference:HumanMessage
Chainingโ
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.runnables import RunnablePassthrough
prompt = ChatPromptTemplate.from_template(
"""please answer the question below: {question}"""
)
retriever_chain = {"question": RunnablePassthrough()} | prompt | llm | StrOutputParser()
AIMessage(content=' Ich liebe Programmieren.\n\n', additional_kwargs={}, response_metadata={}, id='run-ffc4ace1-b73a-4fb3-ad0f-57e60a0f9b8d-0')
API referenceโ
https://docs.openwebui.com/getting-started/api-endpoints
Relatedโ
- Chat model conceptual guide
- Chat model how-to guides