Using Gemini Pro AI with PB (free)

Share your advanced PureBasic knowledge/code with the community.
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Using Gemini Pro AI with PB (free)

Post 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$)
ARGENTINA WORLD CHAMPION
User avatar
Caronte3D
Addict
Addict
Posts: 1361
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: Using Gemini Pro AI with PB (free)

Post by Caronte3D »

Thanks! :wink:
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Re: Using Gemini Pro AI with PB (free)

Post 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...
ARGENTINA WORLD CHAMPION
Post Reply