Page 1 of 1

Using Gemini Pro AI with PB (free)

Posted: Sat Dec 30, 2023 9:10 pm
by ricardo
Hi,

I shared in the past something very similar using openai, the difference is that its possible to use Gemini Pro for free (max 60 time per minute i think, but that is good enough= and its very easy to get the api key.

Just go to
https://makersuite.google.com/app/apikey

and easily create you free apikey.

I just started using it, but in my opinion (just test it a few times) its better than openai. It can also write some code...

Code: Select all

Procedure.s SendPrompt(sPrompt.s)
    sUrl.s = "https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key=YOUR_API_KEY"

    NewMap Header$()
    Header$("content-type") = "application/json"

    sBody.s = "{"
    sBody.s + Chr(34) + "contents" + Chr(34) + ": ["
    sBody.s + "{"
    sBody.s + Chr(34) + "parts" + Chr(34) + ": ["
    sBody.s + "{"
    sBody.s + Chr(34) + "text" + Chr(34) + ": " + Chr(34) + sPrompt + Chr(34)
    sBody.s + "}]"
    sBody.s + "}]"
    sBody.s + "}"

    Define httpReq

    httpReq = HTTPRequest(#PB_HTTP_Post, sUrl, sBody, 0, Header$())

    If httpReq
        Response$ = Trim(HTTPInfo(httpReq, #PB_HTTP_Response))
        Debug Response$
    EndIf

EndProcedure

lKeyword$ = "Write an article about Purebasic"
SendPrompt(lKeyword$)

Re: Using Gemini Pro AI with PB (free)

Posted: Sun Dec 31, 2023 5:13 pm
by Caronte3D
Thanks! :wink:

Re: Using Gemini Pro AI with PB (free)

Posted: Mon Jan 01, 2024 7:29 am
by ricardo
Updated: You can add temperature, MaxOutputTokens, etc.

Code: Select all

Procedure.s SendPrompt(sPrompt.s)
    sUrl.s = "https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key=YOUR_API_KEY"

    NewMap Header$()
    Header$("content-type") = "application/json"

   sBody.s = "{"
  sBody.s + Chr(34) + "contents" + Chr(34) + ": ["
  sBody.s + "{"
  sBody.s + Chr(34) + "parts" + Chr(34) + ": ["
  sBody.s + "{"
  sBody.s + Chr(34) + "text" + Chr(34) + ": " + Chr(34) + sPrompt + Chr(34)
  sBody.s + "}"
  sBody.s + "]"
  sBody.s + "}" ; Cierra el bloque de "contents"
  sBody.s + "]," ; Cierra el array "contents"
  

  sBody.s + Chr(34) + "generation_config" + Chr(34) + ": {"
  sBody.s + Chr(34) + "temperature" + Chr(34) + ":0.9,"
  sBody.s + Chr(34) + "top_k" + Chr(34) + ":1,"
  sBody.s + Chr(34) + "top_p" + Chr(34) + ":1,"
  sBody.s + Chr(34) + "maxOutputTokens" + Chr(34) + ":5000,"
  sBody.s + Chr(34) + "stop_sequences" + Chr(34) + ":[]"
  sBody.s + "}" ; Cierra el bloque de "generation_config"
  
  sBody.s + "}" ; Cierra todo el JSON

    Define httpReq

    httpReq = HTTPRequest(#PB_HTTP_Post, sUrl, sBody, 0, Header$())

    If httpReq
        Response$ = Trim(HTTPInfo(httpReq, #PB_HTTP_Response))
        Debug Response$
    EndIf

EndProcedure

lKeyword$ = "Write an article about Purebasic"
SendPrompt(lKeyword$)


Its free.

So you can make 60 requests per minute, its enough to do almost anything in a desktop application.
This limit is in fact planned for people offering free online tools.

But for one app (your user should get his own ApiKey) its a lot of request per minute.

Gemini as GPT are not as inteligent as people used to think. BUT, if you can do many requests, without paying, you could do a step by step prompt by prompt, and then you could -if you are smart enough- correct all the mistakes or avoid it.
I discover this by myself and i am sharing this really POWERFULL thing, because this is a great community.

Believe me that make it a prompt by prompt strategy, you could get all the power of ai, without the limitations, and lies and hallucinations, etc.
Hope that some people here could make great projects and share some finds...