Quick Start

Interacting with Konko Models using LlamaIndex

This guide goes over how to use LlamaIndex to interact with Konko ChatCompletion models and Completion models.

By the end of this tutorial, you will be able to set up your environment to interact with Konko models, send queries, and receive responses from these models.



Before you begin, make sure you have the Konko API key. If you don't, request it by emailing [email protected]. For installation guidance, please refer to the Installation and Setup guide.

Also, remember to set the Konko API key using the options specified on this page. If you're using OpenAI models, ensure that the OpenAI API key is set up as well.

Call chat with ChatMessage List

Step 1: Import Modules and Classes

from llama_index.llms import Konko
from llama_index.llms.base import ChatMessage

Step 2: Selecting and Calling a Model

First, find a model that suits your needs on the Available Models. For demonstration purposes, we'll use the LLama 2 model. The model ID for this would be: "meta-llama/Llama-2-13b-chat".

To view the list of models available on your Konko instance, check this endpoint.

Now, initialize your model with the following code:

llm = Konko(model="meta-llama/llama-2-13b-chat")

Step 3: Sending a Message

To interact with the model, create a series of messages and pass them to the llm:

message = ChatMessage(role="user", content="Generate a Product Description for Apple Iphone 15")
response = llm.chat([message])


Sure, here's a product description for the Apple iPhone 15:

Introducing the latest and greatest from Apple - the iPhone 15! This sleek and powerful device is the perfect combination of form and function, with a stunning design that's sure to turn heads.

With a 6.7-inch Super Retina XDR display, you'll enjoy an immersive viewing experience like never before. The bright and vibrant colors will make you feel like you're right in the midst of the action, whether you're watching a movie, playing a game, or browsing your favorite social media apps.

But it's not just about looks - the iPhone 15 is also a powerhouse of a device. With the latest A15 Bionic chip, you'll experience lightning-fast performance and efficient battery life that will keep you going all day long. Plus, with up to 16GB of RAM and 512GB of storage, you'll have all the space you need to store your favorite songs, photos, and apps.

The camera on the iPhone 15 is simply stunning, with a quad-camera setup that includes a 12MP main camera, a 12MP ultra-wide camera, a 12MP telephoto camera, and a time-of-flight camera. With features like night mode, portrait mode, and more, you'll be able to capture professional-quality photos and videos with ease.

And with the latest iOS 15 operating system, you'll have access to all the latest features and updates, including a redesigned Home screen, improved multitasking, and enhanced privacy and security features.

But that's not all - the iPhone 15 also features advanced biometric security, including Face ID and Touch ID, so you can protect your device and your personal information with just a glance or a touch. And with wireless charging and IP68 water and dust resistance, you can use your device with confidence, no matter where you are or what you're doing.

So why settle for an older, slower device when you can have the best of the best with the Apple iPhone 15? Upgrade to the latest and greatest today and experience the difference for yourself!

That's it! You've successfully sent a query to the Konko chat model and received a response.


message = ChatMessage(role="user", content="Tell me a story in 250 words")
resp = llm.stream_chat([message], max_tokens=1000)
for r in resp:
    print(r.delta, end="")

Call complete with Prompt

llm = Konko(model="numbersstation/nsql-llama-2-7b", max_tokens=100)
text = """CREATE TABLE stadium (
    stadium_id number,
    location text,
    name text,
    capacity number,
    highest number,
    lowest number,
    average number

    singer_id number,
    name text,
    country text,
    song_name text,
    song_release_year text,
    age number,
    is_male others

CREATE TABLE concert (
    concert_id number,
    concert_name text,
    theme text,
    stadium_id text,
    year text

CREATE TABLE singer_in_concert (
    concert_id number,
    singer_id text

-- Using valid SQLite, answer the following questions for the tables provided above.

-- What is the maximum capacity of stadiums ?

response = llm.complete(text)
llm = Konko(model="phind/phind-codellama-34b-v2", max_tokens=100)
text = """### System Prompt
You are an intelligent programming assistant.

### User Message
Implement a linked list in C++

### Assistant

resp = llm.stream_complete(text, max_tokens=1000)
for r in resp:
    print(r.delta, end="")

What’s Next