Skip to content

Commit 449334d

Browse files
authored
Merge pull request #225529 from soferreira/patch-15
Add python code sample
2 parents 33b7032 + bae48e5 commit 449334d

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

articles/cognitive-services/openai/how-to/embeddings.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,31 @@ An embedding is a special format of data representation that can be easily utili
2222

2323
To obtain an embedding vector for a piece of text, we make a request to the embeddings endpoint as shown in the following code snippets:
2424

25+
# [console](#tab/console)
2526
```console
2627
curl https://YOUR_RESOURCE_NAME.openai.azure.com/openai/deployments/YOUR_DEPLOYMENT_NAME/embeddings?api-version=2022-12-01\
2728
-H 'Content-Type: application/json' \
2829
-H 'api-key: YOUR_API_KEY' \
2930
-d '{"input": "Sample Document goes here"}'
3031
```
3132

33+
# [python](#tab/python)
34+
```python
35+
import openai
36+
37+
openai.api_type = "azure"
38+
openai.api_key = YOUR_API_KEY
39+
openai.api_base = "https://YOUR_RESOURCE_NAME.openai.azure.com"
40+
openai.api_version = "2022-12-01"
41+
42+
response = openai.Embedding.create(
43+
input="Your text string goes here",
44+
engine="YOUR_DEPLOYMENT_NAME"
45+
)
46+
embeddings = response['data'][0]['embedding']
47+
```
48+
---
49+
3250
## Best Practices
3351

3452
### Verify inputs don't exceed the maximum length

0 commit comments

Comments
 (0)