# Completion or Chat Models

## What is Completion

At its core, a text model is a sophisticated mathematical construct trained to perform a specific task: predicting the next token or character in a sequence. This process, known as completion, is a fundamental concept you will encounter frequently as you explore our API.

For instance, when utilizing the completion text model, such as `gpt-3.5-turbo-instruct`, you can provide an initial prompt to the model:

**Example Prompt:**

{% code overflow="wrap" %}

```bash
In a bustling city, a young inventor named Leo discovered a mysterious device that could:
```

{% endcode %}

Upon running the model, you might receive a response like this:

**Example Output:**

{% code overflow="wrap" %}

```bash
...transform everyday objects into extraordinary inventions. With a flick of a switch, Leo turned a simple bicycle into a flying machine, capturing the attention of everyone around him. As word spread, curious onlookers gathered, eager to see what else Leo could create with his newfound gadget.
```

{% endcode %}

This illustrates a basic text completion. However, as training datasets grow larger and are refined through human feedback, the results can become remarkably sophisticated, often exceeding initial expectations from researchers.

## What is a Chat Completion

To enhance the utility of text models in applications beyond generating arbitrary creative content, these models must be pretrained to return data in a specific format. Typically, interacting with a text model resembles a chat experience: you pose a question or request in a designated role, and the model responds as if it were another entity in a different role.

Model providers train their models using structured training data that includes metadata, such as roles. This training allows the model to respond in a specific format, making it suitable for a variety of complex applications.

**Example of Chat-like Interaction**

Consider the following training data structured as a conversation:

```bash
USER: What’s the capital of France?
ASSISTANT: The capital of France is Paris.

USER: Can you tell me more about its culture?
ASSISTANT: Paris is renowned for its art, fashion, and cuisine, making it a cultural hub in Europe.
```

This chat-like format is crucial for training, as the dataset consists of numerous such interactions. During training, the model learns the relationships between words and characters, enabling it to generate responses in a similar conversational style.

After generating data, a subsystem parses this information and returns it in a format that can be easily handled by your code, such as the following JSON:

```json
[
  { "message": "What’s the capital of France?", "role": "user" },
  { "message": "The capital of France is Paris.", "role": "assistant" }
]
```

This structured output allows developers to integrate chat functionalities seamlessly into their applications.

#### What Roles Exist?

In chat models, several roles are commonly utilized to structure interactions. Each role serves a specific purpose, enabling the model to generate contextually relevant responses. The primary roles include:

* **System**: This role provides the main instructions regarding formatting, rules, and behavior for the model. It typically appears once at the beginning of the interaction.
* **Assistant**: This role represents the model's responses to user queries. It generates the output based on the input received from the user.
* **User**: This role encompasses the content provided by the user. It includes questions, prompts, and any other input the user wishes to convey.
* **Tool**: This role is used for responses related to external tools or functionalities that the model can utilize, enhancing its capabilities.

By leveraging these roles, developers can create complex interactions and safeguard the AI from misleading or unproductive user inputs.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://kidjig.gitbook.io/kidjig-docs/api-provider/text-models-llm/completion-or-chat-models.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
