Skip to main content
The Qualcomm LLM/VLM containerized service can be used with Langchain to build agentic applications as it exposes an OpenAI API compatible interface.

Simple LLM query (no streaming)

Let’s start with a simple example that calls our API and gets a result. In this example we are not using streaming mode, which means we won’t get the result from our query until the LLM has generated all of tokens in response. Let’s start by creating a new venv and install some base packages for langchain:
Next, let’s look at the code to call our locally hosted LLM. Be sure to update the base URL to match your port # as well as the model name:
python langchain example
Copy this code to a python file (langchainbasic.py in this example) and run using:
python langchainbasic.py "What is the capital of Texas?"

LLM query with streaming

While the above works fine, sometimes we want to display the tokens as they are being generated so that the user sees feedback sooner which requires us to call the LLM using streaming mode. Let’s modify our example to use this:
python langchain streaming example
Copy this code to a python file (langchainstreaming.py in this example) and run using:
python langchainstreaming.py "Tell me about Qualcomm in 50 words or less."

LLM query with tool calling

In this final example, we will call the LLM using an example of tool calling. We will define a mock api called get_weather() which the LLM will use when appropriate to look up the weather for a specific location. In the example below this function will return hardcoded values, but your real implementation could call out to a network API or some other resource to look up the actual weather.
python langchain tool calling example
Copy this code to a python file and run using:
python toolcalling.py
To exit venv:
For more information on how to use Langchain with LLMs to build Agentic AI applications, please see the Langchain documentation.