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

Skip to content

Commit 0e21703

Browse files
adds examples to openai python readme (openai#55)
1 parent b39bddd commit 0e21703

File tree

1 file changed

+52
-1
lines changed

1 file changed

+52
-1
lines changed

README.md

+52-1
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,65 @@ This library additionally provides an `openai` command-line utility
5858
which makes it easy to interact with the API from your terminal. Run
5959
`openai api -h` for usage.
6060

61-
```
61+
```sh
6262
# list engines
6363
openai api engines.list
6464

6565
# create a completion
6666
openai api completions.create -e ada -p "Hello world"
6767
```
6868

69+
## Example code
70+
71+
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).
72+
73+
### Embeddings
74+
75+
In the OpenAI Python library, an embedding represents a text string as a fixed-length vector of floating point numbers. Embeddings are designed to measure the similarity or relevance between text strings.
76+
77+
To get an embedding for a text string, you can use the embeddings method as follows in Python:
78+
79+
```python
80+
import openai
81+
openai.api_key = "sk-..." # supply your API key however you choose
82+
83+
# choose text to embed
84+
text_string = "sample text"
85+
86+
# choose an embedding
87+
model_id = "davinci-similarity"
88+
89+
# compute the embedding of the text
90+
embedding = openai.Engine(id=model_id).embeddings(input=text_string)['data'][0]['embedding']
91+
```
92+
93+
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).
94+
95+
Examples of how to use embeddings are shared in the following Jupyter notebooks:
96+
97+
- [Classification using embeddings](https://github.com/openai/openai-python/blob/main/examples/embeddings/Classification.ipynb)
98+
- [Clustering using embeddings](https://github.com/openai/openai-python/blob/main/examples/embeddings/Clustering.ipynb)
99+
- [Code search using embeddings](https://github.com/openai/openai-python/blob/main/examples/embeddings/Code_search.ipynb)
100+
- [Semantic text search using embeddings](https://github.com/openai/openai-python/blob/main/examples/embeddings/Semantic_text_search_using_embeddings.ipynb)
101+
- [User and product embeddings](https://github.com/openai/openai-python/blob/main/examples/embeddings/User_and_product_embeddings.ipynb)
102+
- [Zero-shot classification using embeddings](https://github.com/openai/openai-python/blob/main/examples/embeddings/Zero-shot_classification.ipynb)
103+
104+
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.
105+
106+
### Fine tuning
107+
108+
Fine tuning a model on training data can both improve the results (by giving the model more examples to learn from) and reduce the cost & latency of API calls (by reducing the need to include training examples in prompts).
109+
110+
Examples of fine tuning are shared in the following Jupyter notebooks:
111+
112+
- [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)
113+
- Fine tuning a model that answers questions about the 2020 Olympics
114+
- [Step 1: Collecting data](https://github.com/openai/openai-python/blob/main/examples/finetuning/olympics-1-collect-data.ipynb)
115+
- [Step 2: Creating a synthetic Q&A dataset](https://github.com/openai/openai-python/blob/main/examples/finetuning/olympics-2-create-qa.ipynb)
116+
- [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)
117+
118+
For more information on fine tuning, read the [fine-tuning guide](https://beta.openai.com/docs/guides/fine-tuning) in the OpenAI documentation.
119+
69120
## Requirements
70121

71122
- Python 3.7.1+

0 commit comments

Comments
 (0)