0Pricing
NLP Academy · Aula

Chamando um LLM pelo Python

Envie prompts e interprete respostas.

Chamando um LLM pelo Python é uma aula grátis de NLP Academy no CoddyKit. Esta é a aula 2 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de NLP Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de NLP Academy inclui 4 aulas no total.

Partes desta aula ainda não foram traduzidas e aparecem em inglês.

Talk to a Model in Code

You do not run giant models on your laptop. Instead you send text to a hosted model over an API and get a reply back. 🌐

Install a Client

Most providers ship a Python client library so you can call the model with a few clean lines instead of raw HTTP.

pip install openai

Keep Your Key Secret

Calls are authenticated with an API key. Store it in an environment variable, never hard-coded in your source files.

import os
key = os.environ["OPENAI_API_KEY"]

Create the Client

You start by building a client object. It reads your key and handles the network details for every request you make.

from openai import OpenAI
client = OpenAI()

Messages, Not Just Text

Chat models take a list of messages, each tagged with a role like system, user, or assistant.

The System Role

A system message sets the model's behavior up front, like telling it to answer briefly or act as a helpful tutor.

Send Your Prompt

You put your question in a user message and send the whole list to the model in a single call.

resp = client.chat.completions.create(
  model="gpt-4o-mini",
  messages=[{"role": "user", "content": "Hi!"}])

Parse the Response

The reply is a structured object. The text you want sits inside the first choice, ready to read or store.

text = resp.choices[0].message.content
print(text)

Control With Temperature

The temperature setting controls randomness. Low values give steady answers; high values give more creative, varied ones.

Cap the Output

Setting max tokens limits how long the reply can be, which keeps responses tidy and your costs predictable.

Handle Failures

Networks fail and limits get hit, so wrap calls in try/except and retry gracefully when an error comes back.

Quick Check

Where do you find the model's text in a chat completion response?

Recap

Install a client, load your key from the environment, send role-tagged messages, then read the text from the first choice. ✅

Perguntas Frequentes

A aula “Chamando um LLM pelo Python” é grátis?

Sim — o texto completo de “Chamando um LLM pelo Python” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de NLP Academy, atualize para CoddyKit PRO. O curso de NLP Academy inclui 4 aulas no total.

O que vou aprender em “Chamando um LLM pelo Python”?

Envie prompts e interprete respostas. Você pratica NLP Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.

Preciso ter experiência prévia para começar NLP Academy?

Nenhuma experiência prévia é necessária. NLP Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 2 de 4.

Quanto tempo leva a aula “Chamando um LLM pelo Python”?

A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.

Posso escrever e executar código nesta aula de NLP Academy?

Sim. Cada aula de NLP Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.

Todas as aulas deste curso

  1. O que torna um modelo grande
  2. Chamando um LLM pelo Python
  3. Prompts zero-shot e few-shot
  4. Saída estruturada e barreiras de segurança
← Voltar para NLP Academy