Posts

AI and Programming

30 comments·0 reblogs
gadrian
25
·
0 views
·
4 min read

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.

Image from thread
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