Overview

Learn how to create completions from language and code models.

Creating a completion

Use client.completions.create to create a completion for a code or language models:

import os
from together import Together

client = Together(api_key=os.environ.get("TOGETHER_API_KEY"))

response = client.completions.create(
    model="codellama/CodeLlama-13b-Python-hf",
    prompt="def fibonacci(n): ",
    stream=True,
)

for chunk in response:
    print(chunk.choices[0].text or "", end="", flush=True)
import Together from 'together-ai';

const together = new Together({
  apiKey: process.env['TOGETHER_API_KEY'],
});

const response = await together.completions.create({
  model: "codellama/CodeLlama-13b-Python-hf",
  prompt: 'def bubbleSort(): ',
  stream: true
});

for chunk in response:
    console.log(chunk.choices[0].text)