![Smile :-)](./images/smilies/icon_smile.gif)
This will be included in next FWH build. If you need it before, please send me an email
You don't have to pay OpenAI to have AI on your FWH apps
![Smile :-)](./images/smilies/icon_smile.gif)
![Image](https://github.com/FiveTechSoft/screenshots/blob/master/fwh_ai.gif?raw=true)
Code: Select all | Expand
#include "Fivewin.ch"
function Main()
local oDlg, cPrompt := PadR( "List 10 possible uses of AI from my Windows apps.", 200 )
local cAnswer := "", oAnswer, oBtn
DEFINE DIALOG oDlg SIZE 700, 500 TITLE "FWH AI"
@ 1, 1 GET cPrompt SIZE 300, 15
@ 3, 1 GET oAnswer VAR cAnswer MULTILINE SIZE 300, 200
@ 0.7, 52.5 BUTTON oBtn PROMPT "start" ;
ACTION ( oBtn:Disable(), Llama( "phi-2_Q4_K_M.gguf", RTrim( cPrompt ),;
CallBack( { | cStr | oAnswer:SetFocus(), oAnswer:Append( cStr ) } ) ),;
oBtn:Enable(), oBtn:SetFocus() )
@ 2.2, 52.5 BUTTON "Clear" ACTION oAnswer:SetText( "" )
ACTIVATE DIALOG oDlg CENTERED
return nil
DLL FUNCTION Llama( cModel AS LPSTR, cPrompt AS LPSTR, pFunc AS PTR ) AS VOID PASCAL LIB "llama64.dll"
Code: Select all | Expand
#include "Fivewin.ch"
function Main()
local oDlg, cPrompt := PadR( "List 10 possible uses of AI from my Windows apps.", 200 )
local cAnswer := "", oAnswer, oBtn
DEFINE DIALOG oDlg SIZE 700, 500 TITLE "FWH AI"
@ 1, 1 GET cPrompt MULTILINE SIZE 300, 15
@ 3, 1 GET oAnswer VAR cAnswer MULTILINE SIZE 300, 200
@ 0.7, 52.5 BUTTON oBtn PROMPT "start" ;
ACTION ( oBtn:Disable(), Llama( "phi-2_Q4_K_M.gguf", RTrim( cPrompt ),;
CallBack( { | cStr | oAnswer:SetFocus(), oAnswer:Append( cStr ) } ) ),;
oBtn:Enable(), oBtn:SetFocus() )
@ 2.2, 52.5 BUTTON "Clear" ACTION oAnswer:SetText( "" )
ACTIVATE DIALOG oDlg CENTERED
return nil
DLL FUNCTION Llama( cModel AS LPSTR, cPrompt AS LPSTR, pFunc AS PTR ) AS VOID PASCAL LIB "llama64.dll"
#pragma BEGINDUMP
#include <Windows.h>
#include <hbapi.h>
#include <hbapiitm.h>
static PHB_ITEM pBlock;
static void callback( char * szMsg )
{
PHB_ITEM pStr = hb_itemPutC( NULL, szMsg );
hb_evalBlock1( pBlock, pStr );
hb_itemRelease( pStr );
}
HB_FUNC( CALLBACK )
{
pBlock = hb_gcGripGet( hb_param( 1, HB_IT_BLOCK ) );
hb_retnll( ( HB_LONGLONG ) callback );
}
#pragma ENDDUMP
No.Antonio Linares wrote:Dear Enrico,
Have you downloaded "phi-2_Q4_K_M.gguf" and have you properly provided its path in the PRG code ?
Code: Select all | Expand
hb_retnll( ( LONGLONG ) callback );
Code: Select all | Expand
#include "Fivewin.ch"
function Main()
local oDlg, cPrompt := PadR( "List 10 possible uses of AI from my Windows apps.", 200 )
local cAnswer := "", oAnswer, oBtn
local oVoice := TOleAuto():New( "Sapi.SPVoice" )
DEFINE DIALOG oDlg SIZE 700, 500 TITLE "FWH AI"
@ 1, 1 GET cPrompt MULTILINE SIZE 300, 15
@ 3, 1 GET oAnswer VAR cAnswer MULTILINE SIZE 300, 200
@ 0.7, 52.5 BUTTON oBtn PROMPT "start" ;
ACTION ( oBtn:Disable(), Llama( "phi-2_Q4_K_M.gguf", RTrim( cPrompt ),;
CallBack( { | cStr | oAnswer:SetFocus(), oAnswer:Append( cStr ) } ) ),;
oBtn:Enable(), oBtn:SetFocus() )
@ 2.2, 52.5 BUTTON "Clear" ACTION oAnswer:SetText( "" )
@ 3.2, 52.5 BUTTON "Speak" ACTION oVoice:Speak( oAnswer:GetText() )
ACTIVATE DIALOG oDlg CENTERED
return nil
DLL FUNCTION Llama( cModel AS LPSTR, cPrompt AS LPSTR, pFunc AS PTR ) AS VOID PASCAL LIB "llama64.dll"
#pragma BEGINDUMP
#include <Windows.h>
#include <hbapi.h>
#include <hbapiitm.h>
static PHB_ITEM pBlock;
static void callback( char * szMsg )
{
PHB_ITEM pStr = hb_itemPutC( NULL, szMsg );
hb_evalBlock1( pBlock, pStr );
hb_itemRelease( pStr );
}
HB_FUNC( CALLBACK )
{
pBlock = hb_gcGripGet( hb_param( 1, HB_IT_BLOCK ) );
hb_retnll( ( HB_LONGLONG ) callback );
}
#pragma ENDDUMP