Langchain
LangChain ↗ is the most popular framework for building AI applications powered by large language models (LLMs).
LangChain publishes multiple Python packages. The following are provided by the Workers runtime:
langchain
↗ (version0.1.8
)langchain-core
↗ (version0.1.25
)langchain-openai
↗ (version0.0.6
)
Python Workers are in beta. Packages do not run in production.
Currently, you can only deploy Python Workers that use the standard library. Packages cannot be deployed and will only work in local development for the time being.
Clone the cloudflare/python-workers-examples
repository and run the LangChain example:
git clone https://github.com/cloudflare/python-workers-examplescd 04-langchainnpx wrangler@latest dev
from workers import Responsefrom langchain_core.prompts import PromptTemplatefrom langchain_openai import OpenAI
async def on_fetch(request, env): prompt = PromptTemplate.from_template("Complete the following sentence: I am a {profession} and ") llm = OpenAI(api_key=env.API_KEY) chain = prompt | llm
res = await chain.ainvoke({"profession": "electrician"}) return Response(res.split(".")[0].strip())
Was this helpful?
- Resources
- API
- New to Cloudflare?
- Products
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- © 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark