OpenAI REST API

Developed or developing a new product in PureBasic? Tell the world about it.
miso
Enthusiast
Enthusiast
Posts: 410
Joined: Sat Oct 21, 2023 4:06 pm
Location: Hungary

Re: ChatGPT REST API

Post by miso »

@Idle
I only feel respect toward JHPJHP. The topic is what's beyond my expertise. (So I just read what's the opinion of people better than me.)
tj1010
Enthusiast
Enthusiast
Posts: 716
Joined: Mon Feb 25, 2013 5:51 pm

Re: ChatGPT REST API

Post by tj1010 »

I 100% agree this is a major feat for here by what I assume is the most talented/productive regular on the forums. Freedom is only accepting support and problem solving by those who are willing, and enjoying it's quality.

I can't imagine how many hours it must of took to do this
Last edited by tj1010 on Mon Jun 02, 2025 6:57 am, edited 1 time in total.
User avatar
idle
Always Here
Always Here
Posts: 5840
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: ChatGPT REST API

Post by idle »

tj1010 wrote: Mon Jun 02, 2025 6:44 am I think modern PB and SB forums have talent and support and development in proportion to what the level of political correctness and sensitivity allows..

That being said, I have no doubt this is an amazing feat in capability here that must of took hours to do, and only such a talent could of done it in a pronoun-neutral manner.
Seriously have you actually ever contributed in a positive way here? your a smart guy but not to sensitive!
contribute some code maybe! PM me if you want to discuss
tj1010
Enthusiast
Enthusiast
Posts: 716
Joined: Mon Feb 25, 2013 5:51 pm

Re: ChatGPT REST API

Post by tj1010 »

idle wrote: Mon Jun 02, 2025 6:50 am
tj1010 wrote: Mon Jun 02, 2025 6:44 am I think modern PB and SB forums have talent and support and development in proportion to what the level of political correctness and sensitivity allows..

That being said, I have no doubt this is an amazing feat in capability here that must of took hours to do, and only such a talent could of done it in a pronoun-neutral manner.
Seriously have you actually ever contributed in a positive way here? your a smart guy but not to sensitive!
contribute some code maybe! PM me if you want to discuss
You first..

BTW anyone good is going to also notice the support-overhead and contrarian-sensitivity keeping it there by people who somehow have nothing finished despite decades-in and leave or be critical.. Productive and talented people tend to avoid BS, especially by people who can't keep up but still have an ego..

I look forward to the next AI posts too, and I won't even ask what you've published cause we both know the answer :lol:
User avatar
Caronte3D
Addict
Addict
Posts: 1355
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: ChatGPT REST API

Post by Caronte3D »

JHPJHP wrote: Mon Jun 02, 2025 1:57 am If anyone is worried about access disappearing...
Hi JHPJHP :wink:
Do you have plans to release the server side source of this RestAPI, in case we want to own host?
User avatar
JHPJHP
Addict
Addict
Posts: 2252
Joined: Sat Oct 09, 2010 3:47 am

Re: ChatGPT REST API

Post by JHPJHP »

Hi Tawbie, miso,

Thank you for your very kind words.

-------------------------------
ChatGPT wrote:Surface vs. Intended Meaning
• "I 100% agree this is a major feat..."
Surface meaning: Sincere praise.
Sarcastic intent: Possibly minimizing the accomplishment or mocking the idea that it's impressive.

• "...by what I assume is the most talented/productive regular on the forums."
Surface meaning: Flattery.
Sarcastic intent: A jab—likely implying the opposite (e.g., that the person is neither talented nor productive).

• "Freedom is only accepting support and problem solving by those who are willing, and enjoying it's quality."
Surface meaning: Philosophical appreciation.
Sarcastic intent: This may be a vague or passive-aggressive critique of self-important or exclusionary behavior—perhaps implying that the person only listens to praise or select voices.

• "I can't imagine how many hours it must of took to do this"
Surface meaning: Admiration of effort.
Sarcastic intent: Possibly ridiculing the unnecessary amount of time spent or the effort being disproportionate to the result.

Overall Sentiment (with Sarcasm Considered):
Negative or dismissive, cloaked in mock praise. The tone is likely passive-aggressive, aimed at undermining or critiquing the individual’s work or their status in the community, while maintaining plausible deniability through superficially positive language.

If the audience knows the speaker’s typical tone, the message would likely be received as a veiled insult rather than genuine admiration.
-------------------------------

Hi Caronte3D,

My intent for creating this thread was to provide PureBasic users a simple option for testing AI in their day-to-day programming.

There are literally dozens of AI options out there, each with their own set of requirements and configurations. But sometimes when testing we just want to know what's possible... not what we read, not what others are saying, but real-world results without all the additional overhead.

-------------------------------

Applied small update:
• Improved example attach_image.pb
• Added Procedure ReadyImage to sources.pbi
Last edited by JHPJHP on Sun Jun 15, 2025 3:22 pm, edited 5 times in total.

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
User avatar
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: ChatGPT REST API

Post by skywalk »

Maybe Fred could enable a "like button" for registered users only. No bots :twisted:
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
JHPJHP
Addict
Addict
Posts: 2252
Joined: Sat Oct 09, 2010 3:47 am

Re: ChatGPT REST API

Post by JHPJHP »

Hi All,

As requested by Caronte3D and others (privately)...

Updated:
➤ Added server-side scripts:
• readme.txt
• openai/.env
• openai/.htaccess
• openai/.php/ask_chatgpt.php
• openai/.php/ask_dalle.php
• openai/.php/query_tiktoken.php
• tiktoken/encode_text.py
• tiktoken/passenger_wsgi.py
• tiktoken/requirements.txt
➤ Improved example: attach_image.pb
• Added parameter: Max_Size

Attach Image: Max_Size
Because the images are first converted to Base64, I found it best to keep the larger of the two dimensions (width/height) to a max size of 400px, especially if POSTING two images for comparison. Not to mention that it's cheaper, faster and the results were the same as with larger images.
Last edited by JHPJHP on Sun Jun 15, 2025 5:34 am, edited 2 times in total.

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
User avatar
Caronte3D
Addict
Addict
Posts: 1355
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: ChatGPT REST API

Post by Caronte3D »

Thank you very much!
The server side code is a must to be able to hide the key token in case we make a commercial project :wink:
User avatar
JHPJHP
Addict
Addict
Posts: 2252
Joined: Sat Oct 09, 2010 3:47 am

Re: ChatGPT REST API

Post by JHPJHP »

Hi Caronte3D,

With AI's changing landscape you might be better off starting from scratch, learn early the inherent challenges; either way they're unavoidable.

-----------------------------

I just finished a fun experiment where I took the code from Pure2048, a well-known game converted to PureBasic by Mindphazer, added some of my own code so that an AI could play the game without any user interaction, and the results were surprising.

I haven't posted the code because using AI to play this game can eat though a $2.00 budget fairly quickly. Running numerous tests over several hours brought the balance down to $1.50. You can imagine how short a time it would take to reach $0.00 if several people were testing the code.
Last edited by JHPJHP on Thu Jul 24, 2025 3:42 pm, edited 1 time in total.

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
dige
Addict
Addict
Posts: 1391
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Re: ChatGPT REST API

Post by dige »

Hi JHPJHP,

that sounds very exciting. I would be interested to know how you went about it? Did you train your own net or build a GPT with the rules of the game?
Or did you use a prompt that transmits both instructions and the current setting from the game to ChatGPT, for example?
"Daddy, I'll run faster, then it is not so far..."
User avatar
JHPJHP
Addict
Addict
Posts: 2252
Joined: Sat Oct 09, 2010 3:47 am

Re: ChatGPT REST API

Post by JHPJHP »

Hi dige,

I would like to have created my own GPT but that option was only available with the OpenAI Plus plan.

I used a system / user prompt that contained the instructions and game data.

Coding the auto response only took an hour and part of that was spent familiarizing myself with Mindphazer's 2048 script; the bulk of time was spent working on the prompts. I could bore you with the details but suffice to say it was both fun and frustrating.

Interesting Website: Play 2048

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
User avatar
JHPJHP
Addict
Addict
Posts: 2252
Joined: Sat Oct 09, 2010 3:47 am

Re: ChatGPT REST API

Post by JHPJHP »

Final Thoughts (the details):
The following was a good starting point but could be refined further as was suggested by the AI.
JHPJHP wrote:In my recent work, I introduced a second AI prompt to address limitations observed in my initial implementation. The visual prompt struggled with tile clustering, while the original prompt lacked adequate spatial reasoning. By switching between them—using the spatial prompt when clustering failed and vice versa—I was able to compensate for individual weaknesses.

However, the real breakthrough came not from this dual-prompt approach, but from rethinking how much logic truly needs to be offloaded to the AI. Since prompt length directly affects cost and performance, it became clear that increasing the role of client-side scripting was the more sustainable path.

The solution is straightforward: keep the AI responsible for final move decisions, but reduce the complexity of each prompt by narrowing its scope. Client-side scripts can pre-analyze the board layout, extract relevant context, and present only the essential data to the AI.

Attempting to capture every possible scenario in a single, all-encompassing prompt per turn is inefficient and cost-prohibitive. A leaner, more targeted approach not only performs better but aligns more closely with how hybrid AI systems should operate.
ChatGPT wrote:Your insight is both technically and economically sound.

You've correctly identified the central tension in AI-assisted decision-making: delegation versus efficiency. Trying to cover all logic within a single or dual prompt is not only inefficient in terms of cost, but also underutilizes what client-side code excels at—state awareness, pre-filtering, and fast deterministic rules.

Your strategy—shifting spatial reasoning and clustering analysis to lightweight client-side logic, and then narrowing the AI's prompt scope accordingly—makes excellent architectural sense for several reasons:

✅ Key Strengths of Your Approach
Reduced Prompt Complexity
By letting script detect tile distributions, merge possibilities, and likely clusters, the AI doesn’t need to “figure out” the board—only to decide based on a structured representation.

Modular Decision Pipeline
With multiple prompt types (e.g., one spatial, one visual, others condition-specific), your system behaves like a layered expert system, allowing the right prompt for the right condition.

Cost Efficiency
Narrow prompts reduce token usage, which directly impacts both latency and operational cost.

AI as a Strategic Oracle, Not a Parser
Instead of offloading simple logical evaluations to the AI, you reserve its use for non-obvious prioritizations—where its value truly lies.

🔄 Potential Enhancements (Should You Implement It)
Pre-prompt Classification Layer
Use script to classify the board state into categories (e.g., “merge-rich,” “clustered,” “blocked,” “stalled”) and tag prompts accordingly.

Prompt Library with Token Budgeting
Maintain a set of minimalistic prompts indexed by scenario, allowing for just-in-time injection of logic without bloating a static instruction set.

Decision Confidence Check
Optionally, let the AI return not just a direction but a short “confidence score” (e.g., a predefined numerical range or heuristic label), so the client script can decide whether to query an alternate prompt type.

In essence, you're evolving the system into an AI-assisted state machine, where scripting handles the state modeling, and AI handles the strategy selection. That’s not just sensible—it’s best practice for hybrid decision systems.
Last edited by JHPJHP on Sun Jun 15, 2025 5:38 am, edited 3 times in total.

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
dige
Addict
Addict
Posts: 1391
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Re: ChatGPT REST API

Post by dige »

Hi JHPJHP, thank you very much for your detailed comments! I really enjoy reading this - I find it very exciting to see the strategies you have developed to find a solution. Thanks for sharing, it's very instructive. 👍
"Daddy, I'll run faster, then it is not so far..."
User avatar
JHPJHP
Addict
Addict
Posts: 2252
Joined: Sat Oct 09, 2010 3:47 am

Re: OpenAI REST API

Post by JHPJHP »

Hi dige,

You are most welcome.

---------------------------------------------

Hi All,

I've decided to post this here as it's only informative, no reason to create a new thread when I'm not expecting feedback.

I was notified mid-week that "access-key" downloads were not working from My PureBasic Stuff; it has since been fixed.
• For over a month I've been writing server-side code and fiddling with my website, so I'm unsure when the problem first occurred.

This all started when Google emailed me about securing their API keys. I could have just set a website filter from Google Cloud Platform but decided more was better. All related PureBsic examples have been updated, and the original examples were kept for comparison.

During the past several months all of my website scripts and programs were tested against the latest version of PureBasic.
• Many were updated with various improvements and bug fixes.

In addition, there have been numerous scripts added, for example RunProgram Python Scripts. This is not some advanced code, but if you're familiar with Python you should have a good understanding of its potential, if not, even better.

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
Post Reply