Package: langcorn
LangcornLangCorn is an API server that enables you to serve LangChain models and pipelines with ease, leveraging the power of FastAPI for a robust and efficient experience.FeaturesEasy deployment of LangChain models and pipelinesReady to use auth functionalityHigh-performance FastAPI framework for serving requestsScalable and robust solution for language processing applicationsSupports custom pipelines and processingWell-documented RESTful API endpointsAsynchronous processing for faster response times📦 InstallationTo get started with LangCorn, simply install the package using pip:pipinstalllangcorn⛓️ Quick StartExample LLM chain ex1.pyimportosfromlangchainimportLLMMathChain,OpenAIos.environ["OPENAI_API_KEY"]=os.environ.get("OPENAI_API_KEY","sk-********")llm=OpenAI(temperature=0)chain=LLMMathChain(llm=llm,verbose=True)Run your LangCorn FastAPI server:langcornserverexamples.ex1:chain[INFO]2023-04-1814:34:56.32|api:create_service:75|Creatingservice[INFO]2023-04-1814:34:57.51|api:create_service:85|lang_app='examples.ex1:chain':LLMChain(['product'])[INFO]2023-04-1814:34:57.51|api:create_service:104|Serving[INFO]2023-04-1814:34:57.51|api:create_service:106|Endpoint:/docs[INFO]2023-04-1814:34:57.51|api:create_service:106|Endpoint:/examples.ex1/run
INFO:Startedserverprocess[27843]INFO:Waitingforapplicationstartup.
INFO:Applicationstartupcomplete.
INFO:Uvicornrunningonhttp://127.0.0.1:8718(PressCTRL+Ctoquit)or as an alternativepython-mlangcornserverexamples.ex1:chainRun multiple chainspython-mlangcornserverexamples.ex1:chainexamples.ex2:chain[INFO]2023-04-1814:35:21.11|api:create_service:75|Creatingservice[INFO]2023-04-1814:35:21.82|api:create_service:85|lang_app='examples.ex1:chain':LLMChain(['product'])[INFO]2023-04-1814:35:21.82|api:create_service:85|lang_app='examples.ex2:chain':SimpleSequentialChain(['input'])[INFO]2023-04-1814:35:21.82|api:create_service:104|Serving[INFO]2023-04-1814:35:21.82|api:create_service:106|Endpoint:/docs[INFO]2023-04-1814:35:21.82|api:create_service:106|Endpoint:/examples.ex1/run[INFO]2023-04-1814:35:21.82|api:create_service:106|Endpoint:/examples.ex2/run
INFO:Startedserverprocess[27863]INFO:Waitingforapplicationstartup.
INFO:Applicationstartupcomplete.
INFO:Uvicornrunningonhttp://127.0.0.1:8718(PressCTRL+Ctoquit)Import the necessary packages and create your FastAPI app:fromfastapiimportFastAPIfromlangcornimportcreate_serviceapp:FastAPI=create_service("examples.ex1:chain")Multiple chainsfromfastapiimportFastAPIfromlangcornimportcreate_serviceapp:FastAPI=create_service("examples.ex2:chain","examples.ex1:chain")orfromfastapiimportFastAPIfromlangcornimportcreate_serviceapp:FastAPI=create_service("examples.ex1:chain","examples.ex2:chain","examples.ex3:chain","examples.ex4:sequential_chain","examples.ex5:conversation","examples.ex6:conversation_with_summary","examples.ex7_agent:agent",)Run your LangCorn FastAPI server:uvicornmain:app--host0.0.0.0--port8000Now, your LangChain models and pipelines are accessible via the LangCorn API server.DocsAutomatically served FastAPI docLive examplehosted on vercel.AuthIt possible to add a static api token auth by specifyingauth_tokenpythonlangcornserverexamples.ex1:chainexamples.ex2:chain--auth_token=api-secret-valueorapp:FastAPI=create_service("examples.ex1:chain",auth_token="api-secret-value")Custom API KEYsPOSThttp://0.0.0.0:3000/examples.ex6/run
X-LLM-API-KEY:sk-******
Content-Type:application/jsonHandling memory{"history":"string","input":"What is brain?","memory":[{"type":"human","data":{"content":"What is memory?","additional_kwargs":{}}},{"type":"ai","data":{"content":" Memory is the ability of the brain to store, retain, and recall information. It is the capacity to remember past experiences, facts, and events. It is also the ability to learn and remember new information.","additional_kwargs":{}}}]}Response:{"output":" The brain is an organ in the human body that is responsible for controlling thought, memory, emotion, and behavior. It is composed of billions of neurons that communicate with each other through electrical and chemical signals. It is the most complex organ in the body and is responsible for all of our conscious and unconscious actions.","error":"","memory":[{"type":"human","data":{"content":"What is memory?","additional_kwargs":{}}},{"type":"ai","data":{"content":" Memory is the ability of the brain to store, retain, and recall information. It is the capacity to remember past experiences, facts, and events. It is also the ability to learn and remember new information.","additional_kwargs":{}}},{"type":"human","data":{"content":"What is brain?","additional_kwargs":{}}},{"type":"ai","data":{"content":" The brain is an organ in the human body that is responsible for controlling thought, memory, emotion, and behavior. It is composed of billions of neurons that communicate with each other through electrical and chemical signals. It is the most complex organ in the body and is responsible for all of our conscious and unconscious actions.","additional_kwargs":{}}}]}LLM kwargsTo override the default LLM params per requestPOSThttp://0.0.0.0:3000/examples.ex1/run
X-LLM-API-KEY:sk-******
X-LLM-TEMPERATURE:0.7
X-MAX-TOKENS:256X-MODEL-NAME:gpt5
Content-Type:application/jsonCustom run functionSee ex12.pychain=LLMChain(llm=llm,prompt=prompt,verbose=True)# Run the chain only specifying the input variable.defrun(query:str)->Joke:output=chain.run(query)returnparser.parse(output)app:FastAPI=create_service("examples.ex12:run")DocumentationFor more detailed information on how to use LangCorn, including advanced features and customization options, please refer to the official documentation.👋 ContributingContributions to LangCorn are welcome! If you'd like to contribute, please follow these steps:Fork the repository on GitHubCreate a new branch for your changesCommit your changes to the new branchPush your changes to the forked repositoryOpen a pull request to the main LangCorn repositoryBefore contributing, please read the contributing guidelines.LicenseLangCorn is released under the MIT License.