
Vultr Serverless Inference allows you to run inference workloads for large language models such as Mixtral 8x7B, Mistral 7B, Meta Llama 2 70B, and more. Using Vultr Serverless Inference, you can run inference workloads without having to worry about the infrastructure, and you only pay for the input and output tokens.
This guide demonstrates step-by-step process to start using Vultr Serverless Inference in Node.js.
Before you begin, you must:
Create a new project directory and navigate to the project directory.
Create a new Node.js project.
Install the required Node.js packages.
Please note that you only need to install the openai package if you are using the OpenAI SDK for Vultr Serverless Inference.
Vultr Serverless Inference provides a RESTful API to run inference workloads. You can use the fetch built-in module to make the API calls.
Create a new JavaScript file name inference.js.
Add the following code to inference.js.
Run the JavaScript script.
Here, we are making a POST request to https://api.vultrinference.com/v1/chat/completions with the required headers and data. The messages list contains the list of messages for which we want to generate completions, role can be either system, user or assistant, and content is the message content.
To maintain conversation context, you can add the previous messages to the messages list. You can also use the stream parameter to get real-time completions. For more information, refer to the Vultr Serverless Inference API documentation.
If you are using the OpenAI SDK for Vultr Serverless Inference, you can use the openai package to make the API calls.
Create a new JavaScript file name inference_openai.js.
Add the following code to inference_openai.js.
Run the JavaScript script.
Here, we are using the openai package to make the API calls. The messages list contains the list of messages for which we want to generate completions, role can be either system, user or assistant, and content is the message content.
In this guide, you learned how to use Vultr Serverless Inference in Node.js. You also learned how to make direct API calls and use the OpenAI SDK for Vultr Serverless Inference. You can now integrate Vultr Serverless Inference into your Node.js applications to generate completions for large language models.
0 Comments
Be the first to comment and share your perspective with the community.