Artificial Intelligence, translate developing Json code in a human reading applications
Have you ever encountered a situation where you come across an entire code, but it lacks any manual, explanations, or anything that would help you understand its purpose within a short span of time? This occurrence is quite familiar to both me and many of my colleagues. On a daily basis, we find ourselves needing to translate information for team collaborations or to provide updates for ongoing projects and software enhancements.
In one of my recent projects, MineoCrypto, I had consistent access to cryptocurrency information, such as exchange rates between two coins (e.g., Bitcoin to Dollar or vice versa), which was presented in a format like JSON.
I bet, how many minutes do you need, if you have experience, to understand what is going on here !?
So, I decided to build a phyton software, able to translate wherever code is into a Human readable, fast and well written and sharable where I need.
The code is written below:
{"RAW":{"MARKET":"CUSTOMAGG","FROMSYMBOL":"BTC","TOSYMBOL":"USD","FLAGS":"1","PRICE":29736.8,"LASTUPDATE":1691514083,"LASTVOLUME":0.00154141,"LASTVOLUMETO":45.8319612439,"LASTTRADEID":"191148157077","VOLUME24HOUR":12087.57619042,"VOLUME24HOURTO":354721272.757272,"OPEN24HOUR":28937.71,"HIGH24HOUR":29814.31,"LOW24HOUR":28933.12,"LASTMARKET":"Gemini","TOPTIERVOLUME24HOUR":12087.57619042,"TOPTIERVOLUME24HOURTO":354721272.757272,"CHANGE24HOUR":799.0900000000001,"CHANGEPCT24HOUR":2.7614140856342817,"CHANGEDAY":0,"CHANGEPCTDAY":0,"CHANGEHOUR":0,"CHANGEPCTHOUR":0},"DISPLAY":{"FROMSYMBOL":"Ƀ","TOSYMBOL":"$","MARKET":"CUSTOMAGG","PRICE":"$ 29,736.8","LASTUPDATE":"Just now","LASTVOLUME":"Ƀ 0.001541","LASTVOLUMETO":"$ 45.83","LASTTRADEID":"191148157077","VOLUME24HOUR":"Ƀ 12,087.6","VOLUME24HOURTO":"$ 354,721,272.8","OPEN24HOUR":"$ 28,937.7","HIGH24HOUR":"$ 29,814.3","LOW24HOUR":"$ 28,933.1","LASTMARKET":"Gemini","TOPTIERVOLUME24HOUR":"Ƀ 12,087.6","TOPTIERVOLUME24HOURTO":"$ 354,721,272.8","CHANGE24HOUR":"$ 799.09","CHANGEPCT24HOUR":"2.76","CHANGEDAY":"$ 0","CHANGEPCTDAY":"0","CHANGEHOUR":"$ 0","CHANGEPCTHOUR":"0"}}
become:
- Market: customaggregation
- From Symbol: BTC (Bitcoin)
- To Symbol: USD (United States Dollar)
- Price: $29,736.8
- Last update: Just now
- Last volume: 0.00154141 BTC
- Last volume to: $45.83
- Last trade ID: 191148157077
- 24-hour volume: 12,087.57619042 BTC
- 24-hour volume to: $354,721,272.757272
Summary:
.This page provides real-time data on the price and market statistics of BTC (Bitcoin) against USD (United States Dollar).
.The current price is $29,736.8 per BTC, with the last update occurring just now.
.The last traded volume was 0.00154141 BTC, equivalent to $45.83.
.The 24-hour volume for BTC is 12,087.57619042 BTC, amounting to $354,721,272.757272. The market for this trade was Gemini.
.The change in price over the past 24 hours is $799.09, indicating a 2.76% increase. .There have been no changes in price over the day or hour.
.This page provides a comprehensive and up-to-date overview of BTC's performance in the market.
The software “translates” in a few seconds!
how did I do? Nothing special, just a bit of fantasy :)
What is a Json
JSON stands for "JavaScript Object Notation." It is a lightweight data-interchange format that is easy for humans to read and write, and it's also easy for machines to parse and generate. JSON is commonly used to transmit data between a server and a web application, as well as for configuration files and other types of structured data storage.
JSON is designed to be a language-independent format, which means it can be used with a wide range of programming languages. It's based on a subset of the JavaScript programming language, but it's not limited to just JavaScript.
JSON data is structured as a collection of key-value pairs, where each key is a string and each value can be a string, number, boolean, null, object, or array. Here's a simple example of JSON data:
{
"name": "John Doe",
"age": 30,
"isStudent": false,
"hobbies": ["reading", "swimming", "painting"]
}
In this example, we have an object with four key-value pairs: "name," "age," "isStudent," and "hobbies." The "name" and "age" values are strings and a number respectively, "isStudent" is a boolean, and "hobbies" is an array of strings.
JSON is widely used because of its simplicity and compatibility with many programming languages and systems.
It's often used in APIs (Application Programming Interfaces) for data exchange between servers and clients, as well as for storing configuration settings and other structured data.
What did I Build:
In PHP, inside our environment already prepared for single-sign-on, I use the ChatGpt text-davinci-003 with these settings:
"model": "text-davinci-003",
"max_tokens": 4000,
"temperature": 1,
"top_p": 1
obviously, the URL of the completion is https://api.openai.com/v1/completions
Once you have the connectors prepared I used the prompt to summarize the page link that I scrapped from the website content and used in a web environment
What is a scraping/scraper website:
A scraper website, also known as a web scraper or web scraping tool, is a software application or script designed to extract information from websites automatically and in large quantities. The primary purpose of a scraper website is to gather data from various online sources for purposes such as data analysis, research, data mining, price comparison, content aggregation, and more.
These scraper tools work by sending requests to web servers, retrieving the HTML content of web pages, and then parsing and extracting the desired information from the HTML. This information can include text, images, links, and other structured data. Scraper websites can be programmed to target specific elements on web pages, such as headlines, product prices, reviews, or any other data that is publicly accessible on the internet.
Legitimate uses of web scraping include:
Data Aggregation: Gathering data from various sources to create comprehensive datasets.
Price Comparison: Collecting pricing information from different e-commerce websites.
Market Research: Analyzing trends and sentiment from user reviews and comments.
News Aggregation: Aggregating news articles from multiple sources.
Social Media Monitoring: Tracking mentions and engagement on social media platforms.
It's crucial to use web scraping responsibly and in accordance with the terms of use of the websites you're scraping from. Some websites might provide APIs (Application Programming Interfaces) that offer a more structured and sanctioned way to access their data.
Always respect copyright, intellectual property rights, and privacy concerns when engaging in web scraping activities.
A bit of PHP CODE
Let’s break down the code:
Initializing cURL: The code starts by initializing a cURL session using
curl_init()
. cURL (Client URL) is a library and command-line tool for transferring data with URLs.Setting cURL Options: The
curl_setopt_array()
function is used to set multiple cURL options at once. This function configures various settings for the cURL session. Let's go through the options being set:CURLOPT_URL
: Specifies the URL to which the cURL request will be sent, in this case, the OpenAI API's endpoint for completions.CURLOPT_RETURNTRANSFER
: Tells cURL to return the response as a string instead of directly outputting it.CURLOPT_ENCODING
: Specifies the encoding to accept (blank means accept any encoding).CURLOPT_MAXREDIRS
: Maximum number of redirects to follow.CURLOPT_TIMEOUT
: Maximum time the cURL request is allowed to take (0 means no timeout).CURLOPT_FOLLOWLOCATION
: Enables automatic following of redirects.CURLOPT_HTTP_VERSION
: Specifies the HTTP version to use.CURLOPT_CUSTOMREQUEST
: Sets the HTTP request method to POST.CURLOPT_POSTFIELDS
: Contains the JSON data that will be sent in the POST request. It specifies the parameters for the AI model.CURLOPT_HTTPHEADER
: An array of HTTP headers to send with the request, including the authorization header (API key) and content type.
Executing cURL Request: The
curl_exec()
function is called to execute the cURL request with the configured options. The response from the API is stored in the$response
variable.Closing cURL:
curl_close($curl)
is used to close the cURL session and release any associated resources.Outputting and Parsing Response: The response from the API, which is in JSON format, is printed out using
print_r()
within an HTML<pre>
tag. This makes the JSON response more readable in the browser.Parsing JSON Response: The JSON response is decoded using
json_decode()
, and the resulting object is stored in the$obj
variable.Iterating through Choices: The code uses a
foreach
loop to iterate through thechoices
array within the$obj
object. Eachchoice
represents a generated text by the AI model.Extracting and Outputting Generated Text: Within the loop, the generated text from each choice is extracted using
$code->text
and stored in the$content_ai
variable. The generated text is then echoed to the output.
And not the end
I used to integrate also the functionality in a Chrome application (chatgpt summarize)
This is the result, check the video below
The possibilities are infinite, extending beyond just JSON/cryptocurrency. You can quickly translate any code that you consider important, without requiring any manual intervention.
Another way we utilize this capability is by our connector fixed with the daily technical summaries in Slack and Trello Channels, allowing the team to read and analyze data without hindering productivity.