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).
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.
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:
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.
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.
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?
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.
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.
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.