
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 Python.
Before you begin, you must:
Create a new project directory and navigate to the project directory.
Create a new Python virtual environment.
Install the required Python 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 requests package to make the API calls.
Create a new Python file name inference.py.
Add the following code to inference.py.
Run the Python 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 Python file name inference_openai.py.
Add the following code to inference_openai.py.
Run the Python 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.
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.
In this guide, you learned how to use Vultr Serverless Inference in Python to run inference workloads for large language models. You also learned how to use the requests package and the OpenAI SDK to make API calls to Vultr Serverless Inference. You can now integrate Vultr Serverless Inference into your Python applications to generate completions for large language models.
0 Comments
Be the first to comment and share your perspective with the community.