Menu

Building a Simple LLM Application with Python

Building a Simple LLM Application with Python

LLMs can be accessed through APIs, hosted platforms, or locally running models. An application sends a prompt to the model and uses the response in a larger workflow.

The following example demonstrates a basic API-based integration using the OpenAI Python SDK.

Step 1: Install the SDK

pip install openai

Step 2: Configure Your API Key

Set your API key as an environment variable instead of placing it directly in source code.

For PowerShell:

$env:OPENAI_API_KEY = "your-api-key"

Replace the placeholder with your actual API key. Keep it private and do not commit it to source control.

Step 3: Send a Prompt to the Model

from openai import OpenAI

client = OpenAI()

response = client.responses.create(

model="gpt-5",

input=(

"Explain dependency injection in Angular "

"for a beginner. Give one short example."

)

)

print(response.output_text)

This example uses the OpenAI API. You need a valid API key and access to the specified model. If that model is unavailable to your account, replace it with a model identifier you can access.

Understanding the Workflow

  1. The application creates an API client.
  2. It sends an instruction to the model.
  3. The model generates a response.
  4. The application reads and displays the generated text.

Real applications should also handle API errors, timeouts, rate limits, costs, and sensitive information.

Where Can You Apply This?

The same pattern can support:

  • A coding assistant.
  • An email drafting tool.
  • A document summarizer.
  • A technical interview preparation application.
  • A chatbot that answers questions about supplied information.

A useful AI application requires more than a model call. It also needs a well-designed interface, suitable context, validation, and safeguards against incorrect outputs.


Artificial Intelligence Tutorial

VA

Vishalini A



Learn via Video Course

Artificial Intelligence and Machine Learning Course Logo

Artificial Intelligence and Machine Learning Course

55 hrs



Get in Touch For Details