Quickstart

Step-by-step tutorial to generate text with the Konko API

Generate your first text response


Tutorial objective: generate a summary of the book "The Foundation" by Isaac Asimov using meta-llama/llama-2-13b via two methods:

  • Method #1: Konko AI's Python SDK
  • Method #2: HTTP

No prior knowledge about Konko AI required. Estimated time to follow along end-to-end is less than 5 minutes

🚧

To follow along you will need a Konko API key

Get your Konko API key here.

Method #1: Python SDK


Step #1: Access & SDK Installation

You must first follow the Setup Python SDK guide.

Step #2: Check Available Models for Use

Run the following Python commands to retrieve a simple list of available open source models and OpenAI models if you have enabled OpenAI on the API Keys page ➡️.

import konko

# Ensure your API key is set as an environment variable or via
konko.api_key = 'KONKO_API_KEY'

# Retrieve the IDs of all models hosted by Konko and recommended from OpenAI
models = konko.models.list()

for item in models.data:
  print(item.id)

Response

codellama/codellama-13b-instruct
codellama/codellama-34b
codellama/codellama-34b-instruct
codellama/codellama-34b-python
codellama/codellama-7b-instruct
meta-llama/llama-2-13b
meta-llama/llama-2-13b-chat
meta-llama/llama-2-70b
meta-llama/llama-2-70b-chat
...

Step #3: Generate Text Using an LLM

  1. Run the following Python commands to generate a completion from the Konko provided model: meta-llama/llama-2-13b
response = konko.completions.create(
	model="meta-llama/llama-2-13b",
  prompt="Summarize the Foundation by Isaac Asimov",
  max_tokens=500,
)

print(response)

Response

Completion(id='82c4fe31-4d48-487c-a409-1aedb2738ac3', 
           choices=[
  CompletionChoice
  (
    finish_reason=None,
    index=0, 
    logprobs=None,
    text='\nThe Foundation by Isaac Asimov is a science fiction novel that tells the story of a group of scientists who are trying to save humanity from extinction. The novel is set in the future, and it follows the story of Hari Seldon, a scientist who has developed a new field of study called psychohistory. Psychohistory is a way of predicting the future by studying the behavior of large groups of people.\nSeldon uses psychohistory to predict that the Galactic Empire will fall, and he creates a plan to save humanity from the chaos that will follow. The Foundation is a group of scientists who are working to preserve human knowledge and culture in the face of the Empire’s collapse.\nThe Foundation is a classic science fiction novel that is still relevant today. The novel explores themes of power, corruption, and the importance of knowledge. The Foundation is a must-read for any fan of science fiction.\nThe Foundation by Isaac Asimov is a science fiction novel that tells the story of a group of scientists who are trying to save humanity from extinction. The novel is set in the future, and it follows the story of Hari Seldon, a scientist who has developed a new field of study called psychohistory. Psychohistory is a way of predicting the future by studying the behavior of large groups of people.\nThe Foundation is a classic science fiction novel that is still relevant today. The novel explores themes of power, corruption, and the importance of knowledge. The Foundation is a must-read for any fan of science fiction. The Foundation by Isaac Asimov is a science fiction novel that tells the story of a group of scientists who are trying to save humanity from extinction. The novel is set in the future, and it follows the story of Hari Seldon, a scientist who has developed a new field of study called psychohistory. Psychohistory is a way of predicting the future by studying the behavior of large groups of people.\nThe Foundation is a classic science fiction novel that is still relevant today. The novel explores themes of power, corruption, and the importance of knowledge. The Foundation is a must-read for any fan of science fiction. The Foundation by Isaac Asimov is a science fiction novel that tells the story of a group of scientists who are trying'
  )
], 
           created=1704895437, 
           model='meta-llama/llama-2-13b', 
           object='text_completion', 
           system_fingerprint=None,
           usage=None
          )

Method #2: HTTP


You can recreate the above example in any common programming language by following the directions on our interactive API Reference ➡️.

Recommended Next Steps


Now that you've setup the Konko AI API and know the basics of how to generate text, we recommend you...

Read the Accessing Models guides to help you decide which LLMs to evaluate and how to construct optimal prompts for each model.


What’s Next