johnmaeda / SK-Recipes-LinkedIn-Course-1

Materials used for LinkedIn Course on Semantic Kernel in April 2023
19 stars 11 forks source link

.Net: PasswordString to string type error #2

Open adammikulis opened 9 months ago

adammikulis commented 9 months ago

When I run the first block of code in s1e1-kernel: `#!import ../config/Settings.cs

bool useAzureOpenAI = false;

await Settings.AskAzureEndpoint(useAzureOpenAI); await Settings.AskModel(useAzureOpenAI); await Settings.AskApiKey(useAzureOpenAI);`

I receive this error: Error: (95,26): error CS0029: Cannot implicitly convert type 'Microsoft.DotNet.Interactive.PasswordString' to 'string' (100,26): error CS0029: Cannot implicitly convert type 'Microsoft.DotNet.Interactive.PasswordString' to 'string' Error: (3,7): error CS0103: The name 'Settings' does not exist in the current context (4,7): error CS0103: The name 'Settings' does not exist in the current context (5,7): error CS0103: The name 'Settings' does not exist in the current context

This appears to be raised in Issue #3124 and addressed in PR #3158, if that helps. Thanks for the hard work, I'm going through your course now and it looks like I can find these resources in the main SK project to keep following along.

brendonparker commented 9 months ago

To work around this I edited the code in Settings.cs replacing InteractiveKernel.GetPasswordAsync InteractiveKernel.GetInputAsync

adammikulis commented 8 months ago

Thanks for identifying the source of the error, I made PR #3 to fix the implicit casting.

BSlap commented 7 months ago

Same problem here: `Error: (95,26): error CS0029: Cannot implicitly convert type 'Microsoft.DotNet.Interactive.PasswordString' to 'string'

(100,26): error CS0029: Cannot implicitly convert type 'Microsoft.DotNet.Interactive.PasswordString' to 'string'

Error: (3,7): error CS0103: The name 'Settings' does not exist in the current context (4,7): error CS0103: The name 'Settings' does not exist in the current context (5,7): error CS0103: The name 'Settings' does not exist in the current context`

I checked the Settings.cs file and it already mentions InteractiveKernel.GetInputAsync. Am running .NET 8.0

What to do?

adammikulis commented 7 months ago

Hey @BSlap, check out the small changes I did in PR #3.

You just have to explicitly cast the PasswordString and it will resolve the problem:

replace: apiKey = await InteractiveKernel.GetPasswordAsync("Please enter your Azure OpenAI API key");

with:

var passwordString = await InteractiveKernel.GetPasswordAsync("Please enter your Azure OpenAI API key");
apiKey = passwordString.ToString();

in Settings.cs. Also in s1e7-connectors/notebook.ipynb if you use that notebook.

Feel free to clone my branch if that's easier: https://github.com/adammikulis/SK-Recipes-LinkedIn-Course-1/tree/fix-getpasswordasync-error

walkerpauldavid commented 1 month ago

Thanks @adammikulis very helpful but I'm getting these errors from VS Code when trying to run s1e1-kernel/notebook.ipynb

[{ "resource": "/c:/Users/.../Documents/GitHub/SK-Recipes-LinkedIn-Course-1/s1e1-kernel/notebook.ipynb", "owner": "_generated_diagnostic_collectionname#7", "severity": 8, "message": "The name 'Settings' does not exist in the current context", "startLineNumber": 5, "startColumn": 7, "endLineNumber": 5, "endColumn": 15 }]

[{ "resource": "/c:/Users/..../Documents/GitHub/SK-Recipes-LinkedIn-Course-1/s1e1-kernel/notebook.ipynb", "owner": "_generated_diagnostic_collectionname#7", "severity": 8, "message": "Cannot implicitly convert type 'Microsoft.DotNet.Interactive.PasswordString' to 'string'", "startLineNumber": 95, "startColumn": 26, "endLineNumber": 95, "endColumn": 108 }]