Harbour using phind.com AI undocumented API

Harbour using phind.com AI undocumented API

Postby Antonio Linares » Fri Apr 21, 2023 2:54 pm

Thanks to Carlos Gallego, Charly, Cristobal, Giorgio, etc. we have been able to make it work from Harbour

This means that you can use the AI engine that http://www.phind.com provides without having to register and free.

This is the first working version. Next we will implement it as a dialogbox. This is great news as we want FWH to provide
a powerfull autoGPT functionality from your apps... :-)

phind.prg
Code: Select all  Expand view
#include "FiveWin.ch"

function Main()

   local oHttp := CreateObject( "MSXML2.ServerXMLHTTP.6.0")
   local cUrl  := "https://www.phind.com/api/infer/creative"
   local cQuestion := "tell me a zen advice"
   local cLine, cAnswer := ""
   local hData := { ;
      "question"    => cQuestion,;
      "codeContext" => "",;
      "options"     => { ;
         "skill"    => "intermediate",;
         "date"     => "14/04/2023",;
         "language" => "en-GB",;
         "detailed" => 'False',;
         "creative" => 'True';
      } }  

   oHttp:SetTimeouts( 30000, 30000, 30000, 30000 )
   oHttp:Open( "POST" , cUrl , .F. )
   oHttp:SetRequestHeader( "Content-Type", "application/json" )
   oHttp:SetRequestHeader( "Accept","*/*" )
   oHttp:SetRequestHeader( "Accept-Language", "en-GB,en-US;q=0.9,en;q=0.8" )
   oHttp:SetRequestHeader( "Origin", "https://www.phind.com" )
   oHttp:SetRequestHeader( "Referer", "https://www.phind.com/search?q=Go+vs+Rust+vs+C%2B%2B&c=&source=searchbox&init=true" )
   oHttp:SetRequestHeader( "sec-ch-ua", '"Chromium";v="112", "Google Chrome";v="112",";Not A Brand";v="99"' )
   oHttp:SetRequestHeader( "sec-ch-ua-mobile", "?0" )
   oHttp:SetRequestHeader( "Connection", "keep-alive" )
   oHttp:SetRequestHeader( "sec-ch-ua-platform", "macOS" )
   oHttp:SetRequestHeader( "sec-fetch-dest", "empty" )
   oHttp:SetRequestHeader( "sec-fetch-mode", "cors" )
   oHttp:SetRequestHeader( "sec-fetch-site", "same-site" )
   oHttp:SetRequestHeader( "Cookie", "__cf_bm = " )
   oHttp:SetRequestHeader( "Cookie", "mp__mixpanel = " )

   oHttp:Send( hb_jsonEncode( hData, .T. ) )

   for each cLine in oHttp:responseText
      cAnswer += StrTran( cLine, Chr( 10 ), "" )
   next  

   cAnswer = StrTran( cAnswer, "data: ", "" )
   cAnswer = StrTran( cAnswer, "  ", " " )

   FW_memoEdit( cAnswer )

return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Re: Harbour using phind.com AI undocumented API

Postby cmsoft » Fri Apr 21, 2023 3:32 pm

Excelente!
User avatar
cmsoft
 
Posts: 1290
Joined: Wed Nov 16, 2005 9:14 pm
Location: Mercedes - Bs As. Argentina

Re: Harbour using phind.com AI undocumented API

Postby MarcoBoschi » Fri Apr 21, 2023 3:33 pm

8)
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: Harbour using phind.com AI undocumented API

Postby cmsoft » Fri Apr 21, 2023 3:37 pm

Lo probé con lenguaje en castellano (cambiando la pregunta) y funcionó muy bien.
oHttp:SetRequestHeader( "Accept-Language", "sp; q=0.9" )
User avatar
cmsoft
 
Posts: 1290
Joined: Wed Nov 16, 2005 9:14 pm
Location: Mercedes - Bs As. Argentina

Re: Harbour using phind.com AI undocumented API

Postby Antonio Linares » Fri Apr 21, 2023 4:59 pm

Versión mejorada con GUI, pero se nos cuela un espacio " " en la respuesta. Ayuda! :-)

Fijaros que en la respuesta DIALOGEX lo escribe como D IALOG EX, CAPTION como CAP TION y asi en otras palabras.

phind.prg
Code: Select all  Expand view
#include "FiveWin.ch"

#define IDC_TARGET_EDIT         1001
#define IDC_RESULT_EDIT         1002
#define IDC_INPUT_EDIT          1003
#define IDC_CONTINUE_BUTTON        1
#define IDC_END_BUTTON             2

function Main()

   local oDlg, cTarget := "write a Windows RC file with a dialog and two buttons", cResult := Space( 2000 )
   local oGet1, oGet2, oBtnOk

   DEFINE DIALOG oDlg RESOURCE "phind"

   REDEFINE GET oGet1 VAR cTarget MULTILINE ID IDC_TARGET_EDIT OF oDlg

   REDEFINE GET oGet2 VAR cResult MULTILINE ID IDC_RESULT_EDIT OF oDlg

   REDEFINE BUTTON oBtnOk ID 1 OF oDlg ;
      ACTION ( oBtnOk:Disable(), oGet2:SetText( Phind( AllTrim( cTarget ) ) ), oBtnOk:Enable() )

   ACTIVATE DIALOG oDlg CENTERED

return nil  

function Phind( cQuestion )

   local oHttp := CreateObject( "MSXML2.ServerXMLHTTP.6.0")
   local cUrl  := "https://www.phind.com/api/infer/creative"
   local cLine, cAnswer := ""
   local hData := { ;
      "question"    => cQuestion,;
      "codeContext" => "",;
      "options"     => { ;
         "skill"    => "intermediate",;
         "date"     => "14/04/2023",;
         "language" => "en-GB",;
         "detailed" => 'False',;
         "creative" => 'True';
      } }  

   oHttp:SetTimeouts( 30000, 30000, 30000, 30000 )
   oHttp:Open( "POST" , cUrl , .F. )
   oHttp:SetRequestHeader( "Content-Type", "application/json" )
   oHttp:SetRequestHeader( "Accept","*/*" )
   oHttp:SetRequestHeader( "Accept-Language", "en-GB,en-US;q=0.9,en;q=0.8" )
   oHttp:SetRequestHeader( "Origin", "https://www.phind.com" )
   oHttp:SetRequestHeader( "Referer", "https://www.phind.com/search?q=Go+vs+Rust+vs+C%2B%2B&c=&source=searchbox&init=true" )
   oHttp:SetRequestHeader( "sec-ch-ua", '"Chromium";v="112", "Google Chrome";v="112",";Not A Brand";v="99"' )
   oHttp:SetRequestHeader( "sec-ch-ua-mobile", "?0" )
   oHttp:SetRequestHeader( "Connection", "keep-alive" )
   oHttp:SetRequestHeader( "sec-ch-ua-platform", "macOS" )
   oHttp:SetRequestHeader( "sec-fetch-dest", "empty" )
   oHttp:SetRequestHeader( "sec-fetch-mode", "cors" )
   oHttp:SetRequestHeader( "sec-fetch-site", "same-site" )
   oHttp:SetRequestHeader( "Cookie", "__cf_bm = " )
   oHttp:SetRequestHeader( "Cookie", "mp__mixpanel = " )

   oHttp:Send( hb_jsonEncode( hData, .T. ) )

   for each cLine in oHttp:responseText
      cAnswer += cLine
   next  

   cAnswer = StrTran( cAnswer, "data:", "" )
   cAnswer = StrTran( cAnswer, CRLF + Chr( 13 ), "" )
   cAnswer = StrTran( cAnswer, "  ", " " )
   cAnswer = StrTran( cAnswer, " " + Chr( 10 ) + " ", " " )

return cAnswer


phind.rc
Code: Select all  Expand view
#define IDC_TARGET_EDIT         1001
#define IDC_RESULT_EDIT         1002
#define IDC_INPUT_EDIT          1003
#define IDC_CONTINUE_BUTTON        1
#define IDC_END_BUTTON             2

phind DIALOGEX 0, 0, 500, 340
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Phind"
FONT 12, "MS Shell Dlg"
BEGIN
    LTEXT           "Target:", IDC_STATIC, 20, 20, 100, 30, SS_CENTERIMAGE
    EDITTEXT        IDC_TARGET_EDIT, 70, 16, 380, 40, ES_AUTOHSCROLL
    LTEXT           "Result:", IDC_STATIC, 20, 90, 100, 30, SS_CENTERIMAGE
    EDITTEXT        IDC_RESULT_EDIT, 70, 86, 380, 120, ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | WS_VSCROLL
    LTEXT           "Input:", IDC_STATIC, 20, 230, 100, 30, SS_CENTERIMAGE
    EDITTEXT        IDC_INPUT_EDIT, 70, 226, 380, 40, ES_AUTOHSCROLL
    PUSHBUTTON      "Continue", IDC_CONTINUE_BUTTON, 310, 280, 80, 20, BS_PUSHBUTTON
    PUSHBUTTON      "End", IDC_END_BUTTON, 410, 280, 80, 20, BS_PUSHBUTTON
END


Image
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Harbour using phind.com AI undocumented API

Postby karinha » Fri Apr 21, 2023 5:53 pm

Code: Select all  Expand view

#include "FiveWin.ch"

#define IDC_TARGET_EDIT         1001
#define IDC_RESULT_EDIT         1002
#define IDC_INPUT_EDIT          1003
#define IDC_CONTINUE_BUTTON        1
#define IDC_END_BUTTON             2

function Main()

   local oDlg, cTarget := "write a Windows RC file with a dialog and two buttons", cResult := Space( 2000 )
   local oGet1, oGet2, oBtnOk, oBtnEx

   DEFINE DIALOG oDlg RESOURCE "phind"

   REDEFINE GET oGet1 VAR cTarget MULTILINE ID IDC_TARGET_EDIT OF oDlg

   REDEFINE GET oGet2 VAR cResult MULTILINE ID IDC_RESULT_EDIT OF oDlg

   REDEFINE BUTTON oBtnOk ID 1 OF oDlg ;
      ACTION ( oBtnOk:Disable(), oGet2:SetText( Phind( AllTrim( cTarget ) ) ), ;
               oBtnOk:Enable() )

   REDEFINE BUTTON oBtnEx ID 2 OF oDlg ACTION( oDlg:End() )

   ACTIVATE DIALOG oDlg CENTERED

return nil  

function Phind( cQuestion )

   local oHttp := CreateObject( "MSXML2.ServerXMLHTTP.6.0")
   local cUrl  := "https://www.phind.com/api/infer/creative"
   local cLine, cAnswer := ""
   local hData := { ;
      "question"    => cQuestion,;
      "codeContext" => "",;
      "options"     => { ;
         "skill"    => "intermediate",;
         "date"     => "14/04/2023",;
         "language" => "en-GB",;
         "detailed" => 'False',;
         "creative" => 'True';
      } }  

   oHttp:SetTimeouts( 30000, 30000, 30000, 30000 )
   oHttp:Open( "POST" , cUrl , .F. )
   oHttp:SetRequestHeader( "Content-Type", "application/json" )
   oHttp:SetRequestHeader( "Accept","*/*" )
   // Como hago in Portuguese?
   oHttp:SetRequestHeader( "Accept-Language", "en-GB,en-US;q=0.9,en;q=0.8" )

   oHttp:SetRequestHeader( "Origin", "https://www.phind.com" )
   oHttp:SetRequestHeader( "Referer", "https://www.phind.com/search?q=Go+vs+Rust+vs+C%2B%2B&c=&source=searchbox&init=true" )
   oHttp:SetRequestHeader( "sec-ch-ua", '"Chromium";v="112", "Google Chrome";v="112",";Not A Brand";v="99"' )
   oHttp:SetRequestHeader( "sec-ch-ua-mobile", "?0" )
   oHttp:SetRequestHeader( "Connection", "keep-alive" )
   oHttp:SetRequestHeader( "sec-ch-ua-platform", "macOS" )
   oHttp:SetRequestHeader( "sec-fetch-dest", "empty" )
   oHttp:SetRequestHeader( "sec-fetch-mode", "cors" )
   oHttp:SetRequestHeader( "sec-fetch-site", "same-site" )
   oHttp:SetRequestHeader( "Cookie", "__cf_bm = " )
   oHttp:SetRequestHeader( "Cookie", "mp__mixpanel = " )

   oHttp:Send( hb_jsonEncode( hData, .T. ) )

   for each cLine in oHttp:responseText
      // cAnswer += cLine                                          r
      // cAnswer += StrTran( cLine, Chr( 10 )+chr(13), "" )
      cAnswer += StrTran( cLine, Chr( 10 )+chr(13) )
   next  

   cAnswer = StrTran( cAnswer, "data:", "" )
   cAnswer = StrTran( cAnswer, CRLF + Chr( 13 ), "" )
   cAnswer = StrTran( cAnswer, "  ", " " )
   cAnswer = StrTran( cAnswer, " " + Chr( 10 ) + " ", " " )

return cAnswer

/*
// PHIND.RC in WORKSHOP.exe
#define IDC_TARGET_EDIT         1001
#define IDC_RESULT_EDIT         1002
#define IDC_INPUT_EDIT          1003
#define IDC_CONTINUE_BUTTON        1
#define IDC_END_BUTTON             2

PHIND DIALOG -28, 56, 454, 340
STYLE DS_ABSALIGN | DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION
CAPTION "Phind"
FONT 12, "MS Shell Dlg"
{
 LTEXT "Target:", 4001, 20,20,100,30
 EDITTEXT IDC_TARGET_EDIT, 70, 16, 380, 40, ES_AUTOHSCROLL
 LTEXT "Result:", 4002, 20,90,100,30
 EDITTEXT IDC_RESULT_EDIT, 70, 86, 380, 120, ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | WS_VSCROLL
 LTEXT "Input:", 4003, 20,230,100,30
 EDITTEXT IDC_INPUT_EDIT, 70, 226, 380, 40, ES_AUTOHSCROLL
 PUSHBUTTON "Continue", IDC_CONTINUE_BUTTON, 270, 280, 80, 20
 PUSHBUTTON "End", IDC_END_BUTTON, 370, 280, 80, 20
}
*/

 


Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7826
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Harbour using phind.com AI undocumented API

Postby Jimmy » Fri Apr 21, 2023 7:30 pm

hi,

which Compiler is to use for these Sample ?

i try buildh.bat MSVC and also BCC7 and got
error RC2104 : undefined keyword or key name: DS_SETFONT
error RC2104 : undefined keyword or key name: DS_ABSALIGN


---

forgot to say : 64 Bit :!:

now i switch to 32 Bit OS and it work with BCC7 32 Bit :D
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Harbour using phind.com AI undocumented API

Postby Jimmy » Fri Apr 21, 2023 11:00 pm

hi,

i have remove ES_AUTOHSCROLL in phind.RC

when have ES_AUTOHSCROLL it will NOT "wrap" Text so you can see Answer when not using Scrollbar
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Harbour using phind.com AI undocumented API

Postby Jimmy » Fri Apr 21, 2023 11:31 pm

hi,

when try to copy Result, via clipboard, from phind i go a line for each word :shock: ... how to fix it :?:
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Harbour using phind.com AI undocumented API

Postby Antonio Linares » Sat Apr 22, 2023 6:17 am

It seems as the unofficial API is temporarly down...

Now it returns HTML with <title>Just a moment...</title>

As soon as it gets fixed, we will post a modified version

thanks
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Harbour using phind.com AI undocumented API

Postby Jimmy » Thu Apr 27, 2023 12:21 am

Antonio Linares wrote:It seems as the unofficial API is temporarly down...

Now it returns HTML with <title>Just a moment...</title>


look at full "Answer"
Code: Select all  Expand view
PHIND( 108 ) cAnswer = E"\n\n\n Just a moment...\n \n \n \n \n \n \n\n\n\n
\n
\n \n
\n
\n \n
\n \n \n Enable JavaScript and cookies to continue\n \n
\n
\n \n
\n \n \n \n

we need to enable JavaScript ... but how :idea:

Antonio Linares wrote:As soon as it gets fixed, we will post a modified version

PLEASE
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Harbour using phind.com AI undocumented API

Postby Antonio Linares » Thu Apr 27, 2023 7:22 am

Dear Jimmy,

Please use the OpenAI API, using the Class TOpenAI() implemented here:

viewtopic.php?p=259193&sid=91f4ac9c0303891f0cf6027c9a08c066#p259193

phind does not provide an official API yet and it is constantly changing
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 89 guests