AI and Programming

avatar
(Edited)

Programming may seem like a foreign language to mere mortals (and it is, lol), but you know who is great with foreign languages? Well, a large language model, i.e. ChatGPT-like AIs. All of them I tried had no trouble understanding me in different languages or a combination of them (even in the same sentence), but they have various degrees of understanding figurative expressions.

For example, I tried the expression "batut in cap" in various LLMs, to see if they understand what it means. The only one which understood it was Bard, from Google. ChatGPT (3.5) had a vague idea it had a meaning other than the literal one but was dancing around the topic, and "Ask Leo" (from Brave) only understood the literal meaning, which is less likely to be used than the figurative one.

The literal meaning of that expression in my language is to be hit hard in the head, potentially causing long-lasting traumas. The figurative meaning is to be dumb.

But let's move on. You will see the power of ChatGPT in a different domain. Many of these LLMs' abilities depend on what they have been trained on and how large their language model is. The larger it is, the more resource-intensive it is.


Source

I started saying programming language is like a foreign language to many.

Like all languages actually, programming languages have clear base constructs that assemble to create complex syntax. And with them, you can write entire novels in natural languages or exceptional algorithms in programming.

Today, I've put ChatGPT's capability to generate code to the test.

After I asked ChatGPT if it is familiar with programming on the Hive blockchain and Hive-Engine, I asked it to create a script for me. It either didn't understand the request from the first prompt or wanted to create something simpler (which didn't match the request), but it only needed one more input to create this:

You: I was thinking about something a little different. Starting from various depletions of the voting power over different reward pools and various settings of the reward multipliers, adjust the latter, to converge to a balanced depletion of the voting power over the respective reward pools. This script should run once a day since the balancing process should be a continuous one.

ChatGPT: I understand the requirement for a continuous balancing process. Achieving a dynamic balance based on the depletion of voting power over different reward pools requires monitoring the current state and adjusting the reward multipliers accordingly. Here's a more complex example that aims to dynamically balance the reward multipliers based on the voting power depletion over time. This example assumes a linear adjustment, and you might need to fine-tune the algorithm based on your specific needs:

const hive = require('hive-js');

// Set your Hive username and private posting key
const username = 'your_username';
const postingKey = 'your_private_posting_key';

// List of tokens and their initial reward multiplier settings
const initialTokenSettings = [
  { symbol: 'TOKEN1', multiplier: 1.0 },
  { symbol: 'TOKEN2', multiplier: 0.8 },
  // Add more tokens as needed
];

// Function to get the current voting power percentage for a given account
async function getVotingPower(account) {
  const accountInfo = await hive.api.getAccountsAsync([account]);
  const votingPower = accountInfo[0].voting_power / 100;
  return votingPower;
}

// Function to adjust reward multiplier for a specific token
async function adjustTokenMultiplier(tokenSymbol, multiplier) {
  const customJsonData = {
    id: 'ssc-mainnet-hive',
    json: {
      contractName: 'tokens',
      contractAction: 'setSettings',
      contractPayload: {
        symbol: tokenSymbol,
        settings: {
          rewardsMultiplier: multiplier,
        },
      },
    },
  };

  const result = await hive.broadcast.customJson(
    postingKey,
    [username],
    [],
    'ssc-mainnet-hive',
    JSON.stringify(customJsonData)
  );

  console.log(`Adjusted ${tokenSymbol} multiplier to ${multiplier}: ${result.result}`);
}

// Function to balance reward multipliers based on voting power depletion
async function balanceRewardMultipliers() {
  const targetVotingPower = 80; // Target voting power percentage for balancing
  const adjustmentFactor = 0.02; // Adjustment factor for multiplier changes

  for (const { symbol, multiplier } of initialTokenSettings) {
    const currentVotingPower = await getVotingPower(username);

    // Calculate the required adjustment based on the difference from the target voting power
    const adjustment = (targetVotingPower - currentVotingPower) * adjustmentFactor;

    // Apply the adjustment to the current multiplier
    const newMultiplier = Math.max(0.1, multiplier + adjustment); // Ensure multiplier doesn't go below 0.1

    // Adjust the token multiplier
    await adjustTokenMultiplier(symbol, newMultiplier);
  }

  console.log('Reward multipliers balanced successfully!');
}

// Run the script
balanceRewardMultipliers();

In this example:

  • The script retrieves the current voting power percentage for the account.
  • It calculates the required adjustment for each token based on the difference from the target voting power (80% in this case).
  • The adjustment is applied to the current multiplier, and the new multiplier is calculated.
  • The script then adjusts the token multiplier using the adjustTokenMultiplier function.
  • This script should be scheduled to run once a day to continuously balance the reward multipliers based on the voting power depletion. Adjust the targetVotingPower and adjustmentFactor values as needed for your specific scenario.

First impression: it looks damn impressive that piece of script generated from the prompt I've given it (and the previous one), even though it might or might not work (haven't tested it yet).

The best thing is that it gives a programmer a draft to work with. A few tweaks, and, if the bulk of the script works, then you have a working tool.

What are my conclusions after this experiment:

  • ChatGPT is far more powerful than most people may think, for generating code
  • someone with at least a background in programming is needed to see when the AI doesn't understand the request and outputs something else than you want
  • the code needs to be checked for logical flaws, the type of error an LLM AI can make frequently in complex scenarios
  • the code is not guaranteed to work, and if it doesn't, someone needs to debug and test it; maybe with the right guidance, the AI itself

Final conclusion: devs are still needed, but AI could become a very strong tool in their hands for the future of code creation, especially for non-critical coding elements!


Want to check out my collection of posts?

It's a good way to pick what interests you.

Posted Using InLeo Alpha

Posted Using InLeo Alpha



0
0
0.000
30 comments
avatar

you gave me an idea!

crezi ca pot face un script care sa publice un post pe zi la ora si data care doresc? eu cred ca nu, dar sa vedem ce zice robotul.

0
0
0.000
avatar

Sunt sigur ca iti va gasi o solutie. Dar sa ai grija daca vrei sa-ti automatizezi postarile zilnice. In general, nu prea sunt apreciate.

0
0
0.000
avatar
(Edited)

Nu, ma gandeam sa scriu 2-3 posturi cand am zi libera, si sa publice unul pe zi, cand sunt la munca, ca lucrez ture lungi. Ceva de genul.

Voting and curation is already automatized following trails and people who I follow.

0
0
0.000
avatar

Pai poti sa le programezi (schedule). PeakD are optiunea asta. INLEO are si ea. Poate si alte platforme, dar nu folosesc.

Sau le lasi ca draft-uri si le publici cand ajungi acasa in ziua respectiva.

0
0
0.000
avatar
(Edited)

Asa fac acum, le las draft si public dimineata, inainte sa plec. O sa verific Peakd sa vad cum functioneaza schedule, ca probabil asta e functia pe care o vreau. Mersi de sfat.

0
0
0.000
avatar

ChatGPT's capability to generate code to the test

With CHatGPT, its easy to get the code and later fix it by removing bugs. It saves time and many developers at my workplace follow this practice now

0
0
0.000
avatar

Yes, by the looks of it, it saves A LOT of time. Unless it introduces complicated bugs that are hard to track. But for small parts that are easy to debug or for code that isn't complicated and doesn't touch critical components and is write-intensive, I see AI as the best helper possible.

0
0
0.000
avatar

Personally, I used it for the coding portion, it really shorten the time needed for me to go search around for codes.

0
0
0.000
avatar

Nice! With this kind of help, the jobs of devs become easier. But that also lowers the entry bar into the domain and increases competition, at least among certain categories of devs.

0
0
0.000
avatar

Engineers are about to get burned by AI too.

0
0
0.000
avatar

At this point, it seems AI still needs qualified supervision and guidance. But the productivity growth is impressive, so this alone can burn a good number of jobs. In the future, it might not need as much hand-holding, which will probably terminate another wave of jobs. Yeah, people will need a mentality shift, for sure, or they'll become dependent on something like a UBI.

0
0
0.000
avatar

The codes are looking confusing, lol
Maybe because I don’t know anything about codes though…

0
0
0.000
avatar

Yeah, as I said, to a non-developer or someone without a coding background, it's like a foreign language.

0
0
0.000
avatar

Congratulations @gadrian! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s)

You made more than 17000 comments.
Your next target is to reach 18000 comments.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

To support your work, I also upvoted your post!

Check out our last posts:

It's the Christmas season: give your friends a gift
0
0
0.000
avatar

Thanks for your contribution to the STEMsocial community. Feel free to join us on discord to get to know the rest of us!

Please consider delegating to the @stemsocial account (85% of the curation rewards are returned).

You may also include @stemsocial as a beneficiary of the rewards of this post to get a stronger support. 
 

0
0
0.000
avatar

That is the reason why a lot of programmers are losing jobs. I've heard of scenarios where companies fired a lot of their programmers, left one senior programmer, and hired a person good with Generative AI prompts. They can create the code, and the senior programmer just checks it or tweaks it until it works perfectly.

0
0
0.000
avatar

Yeah, that is a likely scenario, because productivity with the AI grows. I still wouldn't let it code anything critical, even if the code is overviewed afterwards by a senior dev.

0
0
0.000
avatar

With the way the world is really advancing, I will actually not be surprised if the world is moving to a point where Artificial intelligence is making some programming

0
0
0.000
avatar

Artificial intelligence is making some programming

It already is. I just gave it a task and it produced the script. It still needs supervision, but it's a massive productivity boost. And others commented that AI is already being used in programming firms.

0
0
0.000
avatar

I think it can be a very helpful tool for beginners who have a general or basic knowledge about coding. Most of the heavy lifting can be done by the AI tool and the process can be streamlined. I wonder if it will be able to teach a person to code from scratch.

0
0
0.000
avatar

I think it can be a very helpful tool for beginners who have a general or basic knowledge about coding. Most of the heavy lifting can be done by the AI tool and the process can be streamlined.

Apparently, it is already used heavily in production by software companies too, so the next level from basic coding. I kind of lost contact with them, but it seems like an evolution to be expected.

I wonder if it will be able to teach a person to code from scratch.

I think it can do great teaching someone the basics of coding. Like in real life, a student would learn quicker and deeper by asking enough questions. Unlike the real life, sometimes, the teacher will not mind the avalanche of questions.

0
0
0.000
avatar

AI is definitely improving a lot. That code can be basis for a lot of things and even if there are issues, you can fix them starting from there. Having an extra person to talk to might also make the debugging process easier. So I think it's kind of amazing to see how things are going

0
0
0.000
avatar

Absolutely! I was almost speechless when I saw the second script. If it was its logic producing it from the prompt (practically instantaneously), the programming world would be massively revolutionized (and seems like it is already by reading the comments).

0
0
0.000
avatar

Many of these LLMs' abilities depend on what they have been trained on and how large their language model is. The larger it is, the more resource-intensive it is.

Which model did you use?
I think when you use chatGPT4 Premium it calls on a different (more specialized) LLM to help it with code.

devs are still needed, but AI could become a very strong tool in their hands for the future of code creation, especially for non-critical coding elements!

Generally and in terms of programming I have found out that you get better results, when you give it more context.
If you mock up a function as context and then tell it what you want the function to do, it does a much better job. And you get something that you could integrate much better into your existing design, because it sticks to the same style, etc.

The other day I got stuck at something, and asked chatGPT where the error was and it told me to use deepCopy instead of copy and it worked... That saved me hours of trouble and research... I was on the right track, but misunderstood how copy or assign() worked. It even gave me some explanations and taught me something. It also complimented me, and told me I was doing well. 😅 felt good.

I think current models aren't really good enough to code up an entire app for you, but if you give it a very specific task or problem with enough context it can reliably save you a bunch of time and headache.

0
0
0.000
avatar

Which model did you use?
I think when you use chatGPT4 Premium it calls on a different (more specialized) LLM to help it with code.

I used the free GPT 3.5 version. I'm sure they offer version 4 for premium members. And when it's ready, version 5. Maybe then, version 4 will become free for personal use.

If you mock up a function as context and then tell it what you want the function to do, it does a much better job. And you get something that you could integrate much better into your existing design, because it sticks to the same style, etc.

That's good to know for future interactions I'll have with it. Thanks!

The other day I got stuck at something, and asked chatGPT where the error was and it told me to use deepCopy instead of copy and it worked...

Yep, I heard others using it for debugging too. I've also seen used to ask for ways to optimize a specific code and it gave very good solutions.

It also complimented me, and told me I was doing well. 😅 felt good.

That's a bit scary. 😄 Feels too much like what a human would do.

I think current models aren't really good enough to code up an entire app for you, but if you give it a very specific task or problem with enough context it can reliably save you a bunch of time and headache.

Absolutely! Right now, it's more of a great tool to have and improve productivity, but their evolution is exponential.

0
0
0.000
avatar

Thanks @gadrian for you post on AI programming. It looks really good what the chat bot posted. Are you going to test it? Have an nice weekend and enjoy your days off! Barb #ctp

0
0
0.000
avatar

Are you going to test it?

Probably after Christmas when I get back. Merry Christmas in advance since I won't post until Tuesday or Wednesday.

0
0
0.000
avatar

Time has changed we have to read about all these new technologies and get information if we want to live our future life well.

0
0
0.000
avatar

That is true. We need to adapt to the changing times. Most people will, but at different paces.

0
0
0.000