Langchain Node.js SDK
Utilize the LangChain Node.js SDK with FriendliAI for seamless integration and enhanced tool calling capabilities in your applications.
You can use LangChain Node.js SDK to interact with FriendliAI. This makes migration of existing applications already using LangChain particularly easy.
How to use
Before you start, ensure you’ve already obtained the FRIENDLI_TOKEN
from the Friendli Suite.
Our products are entirely compatible with OpenAI, so we use the @langchain/openai
package by referring to the FriendliAI baseURL
.
Instantiation
Now we can instantiate our model object and generate chat completions. We provide usage examples for each type of endpoint. Choose the one that best suits your needs:
Runnable interface
We support both synchronous and asynchronous runnable methods to generate a response.
Chaining
We can chain our model with a prompt template. Prompt templates convert raw user input to better input to the LLM.
To get the string value instead of the message, we can add an output parser to the chain.
Tool calling
Describe tools and their parameters, and let the model return a tool to invoke with the input arguments. Tool calling is extremely useful for enhancing the model’s capability to provide more comprehensive and actionable responses.
Define tools to use
We can define tools with Zod schemas and use them to generate tool calls.
Bind tools to the model
Now models can generate a tool calling response.
Generate a tool assisted message
Use the tool call results to generate a message.
For more information on how to use tools, check out the LangChain documentation.