Movatterモバイル変換


[0]ホーム

URL:


Skip to content
Cloudflare Docs
Log in

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:

Get Started

Clone thecloudflare/python-workers-examples repository and run the LangChain example:

Terminal window
gitclonehttps://github.com/cloudflare/python-workers-examples
cd04-langchain
uvrunpywranglerdev

Example code

Python
from workersimport WorkerEntrypoint, Response
from langchain_core.promptsimport PromptTemplate
from langchain_openaiimport OpenAI
classDefault(WorkerEntrypoint):
asyncdeffetch(self,request):
prompt= PromptTemplate.from_template("Complete the following sentence: I am a{profession} and ")
llm=OpenAI(api_key=self.env.API_KEY)
chain= prompt| llm
res=await chain.ainvoke({"profession":"electrician"})
returnResponse(res.split(".")[0].strip())

[8]ページ先頭

©2009-2025 Movatter.jp