H4 Tech Solutions Logo
All articles

OpenAI's GPT-3.5 API — Custom Assistant Integration with Python

Learn how to integrate OpenAI's GPT-3.5 API into custom Python applications for advanced AI solutions.

Feb 12, 2024 · 1 min read · Som

OpenAI's GPT-3.5 API — Custom Assistant Integration with Python

A custom assistant is mostly about giving GPT-3.5 the right system context and a clean interface into your app. The API call is small; the design around it is what makes the assistant useful.

A minimal integration

from openai import OpenAI

client = OpenAI()
resp = client.chat.completions.create(
    model="gpt-3.5-turbo",
    messages=[
        {"role": "system", "content": "You are a helpful support assistant."},
        {"role": "user", "content": user_input},
    ],
)
print(resp.choices[0].message.content)

Making it a real assistant

  • Persona & rules live in the system message.
  • Memory comes from replaying prior turns (trim to fit the context window).
  • Tools/data are injected as context or via function calling.

Takeaway

Keep the model call thin and put your effort into context, guardrails, and how the assistant plugs into the rest of your Python application.

Subscribe

Get new articles, white papers, and repos from H4Tech in your inbox.

Follow along via Subscribe via RSS