Skip to content

evangriffiths/openai-sandbox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenAI sandbox

A repo for examples of and utils for using the openai python library.

Lessons from https://learn.deeplearning.ai/chatgpt-prompt-eng/

Setup

Create virtual env and install requirements:

python -m venv venv
source venv/bin/activate
pip install -r requirements.txt

API key

See api_key.py

What's this?

Basically examples of using openai.ChatCompletion.create on the gpt-3.5-turbo model to build applications:

  • that use natural language instead of code
  • that can use the powerful general-purpose functionality of LLMs

How does ChatGPT work in the context of this API?

It has a memory of the conversation so far (called 'context'), and uses that to generate the next response. This is built up as a list and passed to the ChatCompletion.create call to get the next reponse.

The 'system' role is used to give the model some context about how to behave. e.g. 'be a friendly chatbot!'

messages =  [  
    {'role':'system', 'content':'You are an assistant that speaks like Shakespeare.'},    
    {'role':'user', 'content':'tell me a joke'},   
    {'role':'assistant', 'content':'Why did the chicken cross the road'},   
    {'role':'user', 'content':'I don\'t know'},
]
openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=messages)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages