Llama3-70B used locally

202 views
Skip to first unread message

antonio....@gmail.com

unread,
May 3, 2024, 1:01:24 AMMay 3
to Harbour Users
https://github.com/FiveTechSoft/hchat/blob/main/hchat.exe

All Llama3-70B power in just 7 MB

Next, Linux and OSX versions

best regards

cod...@outlook.com

unread,
May 3, 2024, 3:09:57 AMMay 3
to Harbour Users
Hi Antonio.

Can you send us some more information how to use hchat.exe.
It requires some email and password.

Regards,
Simo.

antonio....@gmail.com

unread,
May 3, 2024, 11:41:58 AMMay 3
to Harbour Users
You have to register in https://huggingface.co/

then you can use it. Next is to use it from our Harbour apps redirecting stdin/stdout

best regards,

antonio....@gmail.com

unread,
Jun 9, 2024, 11:18:59 PMJun 9
to Harbour Users
Llama3-70B is the most powerful free AI model (similar to chatgpt but free) that you can use from your Harbour apps.

hchat.exe uses HugChat API. Here you have the EXE already built and updated:
https://github.com/FiveTechSoft/hchat/blob/main/hchat.exe
How hchat.exe is built is explained from: https://github.com/FiveTechSoft/hchat

To use it from your Harbour apps:

1. run this and write your HuggingChat password
hchat.exe -u your_email_id_on_huggingface

2. Use it from Harbour using "pipes". This is an example using FWH:
#include "FiveWin.ch"

#define DT_WORDBREAK     16

static lExit := .F.

function Main()

   local oDlg, cWelcome, oOutput, cOutput := "", oBtn
   local oPrompt, cPrompt := Space( 100 )

   BeginChat( "antonio....@gmail.com" )
   cWelcome = Read()

   DEFINE DIALOG oDlg TITLE "Llama3-70B chat" SIZE 1200, 600

   @ 5.5, 0.7 GET oOutput VAR cOutput MULTILINE SIZE 590, 200 READONLY

   @ 18.7, 1 SAY "Prompt:"
   @ 21.5, 4 GET oPrompt VAR cPrompt SIZE 510, 15
   @ 15.5, 92 BUTTON oBtn PROMPT "Send" SIZE 40, 15 ACTION SendPrompt( cPrompt, oOutput, oBtn, oPrompt ) DEFAULT
   
   ACTIVATE DIALOG oDlg CENTERED ;
      ON PAINT ( SetBkColor( hDC, GetPixel( hDC, 5, 5 ) ),;
                 SelectObject( hDC, oDlg:oFont:hFont ),;
                 DrawTextEx( hDC, cWelcome, { -10, 15, 800, 1000 }, DT_WORDBREAK ) )

   if ! lExit
      Write( "/exit" + CRLF )
   endif  
   EndChat()

return nil

function SendPrompt( cPrompt, oOutput, oBtn, oPrompt )

   local cToken

   oBtn:Disable()
   Write( AllTrim( cPrompt ) + CRLF )
   if cPrompt != "/exit"
     while Right( ( cToken := Read() ), 8 ) != " [0m" + CRLF + "> "
        if Left( cToken, 6 ) == " [36m<"
           cToken = SubStr( cToken, 9 )
        endif
        oOutput:SetFocus()
        oOutput:Append( cToken )
        SysRefresh()
     end
   endif  
   oOutput:SetFocus()
   if cPrompt != "/exit"
      oOutput:Append( SubStr( cToken, 1, Len( cToken ) - 8 ) + CRLF + CRLF )
   else
      lExit = .T.
      oOutput:oWnd:End()  
   endif  
   oBtn:Enable()
   oPrompt:SetFocus()
   
return nil    

#pragma BEGINDUMP

#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <hbapi.h>

HANDLE hInputRead, hInputWrite, hOutputRead, hOutputWrite;
PROCESS_INFORMATION pi;

HB_FUNC( WRITE )
{
   DWORD dwBytesWritten;

   WriteFile( hInputWrite, hb_parc( 1 ), hb_parclen( 1 ), &dwBytesWritten, NULL );
}

HB_FUNC( READ )
{
   char buffer[1024];
   DWORD dwBytesRead;

   ReadFile( hOutputRead, buffer, 1024, &dwBytesRead, NULL );
   buffer[ dwBytesRead ] = '\0'; // Agregar fin de cadena  
   hb_retc( buffer );
}

HB_FUNC( BEGINCHAT )
{
    STARTUPINFO si;
    SECURITY_ATTRIBUTES sa;
    char command[256];
    char email[256];

    sa.nLength = sizeof(SECURITY_ATTRIBUTES);
    sa.bInheritHandle = TRUE;
    sa.lpSecurityDescriptor = NULL;

    strcpy( email, hb_parc( 1 ) );

    if (!CreatePipe(&hInputRead, &hInputWrite, &sa, 0))
        MessageBox( 0, "Error al crear pipe de entrada", "ok", 0 );
   
    if (!CreatePipe(&hOutputRead, &hOutputWrite, &sa, 0))
        MessageBox( 0, "Error al crear pipe de salida", "ok", 0 );

    // Preparar la cadena de comando con los parámetros
    sprintf(command, "hchat.bin -u %s", email);

    // Crear proceso externo
    ZeroMemory(&si, sizeof(si));
    si.cb = sizeof(si);
    si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
    si.wShowWindow = SW_HIDE;
    si.hStdInput = hInputRead;
    si.hStdOutput = hOutputWrite;
    si.hStdError = hOutputWrite;

    if (!CreateProcess(NULL, command, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi))
        MessageBox( 0, "Error al crear proceso externo", "ok", 0 );
}

HB_FUNC( ENDCHAT )
{
   CloseHandle( hInputRead );
   CloseHandle( hInputWrite );
   CloseHandle( hOutputRead );
   CloseHandle( hOutputWrite );
   TerminateProcess( pi.hProcess, 0 );
   CloseHandle( pi.hProcess );
   CloseHandle( pi.hThread );  
}

#pragma ENDDUMP

best regards

antonio....@gmail.com

unread,
Jun 9, 2024, 11:26:40 PMJun 9
to Harbour Users
Using it with Harbour screenshot:
llama3-70B.png
Reply all
Reply to author
Forward
0 new messages