Hugo Ventura

Replacing OpenAI Stack with Local Tools


OpenAI has revolutionized the field of AI by providing a large set of powerful tools and models. However, not everyone may have access to or want to rely on online services. Fortunately, there are offline alternatives available for some of these elements in the OpenAI stack. Let's explore how these alternatives can be used.

ChatGPT

GPT 3.5, a widely used language model, can be easily replaced by Mistral 7B, which is another impressive model with 7 billion parameters. Mistral 7B delivers comparable quality to GPT 3.5 and has the added advantage of being able to run locally. In contrast, GPT 3.5 is proprietary and can only be accessed through OpenAI's paid services.

With Mistral 7B, you can enjoy the same capabilities without relying on external resources. Here's a Python example on how to use Mistral 7B with HuggingFace transformers:

python
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer

# Load Mistral 7B model and tokenizer
model_name = "mistralai/Mistral-7B-Instruct-v0.1"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)

# Define input prompt
prompt = "<s>[INST] Tell me a joke [/INST]"

# Tokenize input prompt
input_ids = tokenizer.encode(prompt, return_tensors="pt")

# Generate text using Mistral 7B
output = model.generate(input_ids, max_length=100, num_return_sequences=1)

# Decode generated output
generated_text = tokenizer.decode(output[0], skip_special_tokens=True)

# Print generated text
print(generated_text)

In the example above, we first import the necessary dependencies from the transformers library. We then specify the Mistral 7B model name and initialize the corresponding tokenizer and model objects. Next, we define the input prompt, tokenize it using the tokenizer, and generate text using the Mistral 7B model. Finally, we decode the generated output and print the resulting text.

But, if you do not want to deal with Python code, and just want to explore what Mistral 7B can offer, a good alternative is to use LM Studio. It's available for macOS, Windows and Linux!

Dall-E 3

For those seeking an offline alternative to Dall-E, the image generation model, Stable Diffusion offers viable options. Models such as SDXL or JuggernautXL can be used programmatically or through user-friendly GUI interfaces like sb-webui or ComfyUI. These alternatives enable you to generate images using Stable Diffusion without the need for an online connection. Moreover, emerging models like SDXL-Turbo or LCM LoRA allow for near real-time image generation, making the offline experience even more seamless.

Code Interpreter

Finding a tangible alternative to the Code Interpreter is a challenge. While it is possible to hack together a solution that executes code in a virtual machine (VM) or a Docker container, there are no readily available solutions with comparable functionality. Developers may need to resort to custom solutions until an offline tool specifically designed for code interpretation becomes available.

Copilot (bonus)

Copilot, an AI-powered tool for code generation, can be replaced with a combination of FauxPilot plugin on VSCode and locally running tools like CodeLLaMa or StarCoder. Additionally, Mistral, the language model mentioned earlier, can also be utilized for code-related tasks as it performs reasonably well in this domain.

While offline alternatives for some elements of the OpenAI stack are readily available, it is important to note that these substitutes may not offer the exact same functionality or performance. Nevertheless, they provide viable options for those who prefer working offline or do not have access to the online OpenAI services.

OpenAI also has another advantage to these offline solutions, everything is in the same interface. Luckily, with a little bit of thought and some basic coding knowledges, it is easily achievable — Is it worth the time ? Probably not, but is it a fun weekend project ? Absolutely!

As this space continues to expand, we can expect a lot more offline tools to emerge. Most recent example being the rise of almost real-time diffusion models.