Best Of
Re: Using AzureOpenAIClient with LINQPadTokenCredential
So thank you again. That thread did help and I'm now up and running.
I now understand that there were a number of things I was not clear on:
As per the other thread I needed to add the https://login.microsoftonline.com/common/oauth2/nativeclient url to the redirect list under App Registrations / MyApp / Authentication (if you have no redirects you hit ADDSTS500113 - No reply address is registered). This matches the redirect in the request which I'm assuming is built by Util.MSAL?
I needed to pass in the clientID (for 'MyApp') in the Util.MSAL.AcquireTokenAsync call and without this I got the blank screen above with the AADSTS65002 error (via dev tools).
Once these two items were in place I was able to authenticate and get a token, but then hit a 401 PermissionDenied, so I went back to the Azure OpenAI resource and added "Cognitive Services OpenAI Contributor" and "Cognitive Services OpenAI User" in additiona to the "Cognitive Services Contributor" that I had previously added.
So below is my working final code (where I set the prompt to require consent each time....so I could see where I was).
Thanks again Joe and other thread for your help.
Best regards
John
void Main() { // Based on: // https://devblogs.microsoft.com/azure-sdk/announcing-the-stable-release-of-the-azure-openai-library-for-net/ string authEndPoint = Util.AzureCloud.PublicCloud.AuthenticationEndpoint; string tenantID = "<my-tenant-name"; string userHint = $"my-name@{tenantID}"; var azureOpenAiUri = new Uri("https://<my-openai-resource-endpoint>.openai.azure.com"); string clientID = Util.GetPassword("<my-app-registration-clientid>"); var credential = new LINQPadTokenCredential($"{authEndPoint}{tenantID}", userHint, clientID); AzureOpenAIClient azureClient = new(azureOpenAiUri, credential); ChatClient chatClient = azureClient.GetChatClient("<my-model-deployment-name>"); ChatCompletion completion = chatClient.CompleteChat( [ // System messages represent instructions or other guidance about how the assistant should behave new SystemChatMessage("You are a helpful assistant that talks like a pirate."), // User messages represent user input, whether historical or the most recent input new UserChatMessage("Hi, can you help me?"), // Assistant messages in a request represent conversation history for responses new AssistantChatMessage("Arrr! Of course, me hearty! What can I do for ye?"), new UserChatMessage("What's the best way to train a parrot?"), ]); Console.WriteLine($"{completion.Role}: {completion.Content[0].Text}"); completion.Dump(); } class LINQPadTokenCredential : TokenCredential { public readonly string Authority, UserIDHint, ClientID; public LINQPadTokenCredential(string authority, string userIDHint, string clientId) => (Authority, UserIDHint, ClientID) = (authority, userIDHint, clientId); public override AccessToken GetToken(TokenRequestContext requestContext, CancellationToken cancellationToken) => GetTokenAsync(requestContext, cancellationToken).Result; public override async ValueTask<AccessToken> GetTokenAsync(TokenRequestContext requestContext, CancellationToken cancelToken) { // Call LINQPad's AcquireTokenAsync method to authenticate interactively, and cache token in the LINQPad GUI. var auth = await Util.MSAL.AcquireTokenAsync(authority: Authority, scopes: requestContext.Scopes, userID: UserIDHint, prompt: Util.MSAL.Prompt.Consent, clientID: ClientID) .ConfigureAwait(false); this.Dump(); requestContext.Dump(); auth.Dump(); return new AccessToken(auth.AccessToken, auth.ExpiresOn); } }
"OpenAI returned HTTP error code TooManyRequests"
I have created and recreated APIs, trying both user API keys and the newer project API keys, and I aways get this error:
That's with the following settings
If I try another model besides gpt-3.5-turbo, I get the following error:
Here is my usage for the month... So if I'm understanding this correctly, there's no reason why I should be getting the error:
Re: Latest Stable LinqPad 5 - No Automatic Update
Yes - the LINQPad 5 betas don't automatically update.
Re: ChatGPT / AI Integration for LINQPad 5
This is unlikely - the priority ATM is with the macOS port. Also, the uptake on the last LINQPad 5 beta which had some backported features was really slow, to the point where it's difficult to safely RTM.
Re: Realtime result logging to a growing table
I believe this should be available in v5 but you could try dumping the table as an observable. I believe LINQPad handles rendering it more efficiently just adding the new rows for every entry to the existing table, instead of redrawing the entire table for every update. The 1000 row limit can be changed in the Preferences -> Results -> In Rich Text Mode.
If you want to implement an auto scroll, you could try what was done here, though I'm not sure if all functions would be available in that version. I believe it's using the old IE renderer as well, so you might have problems with the mutation observer and would have to scroll from the C# side.
Re: Request for LINQPad 8 Support for C# 13
I've just uploaded a new beta with support for the latest C# 13 features. There's also a demo of what's new in C# 13 in the inbuilt samples.
Re: Latest Stable LinqPad 5 - No Automatic Update
Unfortunately, there aren't many beta testers left on LINQPad 5, so there's not been sufficient feedback to safely RTM the preview. I found a couple of bugs just recently that were never reported. I've now uploaded the 5.51.03 beta which should fix those issues. It will be a few months, at least, though, before it can be considered for RTM.
Regarding version numbers, LINQPad jumped directly from 5.48 to 5.51. Version 5.5x signifies loss of support for .NET 4.6. The release notes are here:
https://www.linqpad.net/LINQPad5.aspx
Re: Feature Request: Support for Per-Monitor DPI Awareness in LINQPad 8
I second this, I have three monitors - one horizontal in the middle (main screen) and one vertical on each side. Dragging LINQPad from the middle monitor to one of the others makes everything go blurry. LINQPad is certainly not alone with this problem, but more and more apps handle this fine nowadays.
Re: Feature Request: Support for Per-Monitor DPI Awareness in LINQPad 8
This is likely to happen, but not immediately. LINQPad is a currently mix of WPF and WinForms code. The WinForms code is being progressively replaced by WPF code. Once it's 100% WPF, it should be possible to implement per-monitor DPI.
Feature Request: Support for Per-Monitor DPI Awareness in LINQPad 8
Hello LINQPad Team,
I'd like to request an enhancement for LINQPad 8 to support per-monitor DPI awareness. Currently, LINQPad 8 is confined to using the DPI setting of the primary monitor, which can lead to issues when using multiple monitors with different DPI settings.
Here are two screenshots demonstrating the issue:
Primary Monitor (High DPI) Screenshot(scale=150%): This screenshot shows LINQPad 8 on the primary monitor with a high DPI setting. The text and UI elements are correctly scaled and look sharp.
Secondary Monitor (Lower DPI) Screenshot(scale=250%): This screenshot shows LINQPad 8 on a secondary monitor with a even higher DPI setting. The text and UI elements appear blurry and improperly scaled, making it difficult to use effectively.
Supporting per-monitor DPI awareness would greatly improve the experience for users with multi-monitor setups having different DPI settings. This feature is becoming increasingly important with the growing prevalence of high-DPI displays.
Thank you for considering this enhancement. LINQPad is an excellent tool, and this improvement would make it even better for those of us who rely on multiple screens.
Best regards,