Delphi 7 Indy与API OpenAI chatGPT连接

ukqbszuj  于 2023-05-22  发布在  其他
关注(0)|答案(1)|浏览(268)

无法从 Delphi 7使用TidHTTP连接https://api.openai.com/v1/chat/completions
我在项目目录ssleay32.dll和libeay32.dll中,它们与其他项目一起测试
我得到一个错误:“连接SSL时出错”
用“ Postman ”我的令牌没有错误

function TAIform.message_send(JSONtext:String):String;
var idhttp1:Tidhttp;
    IdSSLIOHandlerSocket1:TIdSSLIOHandlerSocket;
    EnvStr : TStringStream;
begin

FError:='';
EnvStr := TStringStream.Create(JSONtext);

try

    idhttp1:=Tidhttp.Create(nil);
    IdSSLIOHandlerSocket1:=TIdSSLIOHandlerSocket.create(nil);
    idhttp1.IOHandler:=IdSSLIOHandlerSocket1;
    IdSSLIOHandlerSocket1.SSLOptions.Method:=sslvTLSv1_2;
    IdHTTP1.Request.CustomHeaders.Clear;
    IdHTTP1.Request.CustomHeaders.FoldLines := False;
    IdHTTP1.Request.CustomHeaders.Add('Content-Type: application/json ');
    IdHTTP1.Request.CustomHeaders.Add('Authorization: Bearer ' + FAIToken);  //Bearer
    IdHTTP1.Request.SetHeaders;
    IdHTTP1.Request.ContentType:='application/json';
    IdHTTP1.Request.Accept:='application/json';

    result:=ConvertFromUTF8(idhttp1.Post( FAIlink,EnvStr));  

 except
   on E: Exception do 
   begin
     FError:= 'Error: '+E.Message+#13#10+ConvertFromUTF8(idhttp1.ResponseError);
   end;
 end;

 EnvStr.free;
 IdSSLIOHandlerSocket1.free;
 idhttp1.free;

end;

我哪里错了?

u0sqgete

u0sqgete1#

在我的例子中,我用同样的代码在 Delphi 10中编写一个DLL并将其连接到Delphi 7项目更容易,这解决了这个问题。

相关问题