File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed
Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -469,6 +469,54 @@ func main() {
469469```
470470</details >
471471
472+ <details >
473+ <summary >Azure OpenAI Embeddings</summary >
474+
475+ ``` go
476+ package main
477+
478+ import (
479+ " context"
480+ " fmt"
481+
482+ openai " github.com/sashabaranov/go-openai"
483+ )
484+
485+ func main () {
486+
487+ config := openai.DefaultAzureConfig (" your Azure OpenAI Key" , " https://your Azure OpenAI Endpoint" )
488+ config.APIVersion = " 2023-05-15" // optional update to latest API version
489+
490+ // If you use a deployment name different from the model name, you can customize the AzureModelMapperFunc function
491+ // config.AzureModelMapperFunc = func(model string) string {
492+ // azureModelMapping = map[string]string{
493+ // "gpt-3.5-turbo":"your gpt-3.5-turbo deployment name",
494+ // }
495+ // return azureModelMapping[model]
496+ // }
497+
498+ input := " Text to vectorize"
499+
500+ client := openai.NewClientWithConfig (config)
501+ resp , err := client.CreateEmbeddings (
502+ context.Background (),
503+ openai.EmbeddingRequest {
504+ Input: []string {input},
505+ Model: openai.AdaEmbeddingV2 ,
506+ })
507+
508+ if err != nil {
509+ fmt.Printf (" CreateEmbeddings error: %v \n " , err)
510+ return
511+ }
512+
513+ vectors := resp.Data [0 ].Embedding // []float32 with 1536 dimensions
514+
515+ fmt.Println (vectors[:10 ], " ..." , vectors[len (vectors)-10 :])
516+ }
517+ ```
518+ </details >
519+
472520<details >
473521<summary >Error handling</summary >
474522
You can’t perform that action at this time.
0 commit comments