How to Use OgbujiPT for Self-Hosted Large Language Models

Jun 29, 2024 | Educational

If you’re diving into the world of artificial intelligence and large language models (LLMs), you’ve come to the right place! OgbujiPT is an incredibly versatile toolkit that allows you to harness the power of both self-hosted LLMs and full-service APIs like OpenAI’s GPT. This guide will take you through the steps to get started, demonstrating how you can chat with documents, run your own AutoGPT-style models, and streamline your LLM tasks.

Getting Started with OgbujiPT

Before we get into the nitty-gritty, let’s first ensure you have OgbujiPT installed. You can easily do this through pip:

pip install ogbujipt

Implementing Your First Model

Let’s walk through some sample code to get your first LLM running. Here’s how you would utilize the OpenAI Chat API:

from ogbujipt.llm_wrapper import openai_chat_api, prompt_to_chat

# Set up your API
llm_api = openai_chat_api(base_url="http://localhost:8000") # Update for your LLM API host

# Create a prompt
prompt = "Write a short birthday greeting for my star employee"

# Call the model
resp = llm_api.call(prompt_to_chat(prompt), temperature=0.1, max_tokens=256)

# Display result
print(resp.first_choice_text)

In this example, we formulate a prompt and call our model to get a response that would make any employee feel appreciated on their birthday!

Asynchronous Integration

For those who need more responsive applications, the asynchronous API is your best bet. Here’s how you can implement it:

import asyncio
from ogbujipt.llm_wrapper import openai_chat_api, prompt_to_chat

# Set up your API
llm_api = openai_chat_api(base_url="http://localhost:8000") # Update for your LLM API host

# Create a prompt and add a system message
prompt = "Write a short birthday greeting for my star employee"
messages = prompt_to_chat(prompt, system="You are a helpful AI agent…")

# Call the model asynchronously
resp = await asyncio.run(llm_api(messages, temperature=0.1, max_tokens=256))

# Display result
print(resp.first_choice_text)

Just like a fast-paced restaurant kitchen, an asynchronous setup gets your requests back to you with no delays, providing an efficient experience.

Utilizing llama.cpp for Model Control

Llama.cpp offers a unique take on LLM control. Here’s how you utilize it:

import asyncio
from ogbujipt.llm_wrapper import prompt_to_chat, llama_cpp_http_chat

# Set up your API
llm_api = llama_cpp_http_chat("http://localhost:8000") 

# Call the model
resp = asyncio.run(llm_api(prompt_to_chat("Knock knock!"), min_p=0.05))
print(resp.first_choice_text)

Think of this like knocking on a friend’s door and seeing who answers—llama.cpp lets you reach out to a model and interact immediately.

Working with Local Models Using ctransformers

If you prefer running models locally, here’s an example using ctransformers:

from ctransformers import AutoModelForCausalLM
from ogbujipt.llm_wrapper import ctransformer as ctrans_wrapper

# Load the model
model = AutoModelForCausalLM.from_pretrained(
    "TheBloke_LlongOrca-13B-16K-GGUF", 
    model_file='llongorca-13b-16k.Q5_K_M.gguf', 
    model_type='llama', 
    gpu_layers=50
)

llm = ctrans_wrapper(model=model)

# Call the model
print(llm(prompt="Write a short birthday greeting for my star employee", max_new_tokens=100))

This setup allows you to keep all the functionality on your own machine, just like having your own personal library of knowledge right at your fingertips!

Troubleshooting Tips

  • Installation Errors: Make sure pip is updated and you have the necessary dependencies installed.
  • API Issues: Double-check that your API URL is correctly set, and that your server is running.
  • Resource Limitations: If models take too long to respond, consider optimizing your LLM configuration or using a machine with better specifications.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

In Conclusion

Whether you’re utilizing self-hosted models to maintain data privacy or tapping into the power of full-service APIs for AI-driven capabilities, OgbujiPT provides the flexibility and tools needed to succeed. At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox