Skip to content

Commit

Permalink
Fix Azure embeddings model detection by passing string to fullURL (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
greysteil authored Jan 16, 2024
1 parent 09f6920 commit 4ce03a9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion embeddings.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func (c *Client) CreateEmbeddings(
conv EmbeddingRequestConverter,
) (res EmbeddingResponse, err error) {
baseReq := conv.Convert()
req, err := c.newRequest(ctx, http.MethodPost, c.fullURL("/embeddings", baseReq.Model), withBody(baseReq))
req, err := c.newRequest(ctx, http.MethodPost, c.fullURL("/embeddings", string(baseReq.Model)), withBody(baseReq))
if err != nil {
return
}
Expand Down
26 changes: 26 additions & 0 deletions embeddings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,32 @@ func TestEmbeddingEndpoint(t *testing.T) {
checks.HasError(t, err, "CreateEmbeddings error")
}

func TestAzureEmbeddingEndpoint(t *testing.T) {
client, server, teardown := setupAzureTestServer()
defer teardown()

sampleEmbeddings := []openai.Embedding{
{Embedding: []float32{1.23, 4.56, 7.89}},
{Embedding: []float32{-0.006968617, -0.0052718227, 0.011901081}},
}

server.RegisterHandler(
"/openai/deployments/text-embedding-ada-002/embeddings",
func(w http.ResponseWriter, r *http.Request) {
resBytes, _ := json.Marshal(openai.EmbeddingResponse{Data: sampleEmbeddings})
fmt.Fprintln(w, string(resBytes))
},
)
// test create embeddings with strings (simple embedding request)
res, err := client.CreateEmbeddings(context.Background(), openai.EmbeddingRequest{
Model: openai.AdaEmbeddingV2,
})
checks.NoError(t, err, "CreateEmbeddings error")
if !reflect.DeepEqual(res.Data, sampleEmbeddings) {
t.Errorf("Expected %#v embeddings, got %#v", sampleEmbeddings, res.Data)
}
}

func TestEmbeddingResponseBase64_ToEmbeddingResponse(t *testing.T) {
type fields struct {
Object string
Expand Down

0 comments on commit 4ce03a9

Please sign in to comment.