1. A Deep Dive Into The GPT-4 And ChatGPT APIs :th...
# ai-reading-club
2. A Deep Dive Into The GPT-4 And ChatGPT APIs 🧵
Just noting that the api changed slightly since writing, here is an example of how to setup your API key and use chat completion
Copy code
from openai import OpenAI
client = OpenAI(
def summarize_text(user_prompt, system_prompt=None):

  response = client.chat.completions.create(
    {"role": "system",
     "content": system_prompt},
    {"role": "user",
     "content": user_prompt}

  prompt_and_response = {
      "prompt": user_prompt,
      "response": response.choices[0].message.content

  return prompt_and_response
^ I have a habit of logging both prompts and responses together.
Copy code
# prompt: use the function above to summarize some text

summary = summarize_text(test_prompt, instructions)
example text to try:
Copy code
# Set system prompt to change Summarization behavior
instructions = "Summarize this text. Use only 3 bullet points. explain like I'm 5 wordings "

# Spoiler alert for the first episode of DEVs
test_prompt = """The dominant sequence transduction models are based on complex recurrent or convolutional
 neural networks in an encoder-decoder configuration. The best performing models also connect the encoder
 and decoder through an attention mechanism. We propose a new simple network architecture, the Transformer,
 based solely on attention mechanisms, dispensing with recurrence and convolutions entirely. Experiments on
 two machine translation tasks show these models to be superior in quality while being more parallelizable
 and requiring significantly less time to train. Our model achieves 28.4 BLEU on the WMT 2014 English-to-German
 translation task, improving over the existing best results, including ensembles by over 2 BLEU. On the WMT 2014
 English-to-French translation task, our model establishes a new single-model state-of-the-art BLEU score of 41.8
 after training for 3.5 days on eight GPUs, a small fraction of the training costs of the best models from the
 literature. We show that the Transformer generalizes well to other tasks by applying it successfully to English
 constituency parsing both with large and limited training data.