ChatGPT API examples & templates
Calorie Count via Photo
Uploads your photo to ChatGPT's new vision model to automatically categorize the food and estimate the calories.
CronGPT
This is a minisite to help you create cron expressions, particularly for crons on Val Town. It was inspired by Cron Prompt, but also does the timezone conversion from wherever you are to UTC (typically the server timezone).
Tech
- Hono for routing (
GET /
andPOST /compile
.) - Hono JSX
- HTML (probably overcomplicates things; should remove)
- @stevekrouse/openai, which is a light wrapper around @std/openai
TODO
- simplify by removing HTMX (try doing the form as a GET request, manual JS script, or client side react)
- make the timezone picker better (fewer options, searchable)
- add a copy button?
CronGPT
This is a minisite to help you create cron expressions, particularly for crons on Val Town. It was inspired by Cron Prompt, but also does the timezone conversion from wherever you are to UTC (typically the server timezone).
Tech
- Hono for routing (
GET /
andPOST /compile
.) - Hono JSX
- HTML (probably overcomplicates things; should remove)
- @stevekrouse/openai, which is a light wrapper around @std/openai
CronGPT
This is a minisite to help you create cron expressions, particularly for crons on Val Town. It was inspired by Cron Prompt, but also does the timezone conversion from wherever you are to UTC (typically the server timezone).
Tech
- Hono for routing (
GET /
andPOST /compile
.) - Hono JSX
- HTMX (probably overcomplicates things; should remove)
- @stevekrouse/openai, which is a light wrapper around @std/openai
I'm finding HTMX a bit overpowered for this, so I have two experimental forks without it:
- Vanilla client-side JavaScript: @stevekrouse/cron_client_side_script_fork
- Client-side ReactJS (no SSR): @stevekrouse/cron_client_react_fork
I think (2) Client-side React without any SSR is the simplest architecture. Maybe will move to that.
OpenAI ChatGPT helper function
This val uses your OpenAI token if you have one, and the @std/openai if not, so it provides limited OpenAI usage for free.
Create valimport { chat } from "https://esm.town/v/stevekrouse/openai";
const { content } = await chat("Hello, GPT!");
console.log(content);
Create valimport { chat } from "https://esm.town/v/stevekrouse/openai";
const { content } = await chat(
[
{ role: "system", content: "You are Alan Kay" },
{ role: "user", content: "What is the real computer revolution?"}
],
{ max_tokens: 50, model: "gpt-4" }
);
console.log(content);
Code from https://deno.com/blog/build-image-resizing-api
Useful for compressing an image before sending to chatgpt4v, for example
Doesn't seem to work on val.town, should work in principle
OpenAI ChatGPT helper function
This val uses your OpenAI token if you have one, and the @std/openai if not, so it provides limited OpenAI usage for free.
Create valimport { chat } from "https://esm.town/v/stevekrouse/openai";
const { content } = await chat("Hello, GPT!");
console.log(content);
Create valimport { chat } from "https://esm.town/v/stevekrouse/openai";
const { content } = await chat(
[
{ role: "system", content: "You are Alan Kay" },
{ role: "user", content: "What is the real computer revolution?"}
],
{ max_tokens: 50, model: "gpt-4" }
);
console.log(content);
Add an email entry option to your static website/blog. Easy peasy. 🚀
PoV: You just hacked together a portfolio website or launched a blog as a static website. Some people who visit might be interested in hearing more from you. ❤️ But you don't want to get lost building your backend, API, DB or fancy apps like SubstandardStack or MailMachineGun for people to sign up to your newsletter. 😩
All you want is a simple input box on your website - when someone types their email
, username
or social link
in and submits it, you want to be notified.
psst...do you want another one that uses the DB instead of email so you can look up all entries at once? Let me know and I'll get cooking!
Quickstart
Call the val URL with data in the query param userContact
. That's it!
// Format
`https://<val_url>?userContact=<mandatory_primary_contact>`
// Examples
`https://dvsj-subscribeToNewsletter.web.val.run?userContact=dav.is@zohomail.in`
`https://dvsj-subscribeToNewsletter.web.val.run?userContact=CatalanCabbage`
Bonus
Have extra data apart from email?
Pass any encoded data in the queryParam userData
, will be included in the email. It's optional.
// Format
`https://<val_url>?userContact=<mandatory_primary_contact>&userData=<optional_any_data>`
//Examples
`https://dvsj-subscribeToNewsletter.web.val.run?userContact=dav.is@zohomail.in&userData={"time": "2/2/1969", "twitter": "https://twitter.com/dvsj_in"}`
// Note: All values should be URL encoded. Example:
let userData = {"time": "2/2/1969", "twitter": "https://twitter.com/dvsj_in"}
let encodedUserData = encodeURIComponent(userData) //This should go in the query param
Want bot protection?
Add a simple question to your website, like "okay, so what's one minus one?"
.
In the val, set isBotProtectionOn = true
and botProtectionAnswer="0"
.
When you call the val, include the encoded user's answer to the bot question as botProtection
query param.
Answer will be compared with botProtectionAnswer
; if the answer is wrong, the request is rejected.
// Format
`https://<val_url>?userContact=<mandatory_primary_contact>&userData=<optional_any_data>&botProtection=<answer>`
//Examples
`https://dvsj-subscribeToNewsletter.web.val.run?userContact=dav.is@zohomail.in&botProtection=123`
Add it to your website
Want to add it to your site but get a headstart coding it? Use this ChatGPT prompt to get code for your website!
I'm building a simple form submission component. It should a submit button and these 2 input boxes:
1. "userContact" to get the user's email (mandatory)
2. "userData" to get a custom message from the user (optional)
On clicking the submit button:
1. Both input values should be encoded using "encodeURIComponent"
2. A GET URL should be built in this format with query params. Include userData query param only if input is not null or empty.
`https://dvsj-subscribeToNewsletter.web.val.run?userContact=<encodedUserContact>&userData=<encodedUserData>`
3. The GET URL should be called and result printed in the console.
I'm using React, so make it a react component.
OpenAI ChatGPT helper function
This val uses your OpenAI token if you have one, and the @std/openai if not, so it provides limited OpenAI usage for free.
Create valimport { chat } from "https://esm.town/v/stevekrouse/openai";
const { content } = await chat("Hello, GPT!");
console.log(content);
Create valimport { chat } from "https://esm.town/v/stevekrouse/openai";
const { content } = await chat(
[
{ role: "system", content: "You are Alan Kay" },
{ role: "user", content: "What is the real computer revolution?"}
],
{ max_tokens: 50, model: "gpt-4o" }
);
console.log(content);