By James Smith on Wednesday, 09 August 2023
Posted in General
Replies 16
Likes 0
Views 1K
Votes 0
Greetings, chatgpt client works fine with openai. Now I'm trying with my instance of azure. The endpoint changes to https://YOUR_RESOURCE_NAME.openai.azure.com/, which for experimentation, I changed the CS_OPENAI_URL_BASE (in sgcHTTP_API_OpenAI) constant to reflect.

So, tracing into TsgcHTTP_API_OpenAI_Base.DoHTTP_POST(), I'm thinking the request (including headers) is set up in a way that doesn't correspond to what azure specifically is expecting. When I run your example client, I get a 404. I verified the api key as generated (see attached shot).

This python example that msft provides is pretty simple: https://learn.microsoft.com/en-us/azure/ai-services/openai/quickstart?tabs=command-line&pivots=programming-language-python

Thanks for help,
James
Hello,

The chatgpt client works with the OpenAI API and most probably Azure requires some modifications, I'll check the documentation to see if can be implemented. I'll contact you again with more info.

Kind Regards,
Sergio
·
1 year ago
·
0 Likes
·
0 Votes
·
0 Comments
·
Hello,

According the documentation, Azure requires some modifications to send requests to the OpenAI API. I've added a couple of new properties to set the required parameters. Set first the provider to Azure (by default is set to OpenAI) and then fill the ResourceName and DeplymentId with your own values:


TsgcHTTP_API_OpenAI.OpenAIOptions.Provider := oapvAzure;
TsgcHTTP_API_OpenAI.OpenAIOptions.AzureOptions.ResourceName := '<your resource name>';
TsgcHTTP_API_OpenAI.OpenAIOptions.AzureOptions.DeploymentId := '<your deployment id>';


You can download the latest beta which includes these new properties. I've requested access to the Microsoft's Azure OpenAI Service, so I still can not test if this works or not, feel free to test with your account and let me know if works.

Kind Regards,
Sergio
·
1 year ago
·
0 Likes
·
0 Votes
·
0 Comments
·
You're awesome dude, thanks.

James
·
1 year ago
·
0 Likes
·
0 Votes
·
0 Comments
·
Greetings, compiling now. In fOpenAIChatGPT.pas line 206 I don't think you can inline proc calls like in FPC can you?

Thanks,
James
·
1 year ago
·
0 Likes
·
0 Votes
·
0 Comments
·
Sorry, I meant to say inline proc calls in FPC like you can in Delphi. I'll break those procs out and see if that compiles.
·
1 year ago
·
0 Likes
·
0 Votes
·
0 Comments
·
Had to do some surgery on it. Mainly break out anons to methods. The screwy part is CreateAnonymousThread isn't that usable in FPC yet because it takes a TProcedure and Synchronize takes a method. Compiles but I haven't tried it yet.
·
1 year ago
·
0 Likes
·
0 Votes
·
0 Comments
·
Hi,

Thanks for sharing with us!

Kind Regards,
Sergio
·
1 year ago
·
0 Likes
·
0 Votes
·
0 Comments
·
Sergio, sgcWebsocketsLazarus beta compiles on windows but not linux. See attached for error. And here's the issue in sgcver.inc line 724:

{$IFDEF MSWINDOWS}
{$DEFINE SGC_AI}
{$ENDIF}

Thanks,
James
·
1 year ago
·
0 Likes
·
0 Votes
·
0 Comments
·
Hi,

I've fixed the error compiling on Linux (the AI components are only supported on Windows), you can download the latest beta from your account.

Kind Regards,
Sergio
·
1 year ago
·
0 Likes
·
0 Votes
·
0 Comments
·
Sergio, your latest beta with ChatGPT example still has the anonymous funcs that FPC won't compile. I sent an alternative fOpenAIChatGPT.pas that will compile with FPC, but I don't think it's correct. Could you take a look when you get a chance?

Thanks,
James
·
1 year ago
·
0 Likes
·
0 Votes
·
0 Comments
·
Hi,

I am checking the modified fOpenAIChatGPT.pas and I see there are 5 Anonymous methods (Anon1, Anon2...), but I am sorry but I don't understand why are you synchronizing with the main thread because when the Anon1 method is called, this is called in the context of the main thread and the methods that make calls to the OpenAI api are blocking, so are waiting till the request is completed, so (I thinkd) there is no need to synchronize with the main thread. Probably there is something that I dont' see but could you give me a bit more info please? Thanks for your feedback, I really appreciate it.

Kind Regards,
Sergio
·
1 year ago
·
0 Likes
·
0 Votes
·
0 Comments
·
It may be a waste of time to get that code I sent working.

The issue is, the latest FPC version doesn't support anonymous function syntax in the Procedure (procedure()...) style (they say it will in next version not released yet). So if you try to compile your original ChatGPT example code from 2023.7 beta, it won't work. 2023.5.0 is fine, but it doesn't use anonymous procs in the btnSendClick method.

Thanks for help.
James
·
1 year ago
·
0 Likes
·
0 Votes
·
0 Comments
·
Hi,

Ok, I understand now. There is no need to use the anonymous function, so I've deleted all the calls to the anonymous methods. I think now it's more clear. Find attached the modified unit. Thanks for the feedback.

Kind Regards,
Sergio
·
1 year ago
·
0 Likes
·
0 Votes
·
0 Comments
·
Compiles fine, thanks. May need to check the openssl files. Getting a load error.

Thanks,
James
·
1 year ago
·
0 Likes
·
0 Votes
·
0 Comments
·
Hi,

Yes, the openssl libraries are required, thanks for the feedback.

Kind Regards,
Sergio
·
1 year ago
·
0 Likes
·
0 Votes
·
0 Comments
·
What Im saying is I get an open error, but the dlls are in the folder. So I may have an environment variable set in Windows.

Ill check a few things.

Thanks
James
·
1 year ago
·
0 Likes
·
0 Votes
·
0 Comments
·
View Full Post