MacOS install
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py
/Library/Developer/CommandLineTools/usr/bin/python3 -m pip install --upgrade pip
echo "export PATH=\$PATH:~/Library/Python/3.9/bin" > > ~/.zshrc
echo "export OPENAI_ORGANIZATION=org-xxxxx" > > ~/.zshrc
echo "export OPENAI_API_KEY=sk-yyyyy" > > ~/.zshrc
source ~/.zshrc
pip install openai
pip install urllib3==1.26.6
Usage
API Keys
Playground
Examples
Models
Price
Prompt engineering techniques
InstructGPT
This family of models can understand and generate a lot of natural language tasks. It includes several models: text-ada-001, text-babbage-001, text-curie-001, and text-DaVinci-003. Ada is only capable of simple completion tasks but is also the fastest and cheapest model in the GPT-3 series. Both babbage and curie are a little more powerful but also more expensive. DaVinci can perform all completion tasks with excellent quality, but it is also the most expensive model in the family of GPT-3 models.
ChatGPT
The model behind ChatGPT is gpt-3.5-turbo. It is a chat model; as such, it can take a series of messages as input and return an appropriately generated message as output. While the chat format of gpt-3.5-turbo is designed to facilitate multi-turn conversations, it is also possible to use it for single-turn tasks without conversation. In single-turn tasks, the performance of gpt-3.5-turbo is comparable to text-DaVinci-003, and since gpt-3.5-turbo is one-tenth the price, with more or less equivalent performance, it is recommended to use it by default also for single-turn tasks.
messages:
system message helps set the behavior of the assistant.
user messages are the equivalent of a user typing a question or sentence in the ChatGPT web interface. They can be generated by the users of the application or set as an instruction.
assistant messages have two roles: either store prior responses to continue the conversation or can be set as an instruction to give examples of desired behavior. Models do not have any memory of past requests, so storing prior messages is necessary to give context to the conversation and provide all relevant information.
Price
The DaVinci model is x10 times the cost of GPT-3.5 Turbo. We recommend using DaVinci only if you wish to do some fine-tuning.
Tips:
1. Thinking Step by Step
adding "Let's think step by step" to the prompt, the model has empirically proven itself capable of solving more complicated reasoning problems. This technique also called the Zero-shot-CoT strategy
2. Few-shot learning
refers to the ability of the large language model to generalize and produce valuable results with only a few examples in the prompt, Then, in the last line, we provide the prompt for which we want a completion.
3. One-shot learing
provide only one example to help the model to understand the task. The advantages of one-shot learning are simplicity, faster prompt generation, and lower computational cost.
4. prompt with context and task
"Context: xxxxxx"
"Task: yyyyyy" e.g. Grammar correction, Summarize for a 2nd grader, TL;DR summarization, Python to natural language, Calculate Time Complexity, Python bug fixer, SQL request, Analogy maker, Notes to summary
5. Fine-tuning VS Few-shot learing
Fine-tuning produces a highly specialized model that can provide more accurate and contextually relevant results for a given task.
Few-shot learning allows developers to quickly prototype and experiment with various tasks, making it a versatile and practical option for many use cases.
6. fine tuning
pip install pandas
openai tools fine_tunes.prepare_data -f test.jsonl
{"prompt": "", "completion": ""}
{"prompt": "", "completion": ""}
{"prompt": "", "completion": ""}
...
example:
{"prompt": "Review the following Python code: 'def sum(a, b): return a + b\nresult = sum(5, '5')'", "completion": "Type error: The 'sum' function is adding an integer and a string. Consider converting the string to an integer using int() before passing it to the function."}
% openai api fine_tunes.create -t "test_prepared.jsonl"
Upload progress: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████| 570/570 [00:00<00:00, 345kit/s]
Uploaded file from test_prepared.jsonl: file-VtyCiUlG7G5o5UiKmawq7bMN
Created fine-tune: ft-cMOy6aV3KwexUv9RmbBUfOwQ
Streaming events until fine-tuning is complete...
(Ctrl-C will interrupt the stream, but not cancel the fine-tune)
[2023-06-12 16:59:27] Created fine-tune: ft-cMOy6aV3KwexUv9RmbBUfOwQ
Stream interrupted (client disconnected).
To resume the stream, run:
openai api fine_tunes.follow -i ft-cMOy6aV3KwexUv9RmbBUfOwQ
% openai api fine_tunes.follow -i ft-cMOy6aV3KwexUv9RmbBUfOwQ
[2023-06-12 16:59:27] Created fine-tune: ft-cMOy6aV3KwexUv9RmbBUfOwQ
[2023-06-12 17:00:47] Fine-tune costs $0.00
[2023-06-12 17:00:47] Fine-tune enqueued. Queue number: 0
[2023-06-12 17:00:49] Fine-tune started
[2023-06-12 17:01:51] Completed epoch 1/4
[2023-06-12 17:01:52] Completed epoch 2/4
[2023-06-12 17:01:52] Completed epoch 3/4
[2023-06-12 17:01:53] Completed epoch 4/4
[2023-06-12 17:02:10] Uploaded model: curie:ft-personal-2023-06-12-08-02-10
[2023-06-12 17:02:11] Uploaded result file: file-kMj1j7ODxnwqzwbKwyL466Qe
[2023-06-12 17:02:11] Fine-tune succeeded
Job complete! Status: succeeded 🎉
Try out your fine-tuned model:
openai api completions.create -m curie:ft-personal-2023-06-12-08-02-10 -p < YOUR_PROMPT >