Skip to main content
LlamaIndex supports several features for text-to-text models. For instance, you can send a request with a chat history or get a streaming response.

Prerequisites

  1. Create an API key for authentication.
  2. Save the API key to an environment variable:
  3. Install LlamaIndex packages:

Prepare a script

  1. Copy the following part of the script:
  2. Add one of the following methods, depending on your use case:

Examples

Multi-message request

The script below adds a chat to the request and asks in the last message to write a poem:
The output is the following:

Prompt request with streaming output

The script below sends the prompt Amsterdam is the capital of and returns the output that is printed out word by word:
The output is the following: