- Code: Select all Expand view
#include "FiveWin.ch"
#define EM_LIMITTEXT 197
Function Main()
LOCAL oDlg, oGet1, cVar1 := "Hola OpenAI, cómo estás ? Me llamo Carlos, tú tienes nombre ?"
LOCAL oGet2, cVar2 := Space(2048)
LOCAL oFont1, oFont2, oBtn1, oSay1, oSay2
LOCAL nChars := 2048
TBtnBmp():lLegacyLookLeftRight := .T.
cVar1 := "Puedes mostrarme el código de un programa escrito en lenguaje Harbour que en la function main tenga un Alert que diga 'Hola Mundo' ?"
DEFINE FONT oFont1 NAME "Verdana" SIZE 0,-12 BOLD
DEFINE FONT oFont2 NAME "Verdana" SIZE 0,-12
DEFINE DIALOG oDlg FROM 0,0 TO 39,107 TRUEPIXEL TITLE "Taking with OPENAI API"
@ 10,270 SAY "Talking with OPENAI API" OF oDlg FONT oFont1 SIZE 300,15PIXEL CENTER
@ 28,20 SAY "You:" OF oDlg FONT oFont1 SIZE 50,15 PIXEL
@ 28,680 SAY oSay1 VAR "Caracteres: 0 / "+cValToChar(nChars) OF oDlg PIXEL;
SIZE 120,15 UPDATE CENTER
@ 45,20 GET oGet1 VAR cVar1 OF oDlg PIXEL SIZE 800,200 MEMO FONT oFont2;
ON CHANGE(SB_LimitText(oGet1, oSay1, nChars))
oGet1:bGotfocus := {||oGet1:SetSel(0,0)}
@ 250,345 BTNBMP PROMPT "Submit" OF oDlg PIXEL ACTION Api_OpenAI(cVar1, oGet2) SIZE 150,45;
FILE "openai24x24.png" LEFT NOBORDER 2007
@ 300,20 SAY "OPENAI:" OF oDlg FONT oFont1 SIZE 70,15 PIXEL
@ 317,20 GET oGet2 VAR cVar2 OF oDlg PIXEL SIZE 800,200 MEMO FONT oFont2
oGet2:bGotfocus := {||oGet2:SetSel(0,0)}
@ 535,620 BTNBMP PROMPT "Close" OF oDlg PIXEL ACTION oDlg:End() SIZE 150,45;
FILE "exit24x24.png" LEFT NOBORDER 2007
oDlg:bInit := {|| oGet1:SetFocus(),;
oGet1:LimitText(nChars),;
oSay1:VarPut("Caracteres: " + cValToChar(LEN( ALLTRIM( oGet1:cText ) )) + " / " + cValToChar(nChars)),;
oSay1:Refresh()}
ACTIVATE DIALOG oDlg CENTERED ON PAINT oGet1:SetPos(0)
Return(NIL)
//------------------------------------------------------------//
Function Api_OpenAI(cPrompt, oGet2)
LOCAL oSoap := CreateObject( "MSXML2.ServerXMLHTTP.6.0")
LOCAL cUrl := "http://api.openai.com/v1/engines/text-davinci-003/completions"
// I have the key :-)
//LOCAL cToken := "sk-....."
LOCAL cJSon, cRespApi, hResp := {=>}, cResp
TEXT INTO cJson
{
"prompt": "cPrompt_empty",
"temperature": 0,
"max_tokens": 2048
}
ENDTEXT
cPrompt := AllTrim(cPrompt)
cJson := StrTran(cJson, "cPrompt_empty", cPrompt)
oSoap:SetTimeouts(30000,30000,30000,30000)
TRY
oSoap:Open( "POST" , cUrl , .F. )
oSoap:SetRequestHeader( "Content-Type", "application/json; charset=utf-8" )
oSoap:setRequestHeader("Authorization", "Bearer "+cToken )
oSoap:Send(cJson)
cRespApi := Alltrim(oSoap:responseText)
hb_jsondecode(cRespApi,@hResp)
cResp := hResp["choices"][1]["text"]
cResp := StrTran(cResp, Chr(10), Chr(13)+Chr(10))
oGet2:VarPut( AllTrim(cResp) )
oGet2:Refresh()
// MsgInfo( oSoap:Status )
CATCH
msginfo("Mensaje en el CATCH"+CRLF+CRLF+ "No hay conexión con el servidor de Rindegastos."+CRLF+ " Por favor vuelva a intentarlo.","Intente Nuevamente")
END
Return(oSoap)
//------------------------------------------------------------//
FUNCTION SB_LimitText( oGet, oSay, nLimObserv )
///////////////////////////////////////////////////////////////////////////
// Autor..........: Peguei no Forum FiveWin Brasil //
// Modificaçoes...: Ale SB - Soft Camus //
// Descricao......: Restringe o Tamanho de um Texto. //
// Parametros ==> //
// - oGet : oBjeto Get. //
// - nSize : Tamanho que deve ter o Texto. //
// Dependencias ==> //
// Retorno ==> nil //
///////////////////////////////////////////////////////////////////////////
LOCAL nTam, nSize
DEFAULT nSize := nLimObserv // 19 // 99 // maximo e 100 caracteres
nTam := LEN( ALLTRIM( oGet:cText ) )
IF nTam > nSize
Msginfo( "Lo siento, no puedo continuar, el tamaño máximo " + ;
"ha excedido el límite permitido.", "Atención por favor." )
oGet:cText := Substr(oGet:cText, 1, nTam-1)
RETURN( .F. )
ENDIF
oSay:VarPut("Caracteres: " + cValToChar(nTam) + " / " + cValToChar(nLimObserv))
oSay:Refresh()
RETURN( .T. )
//------------------------------------------------------------//
Error
- Code: Select all Expand view
Application
===========
Path and name: c:\sis\fsql901\visual\integrac\sisrev_api\chatgpt.exe (32 bits)
Size: 4,898,816 bytes
Compiler version: Harbour 3.2.0dev (r2008190002)
FiveWin version: FWH 22.12
C compiler version: Borland/Embarcadero C++ 7.0 (32-bit)
Windows 7 64 Bits, version: 6.1, Build 7601 Service Pack 1
Time from start: 0 hours 0 mins 3 secs
Error occurred at: 08/18/23, 09:37:40
Error description: (DOS Error -2147352567) WINOLE/1007 Erro no suporte a canais seguros
(0x80072F7D): msxml6.dll
Args:
[ 1] = C {
"prompt": "\r\ndon't include the words 'Bot:' 'chatGPT:' 'User:' in your answerola",
"temperature": 0,
"max_tokens": 2048
}
Stack Calls
===========
Called from: => TOLEAUTO:SEND( 0 )
Called from: chatgpt.prg => OPENAICALL( 163 )
Called from: chatgpt.prg => TOPENAI:ASK( 120 )
Called from: chatgpt.prg => (b)MAIN( 36 )
Called from: .\source\classes\BUTTON.PRG => TBUTTON:CLICK( 181 )
Called from: .\source\classes\CONTROL.PRG => TBUTTON:HANDLEEVENT( 1811 )
Called from: .\source\classes\WINDOW.PRG => _FWH( 3689 )
Called from: => SENDMESSAGE( 0 )
Called from: .\source\classes\DIALOG.PRG => TDIALOG:COMMAND( 500 )
Called from: => TWINDOW:HANDLEEVENT( 0 )
Called from: .\source\classes\DIALOG.PRG => TDIALOG:HANDLEEVENT( 1213 )
Called from: => DIALOGBOXINDIRECT( 0 )
Called from: .\source\classes\DIALOG.PRG => TDIALOG:ACTIVATE( 307 )
Called from: chatgpt.prg => MAIN( 84 )
System
======
CPU type: Intel(R) Core(TM) i5-4690T CPU @ 2.50GHz 2494 Mhz
Hardware memory: 8083 megs
Free System resources: 90 %
GDI resources: 90 %
User resources: 90 %
Windows total applications running: 4
1 ,
2 , C:\Windows\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82.7601.18837_none_ec86b
3 , c:\sis\fsql901\visual\integrac\sisrev_api\chatgpt.exe
4 GDI+ Window, C:\Windows\WinSxS\x86_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.7601.24542_none_5c0717c7a00ddc
Variables in use
================
Procedure Type Value
==========================
TOLEAUTO:SEND
Param 1: O Class: ERROR
OPENAICALL
Param 1: C " {
"prompt": "\r\ndon't include the words 'Bot:' 'chatGPT:' 'User:' in your answerola",
"temperature": 0,
"max_tokens": 2048
}
"
Local 1: U
Local 2: U
TOPENAI:ASK
Param 1: C "\r\ndon't include the words 'Bot:' 'chatGPT:' 'User:' in your answerola"
Param 2: C "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"
Param 3: N 0
Local 1: C "http://api.openai.com/v2/engines/text-davinci-003/completions"
Local 2: C " {
"prompt": "\r\ndon't include the words 'Bot:' 'chatGPT:' 'User:' in your answerola",
"temperature": 0,
"max_tokens": 2048
}
"
Local 3: H {=>}
Local 4: C ""
(b)MAIN
Param 1: C "ola"
Local 1: U
Local 2: C "\r\ndon't include the words 'Bot:' 'chatGPT:' 'User:' in your answerola"
Local 3: U
Local 4: S
Local 5: O Class: TOPENAI
Local 6: S
Local 7: U
TBUTTON:CLICK
Param 1: O Class: TBUTTON
Local 1: O Class: TMULTIGET
Local 2: S
TBUTTON:HANDLEEVENT
_FWH
Param 1: N 2048
Param 2: N 0
Param 3: N 0
Local 1: U
SENDMESSAGE
Param 1: N 0
Param 2: N 2048
Param 3: N 0
Param 4: N 0
Param 5: N 6
Local 1: O Class: TBUTTON
TDIALOG:COMMAND
Param 1: N 1049096
Param 2: N 2048
Param 3: N 0
Param 4: N 0
TWINDOW:HANDLEEVENT
Param 1: N 105
Param 2: N 1049096
Local 1: O Class: TBUTTON
Local 2: N 0
Local 3: N 105
Local 4: N 1049096
Local 5: U
TDIALOG:HANDLEEVENT
Param 1: N 273
Param 2: N 105
Param 3: N 1049096
DIALOGBOXINDIRECT
Param 1: N 273
Param 2: N 105
Param 3: N 1049096
TDIALOG:ACTIVATE
Param 1: N 4194304
Param 2: C "€ È€ Q' a u t o G P T w i t h O p e n A I P ¹ & e S T A T I C Q u e s t i o n P U f S T A T I C C h a r s : 0 ¡P ¹ ‘e g E D I T P R L h B U T T O N C l e a n c o n t e x t P ¨ L i B U T T O N S u b m i t P ý L j B U T T O N C o n t i n u e P ¹ ” # k S T A T I C R e s u l t ¡P ¹ ž ‘e l E D I T P & m S T A T I C C o n t e x t ¡P « í n T X B R O W S E P þ L o B U T T O N C l o s e P ú p S T A T I C S t r i c t P " q S T A T I C C r e a t i v e P j r T S L I D E R "
Param 3: N 0
Param 4: O Class: TDIALOG
MAIN
Param 1: U
Param 2: U
Param 3: B {|| ... }
Param 4: L .T.
Param 5: U
Param 6: L .T.
Param 7: U
Param 8: U
Param 9: U
Param 10: U
Param 11: U
Param 12: L .F.
Param 13: O Class: TDIALOG
Param 14: U
Local 1: N 0
Local 2: S
Local 3: O Class: TDIALOG
Linked RDDs
===========
DBF
DBFFPT
DBFBLOB
DBFCDX
DBFNTX
DataBases in use
================
Classes in use:
===============
1 ERROR
2 HBCLASS
3 HBOBJECT
4 TOPENAI
5 TFONT
6 TWINDOW
7 TDIALOG
8 TBRUSH
9 TCONTROL
10 TSAY
11 TMULTIGET
12 TBUTTON
13 TXBROWSE
14 TREG32
15 TXBRWCOLUMN
16 TSLIDER
17 TSCROLLBAR
18 TBTNBMP
19 TCLIPBOARD
20 TRECT
21 WIN_OLEAUTO
22 TOLEAUTO
23 TSTRUCT
Memory Analysis
===============
709 Static variables
Dynamic memory consume:
Actual Value: 1441792 bytes
Highest Value: 1441792 bytes