Skip to content

Commit

Permalink
.Net: Issue-2839: Fixed .NET notebook '07-DALL-E-2' errors (microsoft…
Browse files Browse the repository at this point in the history
…#3065)

### Motivation and Context
Running the .NET notebook '07-DALL-E-2' using OpenAI had 2 errors
breaking the experience for new developers.

### Description

1. The configuration attempted to use the **chat** mode 'gpt-3.5-turbo'
but with a **Text** completion service. This was fixed by changing the
model to 'text-davinci-003' (as is stated in the description above the
code box anyway).

2. The embedding comparison code used an extension 'AsReadOnlySpan()'
which does not exist for a ReadOnlyMemory<float> which is what is
returned by the OpenAI Embedding Generation Service. Fix this by
changing it to just access the 'span' that already exists on the
ReadOnlyMemory<float>

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [X] The code builds clean without any errors or warnings
- [X] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [X] All unit tests pass, and I have added new tests where possible
- [X] I didn't break anyone 😄
  • Loading branch information
Roybott authored and SOE-YoungS committed Oct 31, 2023
1 parent 060a420 commit 7776107
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions dotnet/notebooks/07-DALL-E-2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@
"}\n",
"else\n",
"{\n",
" builder.WithOpenAITextEmbeddingGenerationService(\"text-embedding-ada-002\", orgId);\n",
" builder.WithOpenAITextCompletionService(\"gpt-3.5-turbo\", orgId);\n",
" builder.WithOpenAITextEmbeddingGenerationService(\"text-embedding-ada-002\", apiKey, orgId);\n",
" builder.WithOpenAITextCompletionService(\"text-davinci-003\", apiKey, orgId);\n",
" builder.WithOpenAIImageGenerationService(apiKey, orgId);\n",
"}\n",
" \n",
Expand Down Expand Up @@ -213,7 +213,7 @@
"// Compare user guess with real description and calculate score\n",
"var origEmbedding = await textEmbedding.GenerateEmbeddingsAsync(new List<string> { imageDescription.Result} );\n",
"var guessEmbedding = await textEmbedding.GenerateEmbeddingsAsync(new List<string> { guess } );\n",
"var similarity = origEmbedding.First().AsReadOnlySpan().CosineSimilarity(guessEmbedding.First().AsReadOnlySpan());\n",
"var similarity = origEmbedding.First().Span.CosineSimilarity(guessEmbedding.First().Span);\n",
"\n",
"Console.WriteLine($\"Your description:\\n{Utils.WordWrap(guess, 90)}\\n\");\n",
"Console.WriteLine($\"Real description:\\n{Utils.WordWrap(imageDescription.Result.Trim(), 90)}\\n\");\n",
Expand Down

0 comments on commit 7776107

Please sign in to comment.