2023-03-26 12:55:48 -07:00
# OpenAI Cookbook
2022-03-10 18:08:53 -08:00
2023-01-20 14:20:03 -08:00
The OpenAI Cookbook shares example code for accomplishing common tasks with the [OpenAI API].
2022-03-10 18:08:53 -08:00
2023-04-14 12:52:53 -07:00
To run these examples, you'll need an OpenAI account and API key ([create a free account][api signup]).
2022-03-10 18:08:53 -08:00
Most code examples are written in Python, though the concepts can be applied in any language.
2023-03-26 12:54:23 -07:00
[](https://github.com/codespaces/new?hide_repo_select=true& ref=main& repo=468576060& machine=basicLinux32gb& location=EastUs)
2023-05-19 16:54:54 -07:00
## Recently added/updated 🆕 ✨
2023-09-21 17:32:45 -07:00
2023-08-22 14:09:03 -07:00
- [How to fine-tune chat models ](https://github.com/openai/openai-cookbook/blob/main/examples/How_to_finetune_chat_models.ipynb ) [Aug 22, 2023]
2023-08-16 17:59:19 -07:00
- [How to evaluate abstractive summarization ](examples/evaluation/How_to_eval_abstractive_summarization.ipynb ) [Aug 16, 2023]
2023-06-27 14:24:26 -04:00
- [Whisper prompting guide ](examples/Whisper_prompting_guide.ipynb ) [June 27, 2023]
- [Question answering using a search API and re-ranking ](https://github.com/openai/openai-cookbook/blob/main/examples/Question_answering_using_a_search_API.ipynb ) [June 16, 2023]
- [How to call functions with Chat models ](https://github.com/openai/openai-cookbook/blob/main/examples/How_to_call_functions_with_chat_models.ipynb ) [June 13, 2023]
2023-02-14 10:33:59 -06:00
2023-01-20 14:20:03 -08:00
## Guides & examples
2023-02-11 16:37:34 -08:00
- API usage
- [How to handle rate limits ](examples/How_to_handle_rate_limits.ipynb )
- [Example parallel processing script that avoids hitting rate limits ](examples/api_request_parallel_processor.py )
- [How to count tokens with tiktoken ](examples/How_to_count_tokens_with_tiktoken.ipynb )
2023-04-14 12:52:53 -07:00
- GPT
2023-05-19 16:54:54 -07:00
- [How to format inputs to ChatGPT models ](examples/How_to_format_inputs_to_ChatGPT_models.ipynb )
- [How to stream completions ](examples/How_to_stream_completions.ipynb )
- [How to use a multi-step prompt to write unit tests ](examples/Unit_test_writing_using_a_multi-step_prompt.ipynb )
2023-02-11 16:37:34 -08:00
- [Guide: How to work with large language models ](how_to_work_with_large_language_models.md )
- [Guide: Techniques to improve reliability ](techniques_to_improve_reliability.md )
- Embeddings
- [Text comparison examples ](text_comparison_examples.md )
- [How to get embeddings ](examples/Get_embeddings.ipynb )
- [Question answering using embeddings ](examples/Question_answering_using_embeddings.ipynb )
2023-07-10 12:31:35 -07:00
- [Using vector databases for embeddings search ](examples/vector_databases )
2023-02-11 16:37:34 -08:00
- [Semantic search using embeddings ](examples/Semantic_text_search_using_embeddings.ipynb )
- [Recommendations using embeddings ](examples/Recommendation_using_embeddings.ipynb )
- [Clustering embeddings ](examples/Clustering.ipynb )
- [Visualizing embeddings in 2D ](examples/Visualizing_embeddings_in_2D.ipynb ) or [3D ](examples/Visualizing_embeddings_in_3D.ipynb )
- [Embedding long texts ](examples/Embedding_long_inputs.ipynb )
2023-05-22 14:23:23 -07:00
- [Embeddings playground (streamlit app) ](apps/embeddings-playground/README.md )
2023-06-29 10:46:24 -04:00
- [Search reranking with cross-encoders ](examples/Search_reranking_with_cross-encoders.ipynb )
2023-05-19 16:54:54 -07:00
- Apps
- [File Q&A ](apps/file-q-and-a/ )
- [Web Crawl Q&A ](apps/web-crawl-q-and-a )
- [Powering your products with ChatGPT and your own data ](apps/chatbot-kickstarter/powering_your_products_with_chatgpt_and_your_data.ipynb )
2023-02-11 16:37:34 -08:00
- Fine-tuning GPT-3
- [Guide: best practices for fine-tuning GPT-3 to classify text ](https://docs.google.com/document/d/1rqj7dkuvl7Byd5KQPUJRxc19BJt8wo0yHNwK84KfU3Q/edit )
- [Fine-tuned classification ](examples/Fine-tuned_classification.ipynb )
- DALL-E
2023-05-19 19:18:54 +01:00
- [How to generate and edit images with DALL·E ](examples/dalle/Image_generations_edits_and_variations_with_DALL-E.ipynb )
- [How to create dynamic masks with DALL·E and Segment Anything ](examples/dalle/How_to_create_dynamic_masks_with_DALL-E_and_Segment_Anything.ipynb )
2023-06-27 14:24:26 -04:00
- Whisper
- [Whisper prompting guide ](examples/Whisper_prompting_guide.ipynb )
2023-02-11 16:37:34 -08:00
- Azure OpenAI (alternative API from Microsoft Azure)
2023-03-28 22:25:34 +02:00
- [How to use ChatGPT with Azure OpenAI ](examples/azure/chat.ipynb )
2023-02-11 16:37:34 -08:00
- [How to get completions from Azure OpenAI ](examples/azure/completions.ipynb )
- [How to get embeddings from Azure OpenAI ](examples/azure/embeddings.ipynb )
2023-06-12 14:01:49 -07:00
- [How to generate images with DALL·E fom Azure OpenAI ](examples/azure/DALL-E.ipynb )
2022-03-10 18:08:53 -08:00
2023-05-22 21:30:51 -07:00
## Related OpenAI resources
2022-03-10 18:08:53 -08:00
2023-01-20 14:20:03 -08:00
Beyond the code examples here, you can learn about the [OpenAI API] from the following resources:
2022-03-10 18:08:53 -08:00
2023-04-14 12:52:53 -07:00
- Experiment with [ChatGPT]
2023-05-22 21:30:51 -07:00
- Try the API in the [OpenAI Playground]
2023-02-11 16:37:34 -08:00
- Read about the API in the [OpenAI Documentation]
2023-05-22 21:30:51 -07:00
- Get help in the [OpenAI Help Center]
- Discuss the API in the [OpenAI Community Forum] or [OpenAI Discord channel]
2023-02-11 16:37:34 -08:00
- See example prompts in the [OpenAI Examples]
2023-05-22 21:30:51 -07:00
- Stay updated with the [OpenAI Blog]
2022-03-10 18:08:53 -08:00
2023-01-20 14:20:03 -08:00
## Contributing
2022-08-02 17:43:49 -07:00
2023-05-22 21:30:51 -07:00
If there are examples or guides you'd like to see, feel free to suggest them on the [issues page]. We are also happy to accept high quality pull requests, as long as they fit the scope of the repo.
2022-08-02 17:43:49 -07:00
2023-02-11 16:37:34 -08:00
[chatgpt]: https://chat.openai.com/
[openai api]: https://openai.com/api/
[api signup]: https://beta.openai.com/signup
[openai playground]: https://beta.openai.com/playground
[openai documentation]: https://beta.openai.com/docs/introduction
[openai community forum]: https://community.openai.com/top?period=monthly
2023-05-22 21:30:51 -07:00
[openai discord channel]: https://discord.com/invite/openai
2023-02-11 16:37:34 -08:00
[openai help center]: https://help.openai.com/en/
[openai examples]: https://beta.openai.com/examples
[openai blog]: https://openai.com/blog/
2023-05-24 09:39:19 -07:00
[issues page]: https://github.com/openai/openai-cookbook/issues