Code Examples
In this section you will find a list of code examples on what you can build with LangStream. Due to the focus of LangStream to keep the core light, we prefer to provide extensive examples of what you can do rather than extensive pre-made classes that do it for you, this makes it easier for you to understand how everything is working and connected together, and simply adapt to your use-case.
📄️ Simple Bot with Weather Tool
Below is a code example of a bot you can talk too which has the ability of checking the weather, it has memory, it is using OpenAI functions, and it streams its outputs:
📄️ Simple Bot with Weather Tool and Error Handling
The example below is similar to the Simple Bot with Weather Tool example, but here we add on_error for error handling in case something went wrong when calling the weather function. What we do is simply inject the error back into the LLM, so it can figure out itself what is missing, which in example below is the location field, and ask the user for more input
📄️ Extracting Schema for OpenAI Functions
In the code example below, we use the openaifunctioncall library to extract a schema to be used on OpenAIChatStream from a good old python function, so you don't need to write the schema yourself.
📄️ QA over documents
A common use case for LLMs is to reply answers to users based on search on a knowledge base, generally using a vector db under the hood.
📄️ Serve with FastAPI for deploying
Building an LLM bot and playing with it locally is simple enough, however, at some point you will want to put this bot in production, generally serving with through an API that the frontend can talk to. In this example, we are going to reuse the Simple Bot with Weather Tool example, but serve it through a FastAPI endpoint.