Repository: sashabaranov/go-openai
Pull request #318 (2023-05-19 15:46:48)

Update README.md with Azure OpenAI Embeddings example
@sashabaranov I know there's an open PR with a more complex example for embeddings, but I think this gives a clear approach to anyone looking to implement embeddings quickly with Azure OpenAI

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/sashabaranov/go-openai/pull/318?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) Report
> Merging [#318](https://app.codecov.io/gh/sashabaranov/go-openai/pull/318?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (941cbfc) into [master](https://app.codecov.io/gh/sashabaranov/go-openai/commit/21eef5bc8dd8a919c487fffb17214c055396bfcd?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (21eef5b) will **not change** coverage.
> The diff coverage is `n/a`.

```diff
@@           Coverage Diff           @@
##           master     #318   +/-   ##
=======================================
  Coverage   92.41%   92.41%           
=======================================
  Files          21       21           
  Lines         659      659           
=======================================
  Hits          609      609           
  Misses         37       37           
  Partials       13       13           
```





Patch:
diff --git a/README.md b/README.md
index 994f26d..8e76c1a 100644
--- a/README.md
+++ b/README.md
@@ -3,7 +3,7 @@
 [![Go Report Card](https://goreportcard.com/badge/github.com/sashabaranov/go-openai)](https://goreportcard.com/report/github.com/sashabaranov/go-openai)
 [![codecov](https://codecov.io/gh/sashabaranov/go-openai/branch/master/graph/badge.svg?token=bCbIfHLIsW)](https://codecov.io/gh/sashabaranov/go-openai)
 
-This library provides Go clients for [OpenAI API](https://platform.openai.com/). We support:
+This library provides unofficial Go clients for [OpenAI API](https://platform.openai.com/). We support: 
 
 * ChatGPT
 * GPT-3, GPT-4
@@ -469,6 +469,54 @@ func main() {
 ```
 </details>
 
+<details>
+<summary>Azure OpenAI Embeddings</summary>
+
+```go
+package main
+
+import (
+	"context"
+	"fmt"
+
+	openai "github.com/sashabaranov/go-openai"
+)
+
+func main() {
+
+	config := openai.DefaultAzureConfig("your Azure OpenAI Key", "https://your Azure OpenAI Endpoint")
+	config.APIVersion = "2023-05-15" // optional update to latest API version
+
+	//If you use a deployment name different from the model name, you can customize the AzureModelMapperFunc function
+	//config.AzureModelMapperFunc = func(model string) string {
+	//    azureModelMapping = map[string]string{
+	//        "gpt-3.5-turbo":"your gpt-3.5-turbo deployment name",
+	//    }
+	//    return azureModelMapping[model]
+	//}
+
+	input := "Text to vectorize"
+
+	client := openai.NewClientWithConfig(config)
+	resp, err := client.CreateEmbeddings(
+		context.Background(),
+		openai.EmbeddingRequest{
+			Input: []string{input},
+			Model: openai.AdaEmbeddingV2,
+		})
+
+	if err != nil {
+		fmt.Printf("CreateEmbeddings error: %v\n", err)
+		return
+	}
+
+	vectors := resp.Data[0].Embedding // []float32 with 1536 dimensions
+
+	fmt.Println(vectors[:10], "...", vectors[len(vectors)-10:])
+}
+```
+</details>
+
 <details>
 <summary>Error handling</summary>
 
diff --git a/config.go b/config.go
index fbcf377..c58b71e 100644
--- a/config.go
+++ b/config.go
@@ -56,7 +56,7 @@ func DefaultAzureConfig(apiKey, baseURL string) ClientConfig {
 		BaseURL:    baseURL,
 		OrgID:      "",
 		APIType:    APITypeAzure,
-		APIVersion: "2023-03-15-preview",
+		APIVersion: "2023-05-15",
 		AzureModelMapperFunc: func(model string) string {
 			return regexp.MustCompile(`[.:]`).ReplaceAllString(model, "")
 		},


Test patch:
diff --git a/api_internal_test.go b/api_internal_test.go
index 529e7c7..214b627 100644
--- a/api_internal_test.go
+++ b/api_internal_test.go
@@ -122,7 +122,7 @@ func TestAzureFullURL(t *testing.T) {
 			"chatgpt-demo",
 			"https://httpbin.org/" +
 				"openai/deployments/chatgpt-demo" +
-				"/chat/completions?api-version=2023-03-15-preview",
+				"/chat/completions?api-version=2023-05-15",
 		},
 		{
 			"AzureBaseURLWithoutSlashOK",
@@ -131,7 +131,7 @@ func TestAzureFullURL(t *testing.T) {
 			"chatgpt-demo",
 			"https://httpbin.org/" +
 				"openai/deployments/chatgpt-demo" +
-				"/chat/completions?api-version=2023-03-15-preview",
+				"/chat/completions?api-version=2023-05-15",
 		},
 	}