Programming with OpenAi / ChatGPT & CloudFlare Workers
As technology evolves, it's becoming easier for businesses and individuals to build custom software applications to meet their specific needs. However, this requires a particular technical skill and expertise, which can be a barrier to entry for many people.
Fortunately, with OpenAI prompts, you can build software quickly and efficiently, even with little knowledge of how to program.
I put this tutorial for those looking to develop software quickly and efficiently using OpenAi. I was able to build an entire API proxy for our telegram bot in less than an hour. If I had been doing this traditionally, it would have taken me days or longer.
For longer code, use the OpenAi Playground; for shorter code bits, use the ChatGPT interface.
What are OpenAI Prompts?
OpenAI Prompts are pre-trained models that generate text based on input. The models are trained on a massive amount of text data and can develop a wide range of outputs, including code snippets, articles, and even complete software applications. By using OpenAI prompts, you can generate code quickly and easily without needing to understand the underlying programming concepts.
Knowledge
For more complicated applications, programming knowledge is required. This is probably a more complex app, but the concept works for more simple applications.
I use Microsoft VS-Code with its built-in Co-pilot and ChatGPT extensions to help bug test and audit the output code for issues. Let's be clear, the code could be better and often gives code with minor problems that need to fix. Luckily VS-Code does a great job of finding any issues with the structure or missing elements. You can use things like Co-pilot to find and fix those also.
GitHub Co-Pilot is a feature offered by GitHub that provides real-time AI-powered suggestions and recommendations as you work on your coding projects. The AI-powered tips help to streamline your work and reduce the amount of time you spend searching for solutions to coding problems. It works by analyzing your code and providing recommendations for improved or optimized syntax and functions, as well as quick links to relevant documentation. It also helps you identify potential issues and provides suggestions for fixing them. With GitHub Co-Pilot, you can write code more efficiently and effectively, even with limited programming experience.
Using OpenAI Prompts with Cloudflare Workers
Cloudflare Workers are serverless functions that run on Cloudflare's edge network. They allow you to execute code close to your users, making your application faster and more scalable. Using OpenAI prompts with Free Cloudflare Workers, you can quickly and easily build custom software applications without worrying about managing servers or scaling infrastructure. Combing serverless and Ai is a match made in heaven.
How to Use OpenAI Prompts with Cloudflare Workers
Here's a step-by-step guide to building software with OpenAI prompts and Cloudflare Workers:
Determine the problem you want to solve
Before you start building software, you must understand the problem you're trying to solve. What are the requirements for your application, and what are the end goals you're trying to achieve?
Generate code snippets with OpenAI Prompts
Once you know what you're trying to build, you can use OpenAI prompts to generate code snippets to help you achieve your goals. You can input specific requirements into the OpenAI prompt, and it will generate code that meets those requirements.
Make sure to ask for smaller functional components rather then the entire application. The following is just the proxy portion of a larger Telegram bot application.
Make sure to be as clear and concise as possible. Don't leave any room for the Ai to "guess," or it could give you some crazy or useless code.
领英推荐
Example Prompt:
Create a cloudflare script that stores incoming telegram bot webhooks post json to the cloudflare keyvalue store {insert value} using the using update_id value from the telegram webhook json as the key. Post the complete json request as the value using the cloudflare api POST type.
Add an additional timestamp appended to the json saved to the keystore value.
The script should then repost the original incoming webhook to the {insert url example} url using the curl example provided below.
Save any errors posting to the awardpool api to the keyvalue store {keystore value} using the cloudflare api. The key should be the timestamp the value, should there be an error and the update_id from the json posted.
Use switch and case to handle the api calls.?
Don't use any external modules.
Make sure to create the script as a compatible with CloudFlare worker.
Output each function step by step with a brief explaination of the code.
Use the following Sample Code for keyvalue?{insert key value}
? ? ? ? ? ? let apiKey = "value"
? ? ? ? ? ? let response = await fetch(`https://api.cloudflare.com/client/v4/accounts/{accountid}/storage/kv/namespaces/{keyvalue}/values/${uid}`, {
? ? ? ? ? ? ? ? method: "PUT",
? ? ? ? ? ? ? ? headers: {
? ? ? ? ? ? ? ? ? ? "Content-Type": "text/plain",
? ? ? ? ? ? ? ? ? ? "X-Auth-Email": "username",
? ? ? ? ? ? ? ? ? ? "X-Auth-Key": apiKey
? ? ? ? ? ? ? ? },
? ? ? ? ? ? ? ? body: JSON.stringify({ "uid": uid, "value": combination })
? ? ? ? ? ? });;
Use Sample Curl API for a post to the endpoint
curl -i -X POST
? ?-H "Content-Type:application/json" \
? ?-d \
'{
? ? "update_id": 123,
? ? "message": {
? ? ? ? "message_id": 123,
? ? ? ? "from": {
? ? ? ? ? ? "id": 123,
? ? ? ? ? ? "is_bot": false,
? ? ? ? ? ? "first_name": "rUv",
? ? ? ? ? ? "username": "ruv_c",
? ? ? ? ? ? "language_code": "en"
? ? ? ? },
? ? ? ? "chat": {
? ? ? ? ? ? "id": 123,
? ? ? ? ? ? "first_name": "rUv",
? ? ? ? ? ? "username": "ruv_c",
? ? ? ? ? ? "type": "private"
? ? ? ? },
? ? ? ? "date": 1675305577,
? ? ? ? "voice": {
? ? ? ? ? ? "duration": 1,
? ? ? ? ? ? "mime_type": "audio/ogg",
? ? ? ? ? ? "file_id": "AwACAgEAAxkBAAIJd2PbLCv7BiLgXnFKqc6S-Hc9w41EAAJYAwACGI3hRp-CEmB4NcQ5LgQ",
? ? ? ? ? ? "file_unique_id": "AgADWAMAAhiN4UY",
? ? ? ? ? ? "file_size": 6779
? ? ? ? },
? ? ? ? "text": "/help",
? ? ? ? "entities": [
? ? ? ? ? ? {
? ? ? ? ? ? ? ? "offset": 0,
? ? ? ? ? ? ? ? "length": 5,
? ? ? ? ? ? ? ? "type": "bot_command"
? ? ? ? ? ? }
? ? ? ? ]
? ? }
}' \
?'{apiendpointurl}'\
Create a Cloudflare Worker
With your code snippets generated, it's time to create a Cloudflare Worker. You can use the code snippets generated by OpenAI prompts to build out your Cloudflare Worker.
Deploy your Cloudflare Worker
You can also get OpenAi to guide you through deploying your code or copy and paste it into the CloudFlare worker dashboard.
Once your Cloudflare Worker is complete, you can deploy it to the Cloudflare edge network. This will make your application faster and more scalable without worrying about managing servers or scaling infrastructure.
Building custom software applications can be a challenging task, especially for people with little programming knowledge. However, with OpenAI prompts and Cloudflare Workers, you can build software quickly and efficiently without needing to understand the underlying programming concepts. Using these tools, you can achieve your goals faster and more efficiently without sacrificing performance or scalability.
In summary, Ai takes ok programmers and makes them good. Good programmers, great and great programmers, mind-blowing geniuses.
Market Research | B2B | Web developer |
2 年Great job! Thank you for sharing!
Empowering Enablement
2 年Josh Crosby ??
STEM.org (CTO) | #GiveFirst ?? Techstars Mentor | Building with ?????????? ??????????????????. Helping democratize education and tech. | Mental Health | Sports Philanthropy | #Rugby #Esports #EdTech #SportsTech #STEAM
2 年Great share, thank you!
CTO at EY Americas
2 年Nice - thank you for sharing. This conversational programming model is going to fun to watch as it evolves quickly.
Excellent work. Really, really helpful.