Introduction

The KOG library provides a comprehensive set of tools and functionalities for interacting with AI and machine learning models, particularly focusing on tasks such as natural language processing, document analysis, and interaction with large language models (LLMs). This documentation outlines the various components of the KOG library, including class definitions, function definitions, procedural calls, constants, and utility functions.

Prerequisites for Using the KOG Library

Before you can start using the Kognitos ensure that you have the following prerequisites:

  1. API Access: Depending on the functionalities you intend to use, you may need API access to services like OpenAI
  2. Basic Understanding of AI/ML Concepts: Familiarity with concepts such as tokens, models, and natural language processing will help you utilize the library more effectively..

Class Definitions

LLMRegions

The LLMRegions class defines the regions where the large language models are hosted.

LLMProviders

The LLMProviders class lists the available providers for large language models.

LLMFeatures

The LLMFeatures class outlines the features supported by the large language models.

LLMAttributes

The LLMAttributes class specifies the attributes of the large language models.


Function Definitions

_get_llm_region_and_provider

Retrieves the region and provider for a given large language model.

_get_model_with_version

Fetches the model along with its version.

get_model_with_version

Public function to get the model with its version.

_get_api_info

Retrieves API information for a given service.

_get_args_from

Extracts arguments from a given input.

get_secret

Fetches a secret from the secret management service.

openai_client

Initializes and returns an OpenAI client.

_get_openai_max_response_tokens

Calculates the maximum number of response tokens for OpenAI.

get_gpt_response

Fetches a response from GPT models.

num_tokens_from_images

Calculates the number of tokens from images.

extract_page_number

Extracts the page number from a document.

get_document_uri_and_pages

Retrieves the URI and pages of a document.

get_document_page_images

Fetches the images of document pages.

get_gpt_image_messages

Generates GPT messages from images.

num_tokens_from_messages

Calculates the number of tokens from messages.

read_jsons_from_result

Reads JSON objects from a result set.

extract_answers

Extracts answers from a given input.

get_openai_answers

Fetches answers from OpenAI.

verify_assertion_openai

Verifies an assertion using OpenAI.

extract_noun_from_sentence_openai

Extracts nouns from a sentence using OpenAI.

describe_thing

Generates a description of a given thing.

to_ask_koncierge

Asks a question to the Koncierge service.

to_find_a_thing_in_a_string

Finds a specific thing in a string.

to_ask_koncierge_for_a_documents_thing

Asks Koncierge for a specific thing in a document.

get_raw_document_text

Retrieves the raw text from a document.

get_invoices_gpt

Fetches invoices using GPT models.


Procedural Calls or Decorators

@procedure Decorator

The @procedure decorator is used to define procedural calls in the following functions:

  • to_ask_koncierge
  • to_find_a_thing_in_a_string
  • to_ask_koncierge_for_a_documents_thing

Constants and Data Structures

Token Constants

  • TOKEN_1K
  • TOKENS_4K
  • TOKENS_8K
  • TOKENS_16K
  • TOKENS_128K

Available LLMs

  • AVAILABLE_LLMS_OPENAI
  • DEFAULT_OPENAI_MODEL
  • KONCIERGE_MODEL_MAP_OPENAI
  • AVAILABLE_LLMS_AZURE
  • KONCIERGE_MODEL_MAP_AZURE

Utility Functions

get_secret

Fetches a secret from the secret management service.

openai_client

Initializes and returns an OpenAI client.

num_tokens_from_images

Calculates the number of tokens from images.

extract_page_number

Extracts the page number from a document.

get_document_uri_and_pages

Retrieves the URI and pages of a document.

get_document_page_images

Fetches the images of document pages.

get_gpt_image_messages

Generates GPT messages from images.

num_tokens_from_messages

Calculates the number of tokens from messages.

read_jsons_from_result

Reads JSON objects from a result set.

extract_answers

Extracts answers from a given input.

get_openai_answers

Fetches answers from OpenAI.

verify_assertion_openai

Verifies an assertion using OpenAI.

extract_noun_from_sentence_openai

Extracts nouns from a sentence using OpenAI.

describe_thing

Generates a description of a given thing.

get_raw_document_text

Retrieves the raw text from a document.

get_invoices_gpt

Fetches invoices using GPT models.


Glossary of Terms

  • API (Application Programming Interface): A set of rules and protocols for building and interacting with software applications. The KOG library uses APIs to communicate with services like OpenAI and Azure.
  • LLM (Large Language Model): A type of AI model designed to understand and generate human language. Examples include GPT-3 from OpenAI.
  • Token: A unit of text that the model processes. Tokens can be as short as one character or as long as one word.
  • Koncierge: A service within the Kognitos that handles specific queries and tasks.