Learning Generative AI
Make ChatGPT API As A More Programmable Interface
Have ChatGPT API be a more meaningful interface for developers
Published in
8 min readJun 8, 2023
In my previous share, we can understand the basics of ChatGPT API. In a simplified view, it looks like something below. A chatbot.
In this article, I will expand on how it can be more useful in producing developer-interested interfaces, which eventually turns it into something below
Pre-requisite
The blog here assumes you have set up your ChatGPT API Key as below
import openai
import os
from dotenv import load_dotenv, find_dotenv
_ = load_dotenv(find_dotenv())
openai.api_key = os.getenv('OPENAI_API_KEY')
And with two functions, one accepting a prompt
, and the other a full messages
def get_completion(prompt, model="gpt-3.5-turbo", temperature=0):
messages = [{"role": "user", "content": prompt}]…