Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7884a7b

Browse files
Ted/move examples to openai cookbook (#112)
* removes examples (which can now be found in the OpenAI Cookbook repo) * Update numpy requirements due to vuln in 1.21.6 * adds api_type to ErrorObject * formats by Black
1 parent a7e3edf commit 7884a7b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+338
-39225
lines changed

README.md

+28-16
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ print(completion.choices[0].text)
5454

5555
### Microsoft Azure Endpoints
5656

57-
In order to use the library with Microsoft Azure endpoints, you need to set the api_type, api_base and api_version in addition to the api_key. The api_type must be set to 'azure' and the others correspond to the properites of your endpoint.
57+
In order to use the library with Microsoft Azure endpoints, you need to set the api_type, api_base and api_version in addition to the api_key. The api_type must be set to 'azure' and the others correspond to the properties of your endpoint.
5858
In addition, the deployment name must be passed as the engine parameter.
5959

6060
```python
@@ -78,8 +78,9 @@ print(search)
7878
```
7979

8080
Please note that for the moment, the Microsoft Azure endpoints can only be used for completion, search and fine-tuning operations.
81-
For a detailed example on how to use fine-tuning and other operations using Azure endpoints, please check out the following Jupyter notebook:
82-
[Using Azure fine-tuning](https://github.com/openai/openai-python/blob/main/examples/azure/finetuning.ipynb)
81+
For a detailed example on how to use fine-tuning and other operations using Azure endpoints, please check out the following Jupyter notebooks:
82+
* [Using Azure fine-tuning](https://github.com/openai/openai-cookbook/tree/main/examples/azure/finetuning.ipynb)
83+
* [Using Azure embeddings](https://github.com/openai/openai-cookbook/blob/main/examples/azure/embeddings.ipynb)
8384

8485
### Microsoft Azure Active Directory Authentication
8586

@@ -118,7 +119,18 @@ openai api completions.create -e ada -p "Hello world"
118119

119120
## Example code
120121

121-
Examples of how to use [embeddings](https://github.com/openai/openai-python/tree/main/examples/embeddings), [fine tuning](https://github.com/openai/openai-python/tree/main/examples/finetuning), [semantic search](https://github.com/openai/openai-python/tree/main/examples/semanticsearch), and [codex](https://github.com/openai/openai-python/tree/main/examples/codex) can be found in the [examples folder](https://github.com/openai/openai-python/tree/main/examples).
122+
Examples of how to use this Python library to accomplish various tasks can be found in the [OpenAI Cookbook](https://github.com/openai/openai-cookbook/). It contains code examples for:
123+
124+
* Classification using fine-tuning
125+
* Clustering
126+
* Code search
127+
* Customizing embeddings
128+
* Question answering from a corpus of documents
129+
* Recommendations
130+
* Visualization of embeddings
131+
* And more
132+
133+
Prior to July 2022, this OpenAI Python library hosted code examples in its examples folder, but since then all examples have been migrated to the [OpenAI Cookbook](https://github.com/openai/openai-cookbook/).
122134

123135
### Embeddings
124136

@@ -140,17 +152,17 @@ model_id = "text-similarity-davinci-001"
140152
embedding = openai.Embedding.create(input=text_string, engine=model_id)['data'][0]['embedding']
141153
```
142154

143-
An example of how to call the embeddings method is shown in the [get embeddings notebook](https://github.com/openai/openai-python/blob/main/examples/embeddings/Get_embeddings.ipynb).
155+
An example of how to call the embeddings method is shown in this [get embeddings notebook](https://github.com/openai/openai-cookbook/blob/main/examples/Get_embeddings.ipynb).
144156

145157
Examples of how to use embeddings are shared in the following Jupyter notebooks:
146158

147-
- [Classification using embeddings](https://github.com/openai/openai-python/blob/main/examples/embeddings/Classification.ipynb)
148-
- [Clustering using embeddings](https://github.com/openai/openai-python/blob/main/examples/embeddings/Clustering.ipynb)
149-
- [Code search using embeddings](https://github.com/openai/openai-python/blob/main/examples/embeddings/Code_search.ipynb)
150-
- [Semantic text search using embeddings](https://github.com/openai/openai-python/blob/main/examples/embeddings/Semantic_text_search_using_embeddings.ipynb)
151-
- [User and product embeddings](https://github.com/openai/openai-python/blob/main/examples/embeddings/User_and_product_embeddings.ipynb)
152-
- [Zero-shot classification using embeddings](https://github.com/openai/openai-python/blob/main/examples/embeddings/Zero-shot_classification.ipynb)
153-
- [Recommendation using embeddings](https://github.com/openai/openai-python/blob/main/examples/embeddings/Recommendation.ipynb)
159+
- [Classification using embeddings](https://github.com/openai/openai-cookbook/blob/main/examples/Classification_using_embeddings.ipynb)
160+
- [Clustering using embeddings](https://github.com/openai/openai-cookbook/blob/main/examples/Clustering.ipynb)
161+
- [Code search using embeddings](https://github.com/openai/openai-cookbook/blob/main/examples/Code_search.ipynb)
162+
- [Semantic text search using embeddings](https://github.com/openai/openai-cookbook/blob/main/examples/Semantic_text_search_using_embeddings.ipynb)
163+
- [User and product embeddings](https://github.com/openai/openai-cookbook/blob/main/examples/User_and_product_embeddings.ipynb)
164+
- [Zero-shot classification using embeddings](https://github.com/openai/openai-cookbook/blob/main/examples/Zero-shot_classification_with_embeddings.ipynb)
165+
- [Recommendation using embeddings](https://github.com/openai/openai-cookbook/blob/main/examples/Recommendation_using_embeddings.ipynb)
154166

155167
For more information on embeddings and the types of embeddings OpenAI offers, read the [embeddings guide](https://beta.openai.com/docs/guides/embeddings) in the OpenAI documentation.
156168

@@ -160,11 +172,11 @@ Fine tuning a model on training data can both improve the results (by giving the
160172

161173
Examples of fine tuning are shared in the following Jupyter notebooks:
162174

163-
- [Classification with fine tuning](https://github.com/openai/openai-python/blob/main/examples/finetuning/finetuning-classification.ipynb) (a simple notebook that shows the steps required for fine tuning)
175+
- [Classification with fine tuning](https://github.com/openai/openai-cookbook/blob/main/examples/Fine-tuned_classification.ipynb) (a simple notebook that shows the steps required for fine tuning)
164176
- Fine tuning a model that answers questions about the 2020 Olympics
165-
- [Step 1: Collecting data](https://github.com/openai/openai-python/blob/main/examples/finetuning/olympics-1-collect-data.ipynb)
166-
- [Step 2: Creating a synthetic Q&A dataset](https://github.com/openai/openai-python/blob/main/examples/finetuning/olympics-2-create-qa.ipynb)
167-
- [Step 3: Train a fine-tuning model specialized for Q&A](https://github.com/openai/openai-python/blob/main/examples/finetuning/olympics-3-train-qa.ipynb)
177+
- [Step 1: Collecting data](https://github.com/openai/openai-cookbook/blob/main/examples/fine-tuned_qa/olympics-1-collect-data.ipynb)
178+
- [Step 2: Creating a synthetic Q&A dataset](https://github.com/openai/openai-cookbook/blob/main/examples/fine-tuned_qa/olympics-2-create-qa.ipynb)
179+
- [Step 3: Train a fine-tuning model specialized for Q&A](https://github.com/openai/openai-cookbook/blob/main/examples/fine-tuned_qa/olympics-3-train-qa.ipynb)
168180

169181
Sync your fine-tunes to [Weights & Biases](https://wandb.me/openai-docs) to track experiments, models, and datasets in your central dashboard with:
170182

examples/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Examples have moved to the [OpenAI Cookbook](https://github.com/openai/openai-cookbook/)
2+
3+
Looking for code examples? Visit the [OpenAI Cookbook](https://github.com/openai/openai-cookbook/), which shares examples of how to use the OpenAI Python library to accomplish common tasks.
4+
5+
Prior to July 2022, code examples were hosted in this examples folder; going forward, code examples will be hosted in the [OpenAI Cookbook](https://github.com/openai/openai-cookbook/).
6+
7+
This separation will help keep the [OpenAI Python library](https://github.com/openai/openai-python) simple and small, without extra files or dependencies.

examples/azure/embeddings.ipynb

+9-165
Original file line numberDiff line numberDiff line change
@@ -4,174 +4,13 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"source": [
7-
"# Azure embeddings example\n",
8-
"In this example we'll try to go over all operations for embeddings that can be done using the Azure endpoints. \\\n",
9-
"This example focuses on finetuning but touches on the majority of operations that are also available using the API. This example is meant to be a quick way of showing simple operations and is not meant as a tutorial."
10-
]
11-
},
12-
{
13-
"cell_type": "code",
14-
"execution_count": null,
15-
"metadata": {},
16-
"outputs": [],
17-
"source": [
18-
"import openai\n",
19-
"from openai import cli"
20-
]
21-
},
22-
{
23-
"cell_type": "markdown",
24-
"metadata": {},
25-
"source": [
26-
"## Setup\n",
27-
"In the following section the endpoint and key need to be set up of the next sections to work. \\\n",
28-
"Please go to https://portal.azure.com, find your resource and then under \"Resource Management\" -> \"Keys and Endpoints\" look for the \"Endpoint\" value and one of the Keys. They will act as api_base and api_key in the code below."
29-
]
30-
},
31-
{
32-
"cell_type": "code",
33-
"execution_count": null,
34-
"metadata": {},
35-
"outputs": [],
36-
"source": [
37-
"openai.api_key = '' # Please add your api key here\n",
38-
"openai.api_base = '' # Please add your endpoint here\n",
39-
"\n",
40-
"openai.api_type = 'azure'\n",
41-
"openai.api_version = '2022-03-01-preview' # this may change in the future"
42-
]
43-
},
44-
{
45-
"cell_type": "markdown",
46-
"metadata": {},
47-
"source": [
48-
"## Deployments\n",
49-
"In this section we are going to create a deployment using the finetune model that we just adapted and then used the deployment to create a simple completion operation."
50-
]
51-
},
52-
{
53-
"cell_type": "markdown",
54-
"metadata": {},
55-
"source": [
56-
"### Deployments: Create Manually\n",
57-
"Let's create a deployment using the text-similarity-curie-001 engine. You can create a new deployment by going to your Resource in your portal under \"Resource Management\" -> \"Deployments\"."
58-
]
59-
},
60-
{
61-
"cell_type": "markdown",
62-
"metadata": {},
63-
"source": [
64-
"### (Optional) Deployments: Create Programatically\n",
65-
"We can also create a deployment using code:"
66-
]
67-
},
68-
{
69-
"cell_type": "code",
70-
"execution_count": null,
71-
"metadata": {},
72-
"outputs": [],
73-
"source": [
74-
"model = \"text-similarity-curie-001\"\n",
75-
"\n",
76-
"# Now let's create the deployment\n",
77-
"print(f'Creating a new deployment with model: {model}')\n",
78-
"result = openai.Deployment.create(model=model, scale_settings={\"scale_type\":\"manual\", \"capacity\": 1})\n",
79-
"deployment_id = result[\"id\"]"
80-
]
81-
},
82-
{
83-
"cell_type": "markdown",
84-
"metadata": {},
85-
"source": [
86-
"### (Optional) Deployments: Retrieving\n",
87-
"Now let's check the status of the newly created deployment"
88-
]
89-
},
90-
{
91-
"cell_type": "code",
92-
"execution_count": null,
93-
"metadata": {},
94-
"outputs": [],
95-
"source": [
96-
"print(f'Checking for deployment status.')\n",
97-
"resp = openai.Deployment.retrieve(id=deployment_id)\n",
98-
"status = resp[\"status\"]\n",
99-
"print(f'Deployment {deployment_id} is with status: {status}')"
100-
]
101-
},
102-
{
103-
"cell_type": "markdown",
104-
"metadata": {},
105-
"source": [
106-
"### Deployments: Listing\n",
107-
"Now because creating a new deployment takes a long time, let's look in the subscription for an already finished deployment that succeeded."
108-
]
109-
},
110-
{
111-
"cell_type": "code",
112-
"execution_count": null,
113-
"metadata": {},
114-
"outputs": [],
115-
"source": [
116-
"print('While deployment running, selecting a completed one.')\n",
117-
"deployment_id = None\n",
118-
"result = openai.Deployment.list()\n",
119-
"for deployment in result.data:\n",
120-
" if deployment[\"status\"] == \"succeeded\":\n",
121-
" deployment_id = deployment[\"id\"]\n",
122-
" break\n",
123-
"\n",
124-
"if not deployment_id:\n",
125-
" print('No deployment with status: succeeded found.')\n",
126-
"else:\n",
127-
" print(f'Found a successful deployment with id: {deployment_id}.')"
128-
]
129-
},
130-
{
131-
"cell_type": "markdown",
132-
"metadata": {},
133-
"source": [
134-
"### Embeddings\n",
135-
"Now let's send a sample embedding to the deployment."
136-
]
137-
},
138-
{
139-
"cell_type": "code",
140-
"execution_count": null,
141-
"metadata": {},
142-
"outputs": [],
143-
"source": [
144-
"embeddings = openai.Embedding.create(deployment_id=deployment_id,\n",
145-
" input=\"The food was delicious and the waiter...\")\n",
146-
" \n",
147-
"print(embeddings)"
148-
]
149-
},
150-
{
151-
"cell_type": "markdown",
152-
"metadata": {},
153-
"source": [
154-
"### (Optional) Deployments: Delete\n",
155-
"Finally let's delete the deployment"
156-
]
157-
},
158-
{
159-
"cell_type": "code",
160-
"execution_count": null,
161-
"metadata": {},
162-
"outputs": [],
163-
"source": [
164-
"print(f'Deleting deployment: {deployment_id}')\n",
165-
"openai.Deployment.delete(sid=deployment_id)"
7+
"This code example has moved. You can now find it in the [OpenAI Cookbook](https://github.com/openai/openai-cookbook) at [examples/azure/embeddings.ipynb](https://github.com/openai/openai-cookbook/tree/main/examples/azure/embeddings.ipynb)."
1668
]
1679
}
16810
],
16911
"metadata": {
170-
"interpreter": {
171-
"hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
172-
},
17312
"kernelspec": {
174-
"display_name": "Python 3.8.10 64-bit",
13+
"display_name": "Python 3.9.9 ('openai')",
17514
"language": "python",
17615
"name": "python3"
17716
},
@@ -185,9 +24,14 @@
18524
"name": "python",
18625
"nbconvert_exporter": "python",
18726
"pygments_lexer": "ipython3",
188-
"version": "3.8.10"
27+
"version": "3.9.9"
18928
},
190-
"orig_nbformat": 4
29+
"orig_nbformat": 4,
30+
"vscode": {
31+
"interpreter": {
32+
"hash": "365536dcbde60510dc9073d6b991cd35db2d9bac356a11f5b64279a5e6708b97"
33+
}
34+
}
19135
},
19236
"nbformat": 4,
19337
"nbformat_minor": 2

0 commit comments

Comments
 (0)