Webview 2 + Html + ChatGPT !

Re: Webview 2 + Html + ChatGPT !

Postby Antonio Linares » Thu Sep 26, 2024 11:41 am

Esta nueva versión ya permite pedirle modificaciones sobre un HTML generado anteriormente, pudiendo especificar todo tipo de detalles :-)
Se reutiliza el HTML existente, asi se puede ir afinando según lo que necesitemos.

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

// get your OpenAI key from https://platform.openai.com/api-keys
static cKey := "sk-proj-..."  
static oChatgpt
static oTree
static cCategory := "                              "
static oWebView
static cContext := "                                                                   "

//----------------------------------------------------------------------------//

function Main()

    local oWnd, oExplBar, oAppPanel, oExplPanel

    oChatgpt = TChatgpt():New( cKey )

    DEFINE WINDOW oWnd TITLE "Build it"

    oExplBar = TExplorerBar():New( 0, 82, 480, 100, oWnd:oLeft, CLR_WHITE, RGB( 31, 31, 31 ) )
    oWnd:oLeft = oExplBar

    oExplPanel = oExplBar:AddPanel( "AI assistant" )
    oExplPanel:AddLink( "what is this app about ?",;
                        { || If( MsgGet( "App category", "Please specify it", @cCategory ), AddOptions( cCategory, oExplBar ),) } )
    oExplPanel:AddLink( "Add options to selected item", { || AddSubOptions() } )
    oExplPanel:AddLink( "Generate HTML for selected item", { || MsgRun( "Building the GUI", "Please wait", { || GenerateHTML() } ) } )
    oExplPanel:AddLink( "Modify HTML for selected item", { || ModifyHTML() } )
    oExplPanel:AddLink( "Overall context", { || Context() } )

    oWnd:oClient = TPanel():New( 0, 0, 100, 100, oWnd )

    oWebView = TWebView2():New( oWnd:oClient )
    oWebView:Navigate( "https://www.google.com" )

    ACTIVATE WINDOW oWnd MAXIMIZED ;
       ON RESIZE ( oWebView:SetSize( nWidth - oExplBar:nWidth, nHeight ), oExplBar:SetSize( 480, nHeight ) )

return nil    

//----------------------------------------------------------------------------//

function AddOptions( cCategory, oExplBar )

   local cOptions, aOptions, cOption, oAppPanel, oItem

   oChatgpt:cPrompt := "genera una lista separada por comas con las opciones de una aplicación de " + ;
                       hb_Utf8ToStr( AllTrim( cCategory ) ) + ". No des ninguna explicación"
   oChatgpt:Send()

   cOptions = oChatgpt:GetValue( "choices", "message", "content" )
   aOptions = hb_ATokens( cOptions, "," )

   oAppPanel = oExplBar:AddPanel( cCategory,, 700 )
   cCategory = hb_Utf8ToStr( AllTrim( cCategory ) )
   oTree = TTreeView():New( 2.5, 2, oAppPanel,,,,, 423, 675 )
   oTree:bChanged = { || oItem := oTree:GetSelected(), oWebView:SetHtml( If( ! Empty( oItem:Cargo ), oItem:Cargo, "" ) ) }

   for each cOption in aOptions
      oTree:Add( cOption )
   next  
   
return nil    

//----------------------------------------------------------------------------//

function AddSubOptions()

   local oItem
   local cOption := If( ( oItem := oTree:GetSelected() ) != nil, oItem:cPrompt, "" )
   local cOptions, cSubOption, aOptions

   if ! Empty( cOption )
      oChatgpt:cPrompt := "genera una lista separada por comas con las opciones de " + hb_StrToUtf8( cOption ) + ;
                          " para una aplicación de " + cCategory + ". No des ninguna explicación"
      oChatgpt:Send()

      cOptions = oChatgpt:GetValue( "choices", "message", "content" )
      aOptions = hb_ATokens( cOptions, "," )

      for each cSubOption in aOptions
        oItem:Add( cSubOption )
      next  

      oItem:Expand()
   endif  

return nil    

//----------------------------------------------------------------------------//

function GenerateHTML()

   local oItem, cHTML
   local cOption := If( ( oItem := oTree:GetSelected() ) != nil, oItem:cPrompt, "" )

   if ! Empty( cOption )
      oChatgpt:cPrompt := "genera el código HTML usando bootstrap para la opción " + hb_StrToUtf8( cOption ) + ;
                          " para una aplicación de " + hb_StrToUtf8( AllTrim( cCategory ) ) + ;
                          ". Que se vea muy profesional y elegante. No des ninguna explicación. " + ;
                          cContext
      oChatgpt:Send()
      cHTML = oChatgpt:GetValue( "choices", "message", "content" )
      oItem:Cargo = SubStr( cHTML, 8, Len( cHTML ) - 10 )
      oWebView:SetHTML( oItem:Cargo )
   endif  

return nil  

//----------------------------------------------------------------------------//

function ModifyHTML()

   local oItem, cHTML
   local cOption := If( ( oItem := oTree:GetSelected() ) != nil, oItem:cPrompt, "" )
   local cChange := Space( 50 )

   if fw_memoEdit( @cChange, "What do you want to change ?" )
      cChange = AllTrim( cChange )
   endif      

   if ! Empty( cOption )
      oChatgpt:cPrompt := "modifica este código HTML usando bootstrap para la opción " + hb_StrToUtf8( cOption ) + ;
                          " para una aplicación de " + hb_StrToUtf8( AllTrim( cCategory ) ) + ;
                          ". Que se vea muy profesional y elegante. No des ninguna explicación. " + ;
                          cContext + ". Y aplica estos cambios exactamente: " + hb_StrToUtf8( cChange ) + ;
                          oItem:Cargo
      MsgRun( "Asking ChatGPT", "Please wait", { || oChatgpt:Send() } )
      cHTML = oChatgpt:GetValue( "choices", "message", "content" )
      oItem:Cargo = SubStr( cHTML, 8, Len( cHTML ) - 10 )
      oWebView:SetHTML( oItem:Cargo )
   endif  

return nil  

//----------------------------------------------------------------------------//

function Context()

   if fw_memoEdit( @cContext, "Overall context for HTML generation" )
      cContext = AllTrim( cContext )
   endif      

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: Webview 2 + Html

Postby cmsoft » Thu Sep 26, 2024 12:44 pm

Antonio Linares wrote:César,

De momento constrúyelo, por favor, usando samples\buildh.bat

Serias tan amable de pasarmelo el buildh.bat que usas?
User avatar
cmsoft
 
Posts: 1290
Joined: Wed Nov 16, 2005 9:14 pm
Location: Mercedes - Bs As. Argentina

Re: Webview 2 + Html + ChatGPT !

Postby leandro » Thu Sep 26, 2024 1:10 pm

Antonio buenos días como estas?

Me devuelve este error

Code: Select all  Expand view

┌────────────────────────────────────────────────────────────────────────────┐
?FiveWin for xHarbour 23.10 64bits - Oct. 2023   Harbour development power  │▄
?(c) FiveTech 1993-2023 for Microsoft Windows 9X/NT/200X/ME/XP/Vista/7/8/10 │█
└────────────────────────────────────────────────────────────────────────────┘?
  ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀?
Compiling...
c:\xHar2407_64\bin\harbour leandro5 /n /d__64__ /ic:\fwh64_2407\include;c:\xHar2407_64\include /w /p
xHarbour 1.3.1 Intl. (SimpLex) (Build 20240624)
Copyright 1999-2024, http://www.xharbour.org http://www.harbour-project.org/
Compiling 'leandro5.prg' and generating preprocessed output to 'leandro5.ppo'...
Generating C source output to 'leandro5.c'...
Done.
Lines 263, Functions/Procedures 12, pCodes 1117
Embarcadero C++ 7.70 for Win64 Copyright (c) 2012-2023 Embarcadero Technologies, Inc.
leandro5.c:
Turbo Incremental Link64 6.98 Copyright (c) 1997-2023 Embarcadero Technologies, Inc.
Error: Unresolved external 'HB_FUN_HB_HSET' referenced from C:\FWH64_2407\SAMPLES\LEANDRO5.OBJ
* Linking errors *

C:\fwh64_2407\samples>
 
Saludos
LEANDRO AREVALO
Bogotá (Colombia)
https://hymlyma.com
https://hymplus.com/
leandroalfonso111@gmail.com
leandroalfonso111@hotmail.com

[ Embarcadero C++ 7.60 for Win32 ] [ FiveWin 23.07 ] [ xHarbour 1.3.0 Intl. (SimpLex) (Build 20230914) ]
User avatar
leandro
 
Posts: 1676
Joined: Wed Oct 26, 2005 2:49 pm
Location: Colombia

Re: Webview 2 + Html + ChatGPT !

Postby acuellar » Thu Sep 26, 2024 1:35 pm

Estimado Antonio

Con what is this app about ?
Me da éste error:
Code: Select all  Expand view

[   1] = H   { "error" => { "message" => "You exceeded your current quota, please check your plan and billi ... }
     [   2] = C   choices

Stack Calls
===========
   Called from: D:\Sistemas\AcrSoft\OK\PRG\ChatGPT.prg => TCHATGPT:GETVALUE( 0 )

Con Add options to selected item
Da éste error en el tree
Code: Select all  Expand view

 Error description: Error BASE/1004  No exported method: GETSELECTED
   Args:
     [   1] = U  

Stack Calls
===========
   Called from: D:\Sistemas\AcrSoft\OK\PRG\ACR.prg => GETSELECTED( 0 )
 


Gracias por la ayuda
Saludos,

Adhemar C.
User avatar
acuellar
 
Posts: 1643
Joined: Tue Oct 28, 2008 6:26 pm
Location: Santa Cruz-Bolivia

Re: Webview 2 + Html

Postby Antonio Linares » Thu Sep 26, 2024 1:47 pm

cmsoft wrote:
Antonio Linares wrote:César,

De momento constrúyelo, por favor, usando samples\buildh.bat

Serias tan amable de pasarmelo el buildh.bat que usas?


buildh.bat
Code: Select all  Expand view
@ECHO OFF
CLS
ECHO ┌────────────────────────────────────────────────────────────────────────────┐
ECHO │ FiveWin for Harbour 24.07 - Jul. 2024           Harbour development power  │▄
ECHO │ (c) FiveTech 1993-2024 for Microsoft Windows 9X/NT/200X/ME/XP/Vista/7/8/10 │█
ECHO └────────────────────────────────────────────────────────────────────────────┘█
ECHO   ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀

if A%1 == A GOTO :SINTAX
if NOT EXIST %1.prg GOTO :NOEXIST

if "%FWDIR%" == "" set FWDIR=.\..
if "%HBDIR%" == "" set HBDIR=c:\harbour
rem if "%2" == "/b" set GT=gtwin
rem if not "%2" == "/b" set GT=gtgui
set GT=gtgui

ECHO Compiling...

set hdir=%HBDIR%
set hdirl=%hdir%\lib\win\bcc
set fwh=%FWDIR%
if exist c:\bcc77 set bcdir=c:\bcc77
if exist c:\bcc64 set bcdir=c:\bcc64

%hdir%\bin\win\bcc\harbour %1 /n /i%fwh%\include;%hdir%\include /w /p %2 %3 > comp.log 2> warnings.log
if errorlevel 1 goto COMPILEERRORS
@type comp.log
@type warnings.log

echo -O2 -e%1.exe -I%hdir%\include -I%bcdir%\include -I%fwh%\include %1.c > b32.bc
%bcdir%\bin\bcc32 -M -c @b32.bc
:ENDCOMPILE

IF EXIST %1.rc %bcdir%\bin\brc32.exe -r -I%bcdir%\include -I%bcdir%\include\windows\sdk %1
rem IF EXIST %1.rc %bcdir%\bin\cgrc.exe -r -m -I%bcdir%\include -I%bcdir%\include\windows\sdk %1
rem IF EXIST %1.rc %vcdir%\bin\rc -r -d__FLAT__ %1

echo -L%bcdir%\lib;%bcdir%\lib\psdk + > b32.bc
echo %bcdir%\lib\c0w32.obj + >> b32.bc
echo %1.obj, + >> b32.bc
echo %1.exe, + >> b32.bc
echo %1.map, + >> b32.bc
echo %fwh%\lib\FiveH.lib %fwh%\lib\FiveHC.lib %fwh%\lib\libmysql.lib + >> b32.bc
rem echo %fwh%\lib\drxlsx32_bcc.lib + >> b32.bc
rem echo %fwh%\lib\xlsxlibhbbcc.lib + >> b32.bc
echo %fwh%\lib\hbpgsql.lib %fwh%\lib\libpq.lib + >> b32.bc
echo %fwh%\lib\drxlsx32_bcc.lib + >> b32.bc
echo %hdirl%\hbhpdf.lib + >> b32.bc
echo %hdirl%\libhpdf.lib + >> b32.bc
echo %hdirl%\png.lib + >> b32.bc
echo %hdirl%\hbwin.lib + >> b32.bc
echo %hdirl%\gtgui.lib + >> b32.bc
echo %hdirl%\hbrtl.lib + >> b32.bc
echo %hdirl%\hbvm.lib + >> b32.bc
echo %hdirl%\hblang.lib + >> b32.bc
echo %hdirl%\hbmacro.lib + >> b32.bc
echo %hdirl%\hbrdd.lib + >> b32.bc
echo %hdirl%\rddntx.lib + >> b32.bc
echo %hdirl%\rddcdx.lib + >> b32.bc
echo %hdirl%\rddfpt.lib + >> b32.bc
echo %hdirl%\hbsix.lib + >> b32.bc
echo %hdirl%\hbdebug.lib + >> b32.bc
echo %hdirl%\hbcommon.lib + >> b32.bc
echo %hdirl%\hbpp.lib + >> b32.bc
echo %hdirl%\hbcpage.lib + >> b32.bc
echo %hdirl%\hbcplr.lib + >> b32.bc
echo %hdirl%\hbct.lib + >> b32.bc
echo %hdirl%\hbpcre.lib + >> b32.bc
echo %hdirl%\xhb.lib + >> b32.bc
echo %hdirl%\hbziparc.lib + >> b32.bc
echo %hdirl%\hbmzip.lib + >> b32.bc
echo %hdirl%\hbzlib.lib + >> b32.bc
echo %hdirl%\minizip.lib + >> b32.bc
rem echo %hdirl%\png.lib + >> b32.bc
echo %hdirl%\hbusrrdd.lib + >> b32.bc
echo %hdirl%\hbtip.lib + >> b32.bc
echo %hdirl%\hbzebra.lib + >> b32.bc
echo %hdirl%\hbcurl.lib + >> b32.bc
echo %hdirl%\libcurl.lib + >> b32.bc

rem Uncomment these two lines to use Advantage RDD
rem echo %hdirl%\rddads.lib + >> b32.bc
rem echo %hdirl%\Ace32.lib + >> b32.bc

echo %fwh%\lib\dolphin.lib + >> b32.bc
rem echo %fwh%\lib\libmysql.lib + >> b32.bc

echo %bcdir%\lib\cw32.lib + >> b32.bc
echo %bcdir%\lib\psdk\uuid.lib + >> b32.bc
echo %bcdir%\lib\import32.lib + >> b32.bc
echo %bcdir%\lib\psdk\ws2_32.lib + >> b32.bc
echo %bcdir%\lib\psdk\odbc32.lib + >> b32.bc
echo %bcdir%\lib\psdk\nddeapi.lib + >> b32.bc
echo %bcdir%\lib\psdk\iphlpapi.lib + >> b32.bc
echo %bcdir%\lib\psdk\msimg32.lib + >> b32.bc
echo %bcdir%\lib\psdk\psapi.lib + >> b32.bc
echo %bcdir%\lib\psdk\rasapi32.lib + >> b32.bc
echo %bcdir%\lib\psdk\gdiplus.lib + >> b32.bc
echo %bcdir%\lib\psdk\shell32.lib + >> b32.bc
echo %bcdir%\lib\psdk\uxtheme.lib , >> b32.bc

IF EXIST %1.res echo %1.res >> b32.bc
if %GT% == gtwin %bcdir%\bin\ilink32 -Gn -Tpe -s @b32.bc
IF ERRORLEVEL 1 GOTO LINKERROR
if %GT% == gtgui %bcdir%\bin\ilink32 -Gn -aa -Tpe -s @b32.bc
IF ERRORLEVEL 1 GOTO LINKERROR
ECHO * Application successfully built *
rem signtool.exe sign /fd sha256 %1.exe
%1
GOTO EXIT
ECHO

rem delete temporary files
@del %1.c

:COMPILEERRORS
@type comp.log
@type warnings.log
ECHO * Compile errors *
GOTO EXIT

:LINKERROR
ECHO * Linking errors *
GOTO EXIT

:SINTAX
ECHO    SYNTAX: Build [Program]     {-- No especifiques la extensi?n PRG
ECHO                                {-- Don't specify .PRG extension
GOTO EXIT

:NOEXIST
ECHO The specified PRG %1 does not exist

:EXIT
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: Webview 2 + Html + ChatGPT !

Postby Antonio Linares » Thu Sep 26, 2024 1:48 pm

leandro wrote:Antonio buenos días como estas?

Me devuelve este error

Code: Select all  Expand view

┌────────────────────────────────────────────────────────────────────────────┐
?FiveWin for xHarbour 23.10 64bits - Oct. 2023   Harbour development power  │▄
?(c) FiveTech 1993-2023 for Microsoft Windows 9X/NT/200X/ME/XP/Vista/7/8/10 │█
└────────────────────────────────────────────────────────────────────────────┘?
  ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀?
Compiling...
c:\xHar2407_64\bin\harbour leandro5 /n /d__64__ /ic:\fwh64_2407\include;c:\xHar2407_64\include /w /p
xHarbour 1.3.1 Intl. (SimpLex) (Build 20240624)
Copyright 1999-2024, http://www.xharbour.org http://www.harbour-project.org/
Compiling 'leandro5.prg' and generating preprocessed output to 'leandro5.ppo'...
Generating C source output to 'leandro5.c'...
Done.
Lines 263, Functions/Procedures 12, pCodes 1117
Embarcadero C++ 7.70 for Win64 Copyright (c) 2012-2023 Embarcadero Technologies, Inc.
leandro5.c:
Turbo Incremental Link64 6.98 Copyright (c) 1997-2023 Embarcadero Technologies, Inc.
Error: Unresolved external 'HB_FUN_HB_HSET' referenced from C:\FWH64_2407\SAMPLES\LEANDRO5.OBJ
* Linking errors *

C:\fwh64_2407\samples>
 

Cambia HB_HSET() en la Clase TChatGPT con la función equivalente para xHarbour
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: Webview 2 + Html + ChatGPT !

Postby Antonio Linares » Thu Sep 26, 2024 1:50 pm

acuellar wrote:Estimado Antonio

Con what is this app about ?
Me da éste error:
Code: Select all  Expand view

[   1] = H   { "error" => { "message" => "You exceeded your current quota, please check your plan and billi ... }
     [   2] = C   choices

Stack Calls
===========
   Called from: D:\Sistemas\AcrSoft\OK\PRG\ChatGPT.prg => TCHATGPT:GETVALUE( 0 )

Con Add options to selected item
Da éste error en el tree
Code: Select all  Expand view

 Error description: Error BASE/1004  No exported method: GETSELECTED
   Args:
     [   1] = U  

Stack Calls
===========
   Called from: D:\Sistemas\AcrSoft\OK\PRG\ACR.prg => GETSELECTED( 0 )
 


Gracias por la ayuda


> [ 1] = H { "error" => { "message" => "You exceeded your current quota, please check your plan and billi ... }

Revisa tu cuenta en OpenAI y asegúrate que los pagos esten al dia. La versión que usamos es muy muy económica, merece el gasto! :-)

> No exported method: GETSELECTED

Hasta que no se crea correctamente la primera opción del asistente las demás no funcionan bien. Hay que controlar ese error
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: Webview 2 + Html + ChatGPT !

Postby leandro » Thu Sep 26, 2024 3:15 pm

Antonio gracias por responder, ya encontramos la funcion que reemplaza la de harbour, pero ahora nos sale un mensaje de error:

Image

Buscando en las carpetas, encontramos la dll -> libcrypto-3-x64.dll, pero la otra nop :( :oops:
Saludos
LEANDRO AREVALO
Bogotá (Colombia)
https://hymlyma.com
https://hymplus.com/
leandroalfonso111@gmail.com
leandroalfonso111@hotmail.com

[ Embarcadero C++ 7.60 for Win32 ] [ FiveWin 23.07 ] [ xHarbour 1.3.0 Intl. (SimpLex) (Build 20230914) ]
User avatar
leandro
 
Posts: 1676
Joined: Wed Oct 26, 2005 2:49 pm
Location: Colombia

Re: Webview 2 + Html + ChatGPT !

Postby acuellar » Thu Sep 26, 2024 3:27 pm

Leandro a mi no me pidió esa

Pide la libcurl-x64.dll

La libcrypto-1_1-x64.dll
La podes encontrar en RunnerxBase
Saludos,

Adhemar C.
User avatar
acuellar
 
Posts: 1643
Joined: Tue Oct 28, 2008 6:26 pm
Location: Santa Cruz-Bolivia

Re: Webview 2 + Html + ChatGPT !

Postby Antonio Linares » Thu Sep 26, 2024 4:35 pm

Lo estoy construyendo, de momento, en 32 bits
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: Webview 2 + Html + ChatGPT !

Postby leandro » Thu Sep 26, 2024 7:26 pm

Antonio buenas tardes, listo ya logramos construir el exe, pero el problema ahora es que no tenemos las keys para acceder a chatgpt, me toca dejar para luego la prueba :oops:
Saludos
LEANDRO AREVALO
Bogotá (Colombia)
https://hymlyma.com
https://hymplus.com/
leandroalfonso111@gmail.com
leandroalfonso111@hotmail.com

[ Embarcadero C++ 7.60 for Win32 ] [ FiveWin 23.07 ] [ xHarbour 1.3.0 Intl. (SimpLex) (Build 20230914) ]
User avatar
leandro
 
Posts: 1676
Joined: Wed Oct 26, 2005 2:49 pm
Location: Colombia

Re: Webview 2 + Html + ChatGPT !

Postby Antonio Linares » Fri Sep 27, 2024 5:53 am

Nueva versión que ya salva la aplicación creada a una DBF.

Se han hecho algunas modificaciones en FWH. Os proporcionaré el EXE ya construido para que solo tengais que especificar vuestra clave de OpenAI

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

REQUEST DbfCdx

// get your OpenAI key from https://platform.openai.com/api-keys
static cKey := "sk-proj-..."  
static oChatgpt
static oTree
static cCategory := "                              "
static oWebView
static cContext := "                                                                   "

//----------------------------------------------------------------------------//

function Main()

    local oWnd, oExplBar, oAppPanel, oExplPanel

    oChatgpt = TChatgpt():New( cKey )

    DEFINE WINDOW oWnd TITLE "Build it"

    oExplBar = TExplorerBar():New( 0, 82, 480, 100, oWnd:oLeft, CLR_WHITE, RGB( 31, 31, 31 ) )
    oWnd:oLeft = oExplBar

    oExplPanel = oExplBar:AddPanel( "AI assistant" )
    oExplPanel:AddLink( "what is this app about ?",;
                        { || If( MsgGet( "App category", "Please specify it", @cCategory ), AddOptions( cCategory, oExplBar ),) } )
    oExplPanel:AddLink( "Add options to selected item", { || AddSubOptions() } )
    oExplPanel:AddLink( "Generate HTML for selected item", { || MsgRun( "Building the GUI", "Please wait", { || GenerateHTML() } ) } )
    oExplPanel:AddLink( "Modify HTML for selected item", { || ModifyHTML() } )
    oExplPanel:AddLink( "Overall context", { || Context() } )
    oExplPanel:AddLink( "Save App", { || SaveApp() } )
    oExplPanel:AddLink( "Load App", { || LoadApp() } )

    oWnd:oClient = TPanel():New( 0, 0, 100, 100, oWnd )

    oWebView = TWebView2():New( oWnd:oClient )
    oWebView:Navigate( "https://www.google.com" )

    ACTIVATE WINDOW oWnd MAXIMIZED ;
       ON RESIZE ( oWebView:SetSize( nWidth - oExplBar:nWidth, nHeight ), oExplBar:SetSize( 480, nHeight ) )

return nil    

//----------------------------------------------------------------------------//

function AddOptions( cCategory, oExplBar )

   local cOptions, aOptions, cOption, oAppPanel, oItem

   oChatgpt:cPrompt := "genera una lista separada por comas con las opciones de una aplicación de " + ;
                       hb_Utf8ToStr( AllTrim( cCategory ) ) + ". No des ninguna explicación"
   MsgRun( "Asking ChatGPT", "Please wait", { || oChatgpt:Send() } )

   cOptions = oChatgpt:GetValue( "choices", "message", "content" )
   aOptions = hb_ATokens( cOptions, "," )

   oAppPanel = oExplBar:AddPanel( cCategory,, 700 )
   cCategory = hb_Utf8ToStr( AllTrim( cCategory ) )
   oTree = TTreeView():New( 2.5, 2, oAppPanel,,,,, 423, 675 )
   oTree:bChanged = { || oItem := oTree:GetSelected(), oWebView:SetHtml( If( ! Empty( oItem:Cargo ), oItem:Cargo, "" ) ) }

   for each cOption in aOptions
      oItem = oTree:Add( cOption )
      oItem:Cargo = HtmlDefault()
   next  
   
return nil    

//----------------------------------------------------------------------------//

function AddSubOptions()

   local oItem
   local cOption := If( ( oItem := oTree:GetSelected() ) != nil, oItem:cPrompt, "" )
   local cOptions, cSubOption, aOptions, oSubItem

   if ! Empty( cOption )
      oChatgpt:cPrompt := "genera una lista separada por comas con las opciones de " + hb_StrToUtf8( cOption ) + ;
                          " para una aplicación de " + hb_StrToUtf8( cCategory ) + ". No des ninguna explicación"
      MsgRun( "Asking ChatGPT", "Please wait", { || oChatgpt:Send() } )

      cOptions = oChatgpt:GetValue( "choices", "message", "content" )
      aOptions = hb_ATokens( cOptions, "," )

      for each cSubOption in aOptions
         oSubItem = oItem:Add( cSubOption )
         oSubItem:Cargo = HtmlDefault()
      next  

      oItem:Expand()
   endif  

return nil    

//----------------------------------------------------------------------------//

function GenerateHTML()

   local oItem, cHTML
   local cOption := If( ( oItem := oTree:GetSelected() ) != nil, oItem:cPrompt, "" )

   if ! Empty( cOption )
      oChatgpt:cPrompt := "genera el código HTML usando bootstrap para la opción " + hb_StrToUtf8( cOption ) + ;
                          " para una aplicación de " + hb_StrToUtf8( AllTrim( cCategory ) ) + ;
                          ". Que se vea muy profesional y elegante. No des ninguna explicación. " + ;
                          cContext
      oChatgpt:Send()
      cHTML = oChatgpt:GetValue( "choices", "message", "content" )
      oItem:Cargo = SubStr( cHTML, 8, Len( cHTML ) - 10 )
      oWebView:SetHTML( oItem:Cargo )
   endif  

return nil  

//----------------------------------------------------------------------------//

function ModifyHTML()

   local oItem, cHTML
   local cOption := If( ( oItem := oTree:GetSelected() ) != nil, oItem:cPrompt, "" )
   local cChange := Space( 50 )

   if fw_memoEdit( @cChange, "What do you want to change ?" )
      cChange = AllTrim( cChange )
   endif      

   if ! Empty( cOption )
      oChatgpt:cPrompt := "modifica este código HTML usando bootstrap para la opción " + hb_StrToUtf8( cOption ) + ;
                          " para una aplicación de " + hb_StrToUtf8( AllTrim( cCategory ) ) + ;
                          ". Que se vea muy profesional y elegante. No des ninguna explicación. " + ;
                          cContext + ". Y aplica estos cambios exactamente: " + hb_StrToUtf8( cChange ) + ;
                          oItem:Cargo
      MsgRun( "Asking ChatGPT", "Please wait", { || oChatgpt:Send() } )
      cHTML = oChatgpt:GetValue( "choices", "message", "content" )
      oItem:Cargo = SubStr( cHTML, 8, Len( cHTML ) - 10 )
      oWebView:SetHTML( oItem:Cargo )
   endif  

return nil  

//----------------------------------------------------------------------------//

function Context()

   if fw_memoEdit( @cContext, "Overall context for HTML generation" )
      cContext = AllTrim( cContext )
   endif      

return nil  

//----------------------------------------------------------------------------//

function CreateDBF( cFileName )

   DbCreate( Tip_UrlEncode( cFileName ) + ".dbf", { { "prompt", "C", 80, 0 },;
                                   { "level",  "N",  3, 0 },;
                                   { "html",   "M", 10, 0 } }, "DBFCDX" )
   USE ( Tip_UrlEncode( cFileName ) )

return nil

//----------------------------------------------------------------------------//

function SaveApp()

   if ! File( cCategory + ".dbf" )
      CreateDBF( StrTran( AllTrim( cCategory ), " ", "_" ) )
   else
      if MsgYesNo ("App already exists", "Do you want to overwrite it?" )
         CreateDBF( StrTran( AllTrim( cCategory ), " ", "_" ) )
      else
         USE ( cCategory )
      endif
   endif

   oTree:Scan( { | oItem, nPos, nLevel | DbAppend(), field->prompt := oItem:cPrompt,;
               field->level := nLevel, field->html := oItem:Cargo, .F. } )
   GO TOP
   XBrowse()
   USE

return nil  

//----------------------------------------------------------------------------//

function LoadApp()

return nil  

//----------------------------------------------------------------------------//

function HtmlDefault()

   local cHtml

   TEXT INTO cHtml
      <!DOCTYPE html>
      <html lang="es">
      <head>
         <style>
            body {
                  background-color: rgb(31, 31, 31);
            }
         </style>
      </head>
      <body>
      </body>
      </html>
   ENDTEXT

return cHtml

//----------------------------------------------------------------------------//
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: Webview 2 + Html + ChatGPT !

Postby Antonio Linares » Fri Sep 27, 2024 6:04 am

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

PreviousNext

Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 41 guests