<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Harshit Kedia</title>
    <description>The latest articles on Forem by Harshit Kedia (@harshit_kedia).</description>
    <link>https://forem.com/harshit_kedia</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F994068%2Fe99f42a2-5aae-452d-916a-741e81465cf3.jpeg</url>
      <title>Forem: Harshit Kedia</title>
      <link>https://forem.com/harshit_kedia</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/harshit_kedia"/>
    <language>en</language>
    <item>
      <title>Idea for a Bitcoin wallet backup service that is non-custodial and fully respects self-sovereignty and privacy</title>
      <dc:creator>Harshit Kedia</dc:creator>
      <pubDate>Sat, 21 Feb 2026 12:36:17 +0000</pubDate>
      <link>https://forem.com/harshit_kedia/idea-for-a-bitcoin-wallet-backup-service-that-is-non-custodial-and-fully-respects-self-sovereignty-1e9g</link>
      <guid>https://forem.com/harshit_kedia/idea-for-a-bitcoin-wallet-backup-service-that-is-non-custodial-and-fully-respects-self-sovereignty-1e9g</guid>
      <description>&lt;p&gt;The ethos of Bitcoin is "Not your keys, not your coins." But the terrifying reality for most people is: "Lose your keys, lose your life savings."&lt;/p&gt;

&lt;p&gt;We are biological beings. We forget passwords, our houses catch fire, we make mistakes, and eventually, we die. Humans are messy, and that’s okay.&lt;/p&gt;

&lt;p&gt;Banks were originally invented to solve this problem—to provide physical security for our assets when we couldn't protect them ourselves. Today, we reject banks because of custody and censorship risks. But what if we could use the &lt;strong&gt;Bank's infrastructure&lt;/strong&gt; (Identity Verification) without giving them &lt;strong&gt;Custody&lt;/strong&gt; of our coins?&lt;/p&gt;

&lt;p&gt;I have thought of a protocol architecture that uses &lt;strong&gt;BitVM&lt;/strong&gt;, &lt;strong&gt;Smart Contracts&lt;/strong&gt;, and &lt;strong&gt;Bank Wire Memos&lt;/strong&gt; to create a non-custodial backup system. It allows for inheritance, recovery, and protection against both hackers and rogue companies. This same concept can be applied to protect the user's Nostr keys, or for that matter, any confidential information.&lt;/p&gt;

&lt;p&gt;I want to share the architecture and the mitigation of specific threat possibilities - User vs. Company, Company vs. User, and Government vs. User.&lt;/p&gt;

&lt;h1&gt;
  
  
  The Workflow: Using the Bank as a "Dumb Pipe"
&lt;/h1&gt;

&lt;p&gt;We don't need to partner with banks. We just need to use their output. Banks have already done the heavy lifting of verifying that you are a real human (KYC). We just need to use their public ledger. A Wire Transfer is a cryptographic signal that links a physical identity to a digital action. While I am focusing on wire transfer, note that here we can use other means like Notarized Affidavit, Personal Cheques, etc. also in place of or along with wire transfer to verify identity and create a paper trail.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phase 1: The Binding (Safety&lt;/strong&gt; &lt;strong&gt;&lt;em&gt;Before&lt;/em&gt;&lt;/strong&gt; &lt;strong&gt;Key Generation)&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;The Handshake:&lt;/strong&gt; You connect a new Wallet (Hardware wallet preferred for security, but Software wallet works too) to the Backup Service Company's open-source client via internet. An End-to-End Encrypted (E2EE) tunnel is established.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Code:&lt;/strong&gt; The Wallet displays an &lt;strong&gt;8-10 digit code&lt;/strong&gt; on its screen. This is a hash of the current session.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Signal:&lt;/strong&gt; You visit your bank for a wire transfer. You send a "Dust" wire transfer (e.g., $1.00) to the Service' bank account. In principle, the backup service should reject wires which came with "Online Transfer" tag in consideration of the risk of hack of the user's net banking account.

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;Crucial Step:&lt;/em&gt; In the &lt;strong&gt;Memo Field&lt;/strong&gt;, you enter that 8-10 digit code.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Verification:&lt;/strong&gt; The Service receives the wire. The employees see "John Doe" sent $1.00 with the correct code. They now know: &lt;em&gt;"The person controlling John Doe's bank account is the person holding this connected Hardware Wallet."&lt;/em&gt; In the next step, when the hardware wallet connects to the company service software, the system first verifies that the 8-to-10 digit code generated by the wallet matches exactly what is recorded in the company's database for that specific session. This confirms that the wallet has been rightly identified as belonging to this specific user, effectively linking the wallet to the user via the bank's human identification process.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Generation:&lt;/strong&gt; To ensure the Service acts as "Blind Storage" and never sees the seed phrase as plain text, we use &lt;strong&gt;Witness Encryption&lt;/strong&gt; logic via BitVM/Zero-Knowledge proofs.

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;For setting the backup (Phase 1) of the original wallet, we use "Blind" Encryption Protocol (Witness Encryption).&lt;/strong&gt; Instead of giving the Service a key, we use &lt;strong&gt;Commutative Encryption&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Setup:&lt;/strong&gt; You connect the wallet back to the service's client, your Wallet generates a random key ($K$) and encrypts the Seed Phrase.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Puzzle:&lt;/strong&gt; Your Wallet encrypts $K$ into a &lt;strong&gt;Mathematical Puzzle&lt;/strong&gt; (Witness Encryption). The rule is: &lt;em&gt;"This puzzle can only be transformed if a valid Bank Wire Proof + 7 Days Time is provided."&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Storage:&lt;/strong&gt; The Service stores the Encrypted Seed and the Puzzle. They physically &lt;strong&gt;cannot&lt;/strong&gt; decrypt it because they lack the "Witness" (the Proof of Wire) to solve the encryption equation.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Risk:&lt;/strong&gt; Can the Service simply lie, claim they received a wire, and secretly decrypt my data?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Defense:&lt;/strong&gt; &lt;strong&gt;The "Loud" Timer.&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;The 7-Day Time-Lock is a &lt;strong&gt;Blockchain Logic&lt;/strong&gt;, not a server clock.&lt;/li&gt;
&lt;li&gt;To start the timer, the Service &lt;em&gt;must&lt;/em&gt; publish a "Recovery Initiation" transaction on the public ledger.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;You cannot hide a transaction on a public blockchain.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;The moment they press that button, the Watchtower detects the on-chain event and alerts you.&lt;/li&gt;
&lt;li&gt;Since the Encryption Puzzle requires the &lt;em&gt;completion&lt;/em&gt; of the 7-day on-chain period, the Service cannot decrypt anything until the time is up. This gives you 7 days to broadcast a &lt;strong&gt;VETO&lt;/strong&gt; transaction, which creates a mathematical block that makes the puzzle unsolvable forever.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;em&gt;Result:&lt;/em&gt; The Service holds your backup, but they &lt;strong&gt;cannot read it&lt;/strong&gt;. They just act as a storage locker.&lt;/li&gt;

&lt;/ul&gt;

&lt;h1&gt;
  
  
  Phase 2: The Recovery (and Inheritance)
&lt;/h1&gt;

&lt;p&gt;Years later, you lose your device. Or perhaps you pass away, and your heir needs access.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;The Request:&lt;/strong&gt; You (or your heir) buy a new wallet. You connect to the Service.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Proof:&lt;/strong&gt; You (or the heir via probate/law) send another $1.00 wire from the registered bank account. You include the &lt;strong&gt;new&lt;/strong&gt; session code in the Memo.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Match:&lt;/strong&gt; The Service matches the Sender Name and the Memo Code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Time-Lock:&lt;/strong&gt; The Service initiates a "Release Transaction" on the Smart Contract with a &lt;strong&gt;3-to-7 Day Time-Lock.&lt;/strong&gt; The count of the days depends on how much delay the user configured while opting the service.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Release:&lt;/strong&gt; When the Time-Lock and Bank Wire conditions are met (and no veto is issued), the Service does &lt;strong&gt;not&lt;/strong&gt; decrypt the blob. The Smart Contract performs an &lt;strong&gt;Atomic Re-Encryption&lt;/strong&gt;. It applies the &lt;strong&gt;New Wallet's Key&lt;/strong&gt; (&lt;code&gt;Key B&lt;/code&gt;) &lt;em&gt;on top&lt;/em&gt; of the blob, and &lt;strong&gt;then&lt;/strong&gt; effectively "subtracts" &lt;code&gt;Key A&lt;/code&gt;. The ZK Circuit proves: &lt;em&gt;"I know the Witness (Wire Transfer + Time) that decrypted&lt;/em&gt; &lt;code&gt;Key A&lt;/code&gt;. But the ZK Proof &lt;strong&gt;does not reveal the Witness itself&lt;/strong&gt;. The public (and the Service) only sees the &lt;strong&gt;Proof&lt;/strong&gt; (a small string of characters) that says "This operation was valid," not the underlying secret that made it valid, therefore the old "decryption key" for &lt;code&gt;Key A&lt;/code&gt; (the Witness) &lt;strong&gt;does not&lt;/strong&gt; become public for anyone to use it to decrypt the original blob.&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The Result:&lt;/strong&gt; The blob transitions from being locked by the Old Wallet to being locked by the New Wallet without &lt;em&gt;ever&lt;/em&gt; being decrypted in the middle. The Service holds the data, but the math prevents them from reading it. The user's wallet decrypts the data with &lt;code&gt;Key B&lt;/code&gt; after receiving it. Funds are recovered.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Note for Inheritance:&lt;/em&gt; This solves the "Dead Man's Switch" problem. Heirs may not have the wallet's seed phrase, but they just need access to the bank account, and they perform a simple wire transfer.&lt;/p&gt;

&lt;h1&gt;
  
  
  The Threat Models (How everyone is protected)
&lt;/h1&gt;

&lt;p&gt;This is where the protocol shines. It protects the User, but it also protects the Service.&lt;/p&gt;

&lt;h1&gt;
  
  
  1. User vs. "Rogue Company" (The Imposter Attack)
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Risk:&lt;/strong&gt; What if a rogue employee at the Service tries to fake a request to steal your backup?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Defense A (Encryption):&lt;/strong&gt; The employee &lt;strong&gt;cannot decrypt&lt;/strong&gt; the blob. They only steal useless cyphertext.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Defense B (The Smart Contract):&lt;/strong&gt; The logic is on BitVM, not the company server. The company cannot force an immediate release. They must wait the 7 days.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Defense C (The Watchtower):&lt;/strong&gt; During that 7-day window, you (the user through his phone, email, and wallet) get an alert through a watchtower service. You can use your original wallet to &lt;strong&gt;VETO&lt;/strong&gt; the transaction on the Smart Contract. You can prove to the public that company was trying to steal funds, as you didn't make any wire transfer request. If proven guilty then the company would have reputational and legal consequences.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  2. Protection: Company vs. "Lying User" (Defamation)
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Scenario:&lt;/strong&gt; A user initiates a recovery, gets his keys, and then publicly claims: &lt;em&gt;"The Service hacked me! I never asked for this recovery!"&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Defense:&lt;/strong&gt; The Service points to the &lt;strong&gt;Bank Ledger&lt;/strong&gt;. They can publicly prove: &lt;em&gt;"Here is a Wire Transfer from your specific Bank Account, on this specific date, containing the specific 8-digit Code that authorized this release."&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Because the Wire Transfer is a regulated financial event, it acts as an immutable "Proof of Intent." The user cannot claim impersonation unless they admit their own bank was compromised. Supplementary checks (Video calls, SMS, Email communication) can exist as &lt;em&gt;layers&lt;/em&gt;, of which the company can have a record with themselves - these layers may work in the same way as  users are assisted by social media or financial companies when the user has forgotten the credentials for his account on their platform, but the "Base Layer" is the financial/legal record.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  3. Protection: User vs. Government/Censorship
&lt;/h1&gt;

&lt;p&gt;This is the critical defense mechanism.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Scenario:&lt;/strong&gt; A hostile government forces the Company (or seizes their servers) to initiate a recovery for your wallet, claiming they are you.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The Company is forced to press the "Wire Received" button even though you didn't send one.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Defense:&lt;/strong&gt; The &lt;strong&gt;7-Day Timer&lt;/strong&gt; starts. You (the user) receive an alert on your phone: &lt;em&gt;"Recovery Initiated."&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You now have two options:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Option A: The Veto (If you are safe)&lt;/strong&gt; You use your original wallet or a secondary key to VETO the transaction on-chain. The attack fails immediately.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Option B: Plausible Deniability (If you are under duress)&lt;/strong&gt; If the government is standing over your shoulder forcing you to let the timer run out:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You use a special "Duress Signal" (e.g., pointing the recovery to a specific decoy address).&lt;/li&gt;
&lt;li&gt;The Zero-Knowledge Proof generates a valid-looking decryption key.&lt;/li&gt;
&lt;li&gt;However, this key decrypts a &lt;strong&gt;"Dummy Wallet"&lt;/strong&gt; containing a small amount of "decoy" funds.&lt;/li&gt;
&lt;li&gt;The government sees the wallet open, sees the funds, and believes they have succeeded.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Crucially:&lt;/strong&gt; Because of the Zero-Knowledge nature of the proof, &lt;strong&gt;they cannot mathematically prove that this is a dummy wallet.&lt;/strong&gt; Your real stash remains hidden and encrypted forever.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  4. Protection: Service vs. Geopolitics
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Scenario:&lt;/strong&gt; The Service's servers are destroyed or seized in a specific country.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Defense:&lt;/strong&gt; Since the data is encrypted blobs, it can be stored on IPFS or decentralized servers globally. As long as the user has their identity (Bank Account) and the Service has the "Oracle" key to verify the wire, the service can be spun up anywhere in the world. Furthermore, each user can avail service from multiple backup companies so that if one of them is knocked down then he has other ones as backup.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Summary
&lt;/h1&gt;

&lt;p&gt;We are trying to bridge the gap between "Code is Law" and "Humans make mistakes."&lt;/p&gt;

&lt;p&gt;By using the &lt;strong&gt;Wire Memo&lt;/strong&gt; as a high-fidelity, we can create a system where:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;No new KYC is needed&lt;/strong&gt; (Your bank already did it).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No Custody is given&lt;/strong&gt; (Everything is encrypted client-side).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Inheritance is solved&lt;/strong&gt; (Legacy banking rails handle the access control).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Future Evolution: Native Bank APIs &amp;amp; Digital Signatures&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Currently, this protocol relies on a functional "hack" of the legacy system: the wire memo. This is also more of an approach for kick starting the process. However, as adoption grows, banks will recognize the utility (and market potential) of serving as a formal identity anchor for digital assets.&lt;/p&gt;

&lt;p&gt;We anticipate a shift toward direct API collaboration between banks and Backup Services. Instead of a service employee manually inputting the 8-to-10 digit code from a screen, the bank’s API could push a confirmation directly to the Service.&lt;/p&gt;

&lt;p&gt;Crucially, this allows us to integrate &lt;strong&gt;Bank-Signed Digital Signatures&lt;/strong&gt; directly into the BitVM Zero-Knowledge circuit. The "Witness" essentially evolves from a legal paper trail into a cryptographic proof. This eliminates the need for human verification at the Service level, reduces the scope for error, and creates a fully automated, trust-minimized bridge between fiat identity and crypto custody.&lt;/p&gt;

&lt;p&gt;I believe this is how we onboard the next billion users—by giving them a safety net that relies on math and existing infrastructure, not on trusting a CEO.&lt;/p&gt;

&lt;h1&gt;
  
  
  Update: Addressing Edge Cases (Internal Theft &amp;amp; Government Detention)
&lt;/h1&gt;

&lt;p&gt;Thank you for the feedback on the initial architecture. Two critical "human" edge cases were raised:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;The "Family" Risk:&lt;/strong&gt; What if someone with shared access to your bank account (like a spouse) tries to initiate a recovery behind your back?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The "Detention" Risk:&lt;/strong&gt; How do you issue a "Duress Signal" if you are physically detained by a government and can’t access your devices?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here is how we have refined the protocol to mitigate these threats while maintaining trust-minimization.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. The "Distributed Duress" Network (Guardian Protocol)
&lt;/h3&gt;

&lt;p&gt;To solve the detention problem, we introduce &lt;strong&gt;Guardians&lt;/strong&gt;. These are $N$ people (friends/family/lawyers) you trust. However, we handle this differently than standard social recovery to avoid extortion and collusion.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Silent by Default:&lt;/strong&gt; When you initiate a &lt;em&gt;legitimate&lt;/em&gt; recovery, your Guardians are &lt;strong&gt;not&lt;/strong&gt; notified. This is crucial. If they don't know a recovery is happening, they cannot extort you for a "cut" of the funds.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;The External Signal:&lt;/strong&gt; Guardians only act when they have external knowledge that you are in trouble (e.g., they see you’ve been arrested in the news, or you’ve disappeared).&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;The Duress Button:&lt;/strong&gt; If a Guardian sees a "Recovery Initiation" on the public ledger during the 7-day window and knows you are under duress, they can broadcast a "Duress Signal."&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Decentralized Veto/Redirection:&lt;/strong&gt; This signal can either move the recovery to a pre-set "Safe Harbor" address or trigger the "Decoy Wallet" logic mentioned in the original post. When you're set free then you can use your original wallet for master control.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. Mitigating Guardian Malice (The "Extortion" Case)
&lt;/h3&gt;

&lt;p&gt;A common concern with social recovery is: &lt;em&gt;"What if my friend turns on me and hits the Duress button just to mess with my recovery?"&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Game Theory &amp;amp; Overrides:&lt;/strong&gt; We use an $M$-of-$N$ logic. For example, if you have 3 Guardians, you can set the protocol so that if 1 Guardian hits "Duress" maliciously, the other 2 (or you, the user) can &lt;strong&gt;Veto/Override&lt;/strong&gt; that signal within the 7-day window.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Privacy of Guardians:&lt;/strong&gt; The Guardians should &lt;strong&gt;not&lt;/strong&gt; know who the other Guardians are. The user registers them independently. This prevents the "Ocean’s Eleven" scenario where your friends huddle together to coordinate an attack against you.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. Protection Against Internal/Family Theft
&lt;/h3&gt;

&lt;p&gt;If a family member with bank access initiates a wire transfer to steal your keys:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;The "Loud" Alert:&lt;/strong&gt; Since the 7-day timer is on-chain, your primary wallet and phone (which the family member may not have access to) will receive a notification immediately.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;The Hardware Veto:&lt;/strong&gt; As long as you have your hardware wallet or a secondary "Veto Key," you can kill the transaction instantly.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;The Bank Record:&lt;/strong&gt; Because the recovery is tied to a wire transfer, there is a legal paper trail. If a family member does this, they have committed a documented financial crime (unauthorized transfer), making it much easier to prosecute or reverse in a court of law compared to a typical "hacked" seed phrase.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4. The Company Reputation Defense
&lt;/h3&gt;

&lt;p&gt;Finally, regarding Government vs. User: A backup service’s primary product is &lt;strong&gt;security&lt;/strong&gt;. Just as high-end VPNs or encrypted mail services (like Proton) have historically fought or ignored government "data requests" to protect their brand, a non-custodial backup service has a massive market incentive to reject suspicious recovery requests.&lt;/p&gt;

&lt;p&gt;If the media reports a user is in detention, and the service sees a "forced" wire transfer request from that user’s account, the service can (and should) flag that request as "High Risk" and pause it, citing the protocol’s duress protections.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I am looking for feedback:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Are there edge cases in the "Dust Transaction" I'm missing?&lt;/li&gt;
&lt;li&gt;Would you feel secure knowing your encrypted backup is held by a service, protected by a 7-day time-lock and your regional bank?&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>bitcoin</category>
      <category>cryptocurrency</category>
      <category>nostr</category>
      <category>web3</category>
    </item>
    <item>
      <title>Function calling with Google Gemini chat AI</title>
      <dc:creator>Harshit Kedia</dc:creator>
      <pubDate>Tue, 24 Dec 2024 14:35:24 +0000</pubDate>
      <link>https://forem.com/harshit_kedia/function-calling-with-google-gemini-chat-ai-2261</link>
      <guid>https://forem.com/harshit_kedia/function-calling-with-google-gemini-chat-ai-2261</guid>
      <description>&lt;h4&gt;
  
  
  Function calling enables developers to incorporte custom functions or APIs with a generative AI chat application
&lt;/h4&gt;

&lt;h5&gt;
  
  
  The AI model decides if any of the functions and APIs is useful for answering the user query, and the AI model responds with the functions and their arguments to be used
&lt;/h5&gt;

&lt;h5&gt;
  
  
  The functions need to be well described with the arguments, their argument data types and the returning values
&lt;/h5&gt;

&lt;h5&gt;
  
  
  In this tutorial we will explore parallel function calling with Python, using Google Gemini AI, with external APIs providing city's population and country's currency used, for answering user questions
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;google.generativeai&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;genai&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Add your API key and select the model
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;genai&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;configure&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;api_key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;YOUR API KEY&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;genai&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GenerativeModel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;gemini-1.5-flash&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;generate_content&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;What is the date today?&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Today is October 26, 2023.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Define function to be used in function calling
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;#### Ensure to specify the datatype of arguments used in the function,
#### otherwise it will give error in function calling
&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;set_light_values&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;brightness&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;color_temp&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Set the brightness and color temperature of a room light. (mock API).

    Args:
        brightness: Light level from 0 to 100. Zero is off and 100 is full brightness
        color_temp: Color temperature of the light fixture, which can be `daylight`, `cool` or `warm`.

    Returns:
        A dictionary containing the set brightness and color temperature.
    &lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;brightness&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;brightness&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;colorTemperature&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;color_temp&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;set_light_values&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;brightness&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;color_temp&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;daylight&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{'brightness': 30, 'colorTemperature': 'daylight'}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Select the model and specify the tool to be used in function calling
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;genai&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GenerativeModel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model_name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;gemini-1.5-flash&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                              &lt;span class="n"&gt;tools&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;set_light_values&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  The response generated from the input will contain the suggested functions and arguments the chat model suggests
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;chat&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;start_chat&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;chat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send_message&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Dim the lights so the room feels cozy and warm.&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;response&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;response:
GenerateContentResponse(
    done=True,
    iterator=None,
    result=protos.GenerateContentResponse({
      "candidates": [
        {
          "content": {
            "parts": [
              {
                "function_call": {
                  "name": "set_light_values",
                  "args": {
                    "brightness": 30.0,
                    "color_temp": "warm"
                  }
                }
              }
            ],
            "role": "model"
          },
          "finish_reason": "STOP",
          "avg_logprobs": -0.0008751733228564262
        }
      ],
      "usage_metadata": {
        "prompt_token_count": 150,
        "candidates_token_count": 10,
        "total_token_count": 160
      }
    }),
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Evaluate the functions with the arguments the chat model suggests and store the functions with their corresponding values returned, as a JSON object
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;function_used_and_their_outputs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;functions&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;part&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;parts&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="c1"&gt;#### in every iteration, fn is assigned a function used by AI during the function call
&lt;/span&gt;      &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;fn&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;part&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;function_call&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
          &lt;span class="c1"&gt;#### args gets assigned a string value like "brightness=30.0, color_temp='warm'",
&lt;/span&gt;          &lt;span class="c1"&gt;#### repr() is used to add quotes to the keys like 'warm',
&lt;/span&gt;          &lt;span class="c1"&gt;#### repr() is used so string value keys are treated as string, not variable
&lt;/span&gt;          &lt;span class="n"&gt;args&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;, &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nf"&gt;repr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;val&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;val&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;items&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
          &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;arguments are: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
          &lt;span class="c1"&gt;#### Function is being generated using f strings
&lt;/span&gt;          &lt;span class="n"&gt;function_to_be_called&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;(&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;)&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
          &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;function being called using eval, with arguments: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;function_to_be_called&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
          &lt;span class="n"&gt;output&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nf"&gt;eval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;function_to_be_called&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
          &lt;span class="n"&gt;functions&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;output&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;house_functions&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{}&lt;/span&gt;
&lt;span class="nf"&gt;function_used_and_their_outputs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;house_functions&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;house_functions&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;arguments are:  brightness=30.0, color_temp='warm'
function being called using eval, with arguments:  set_light_values(brightness=30.0, color_temp='warm')





{'set_light_values': {'brightness': 30.0, 'colorTemperature': 'warm'}}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Provide the JSON object back to the generative chat function to get AI generated response processing the outputs of the functions
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;response_based_on_used_functions&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;functions&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
  &lt;span class="n"&gt;response_parts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
      &lt;span class="n"&gt;genai&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;protos&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Part&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;function_response&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;genai&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;protos&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;FunctionResponse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;result&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;val&lt;/span&gt;&lt;span class="p"&gt;}))&lt;/span&gt;
      &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;val&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;functions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;items&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;

  &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;chat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send_message&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response_parts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;response_based_on_used_functions&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;house_functions&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;OK. I've dimmed the lights to 30% brightness and set the color temperature to warm.  Is there anything else?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Defining functions to get population and currency of input city and country respectively
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;get_population&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;city&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
  &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Gets population of a city and year of count.

  Args:
    city: The name of the city.

  Returns:
    JSON object encapsulating the population of the city and year of count if function executed successfully, else, an error message.
  &lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
  &lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;https://countriesnow.space/api/v0.1/countries/population/cities&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

  &lt;span class="n"&gt;payload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;city&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;city&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="n"&gt;headers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;

  &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;request&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;POST&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="n"&gt;json_data&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;loads&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;json_data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;error&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;json_data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;msg&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;population&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;json_data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;data&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;populationCounts&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;value&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;year of counting&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;json_data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;data&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;populationCounts&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;year&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;get_population&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;amsterdam&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{'population': '779808', 'year of counting': '2011'}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;get_currency&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;country_code&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
  &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Gets information about the currency used in the country

  Args:
      country_code (str): The alphabetical country code of the country, eg.: if referring to Nigeria, then argument passed will be its alphabetical country code NG

  Returns:
    JSON object encapsulating the currency used in the country if function executed successfully, else, an error message is returned.
  &lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
  &lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;https://countriesnow.space/api/v0.1/countries/currency&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

  &lt;span class="n"&gt;payload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;iso2&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;country_code&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="n"&gt;headers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;

  &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;request&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;POST&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="n"&gt;json_data&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;loads&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;json_data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;error&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;json_data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;msg&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;json_data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;data&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;currency&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;get_currency&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;pk&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'PKR'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;demography_functions&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;get_population&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;get_currency&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;genai&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GenerativeModel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model_name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;gemini-1.5-flash&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tools&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;demography_functions&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;chat&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;start_chat&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  In the following example, notice that both, the population and currency functions are being called by the AI chat when population and currency are being asked by user, also notice that the AI is using its own knowledge to identify the country in which the city asked by the user is located, to send the corresponding country code as the argument to the currency function
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;chat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send_message&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Tell about the population and currency used in delhi&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;demography_functions_used&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{}&lt;/span&gt;
&lt;span class="nf"&gt;function_used_and_their_outputs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;demography_functions_used&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;demography_functions_used&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;arguments are:  city='Delhi'
function being called using eval, with arguments:  get_population(city='Delhi')
arguments are:  country_code='IN'
function being called using eval, with arguments:  get_currency(country_code='IN')





{'get_population': {'population': '9879172', 'year of counting': '2001'},
 'get_currency': 'INR'}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;response_based_on_used_functions&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;demography_functions_used&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The population of Delhi was 9,879,172 in 2001. The currency used in India, where Delhi is located, is the Indian Rupee (INR).
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  In the following 2 examples, notice that only the population function is being called by the AI chat when only population is asked by user
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;chat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send_message&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Tell about the population of Tokyo&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;demography_functions_used&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{}&lt;/span&gt;
&lt;span class="nf"&gt;function_used_and_their_outputs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;demography_functions_used&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;response_based_on_used_functions&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;demography_functions_used&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;arguments are:  city='Tokyo'
function being called using eval, with arguments:  get_population(city='Tokyo')
The population of Tokyo was 8,945,695 in 2010.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h5&gt;
  
  
  Due to some reason, the API isn't able to fetch the population of New York, which the AI chat achnowledges
&lt;/h5&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;chat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send_message&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Tell about the population of new york&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;demography_functions_used&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{}&lt;/span&gt;
&lt;span class="nf"&gt;function_used_and_their_outputs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;demography_functions_used&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;response_based_on_used_functions&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;demography_functions_used&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;arguments are:  city='New York'
function being called using eval, with arguments:  get_population(city='New York')
I'm sorry, I couldn't find information about the population of New York.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  In the following examples, notice that only the currency function is being called by the AI chat when only currency is asked by user
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;chat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send_message&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Tell about the currency of london&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;demography_functions_used&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{}&lt;/span&gt;
&lt;span class="nf"&gt;function_used_and_their_outputs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;demography_functions_used&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;response_based_on_used_functions&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;demography_functions_used&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;arguments are:  country_code='GB'
function being called using eval, with arguments:  get_currency(country_code='GB')
The currency used in London, United Kingdom is the British Pound (GBP).
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;– I am Harshit from India. I am exploring generative AI, data science and machine learning. To collaborate, let's connect on &lt;a href="https://www.linkedin.com/in/harshit-kedia-35079929b" rel="noopener noreferrer"&gt;linkedin&lt;/a&gt; and &lt;a href="https://x.com/SoftDevHarshitK?t=s9vSCXGfCYoTk6kdPryF9A&amp;amp;s=09" rel="noopener noreferrer"&gt;twitter&lt;/a&gt; 😊&lt;/p&gt;

</description>
      <category>genai</category>
      <category>datascience</category>
      <category>gemini</category>
      <category>ai</category>
    </item>
    <item>
      <title>Useful insights I got while building web development projects</title>
      <dc:creator>Harshit Kedia</dc:creator>
      <pubDate>Sat, 17 Feb 2024 10:42:04 +0000</pubDate>
      <link>https://forem.com/harshit_kedia/useful-insights-i-got-while-building-web-development-projects-46ei</link>
      <guid>https://forem.com/harshit_kedia/useful-insights-i-got-while-building-web-development-projects-46ei</guid>
      <description>&lt;p&gt;Building a music player web app like spotify using HTML, CSS and Javascript!&lt;/p&gt;

&lt;p&gt;Currently working on building a section for showing the list of songs in the library. Here are some interesting insights:&lt;/p&gt;

&lt;p&gt;Using CSS, the list style of an unordered list (UL) can be modified to none if we want to remove bullet points, it can be set to any other style as well. We can modify the list-style-type to number to use it as an ordered list.&lt;/p&gt;

&lt;p&gt;The getElementByTagName returns array of the tags present, for the particular tag we are searching, to use a particular one we have to refer to the position in the array like arr[0], it can also be nested with querySelector if we want to use it in a particular element having an id, similarly, multiple getElementByTagName can be combined by referring to their respective positions in their arrays.&lt;/p&gt;

&lt;p&gt;Forof loop can be used for iteration in an array. To return it in HTML in the desired format we can use a template literal to concatenate the outputs of the iteration. Ex: use &lt;code&gt;songUL.innerHTML += &amp;lt;li&amp;gt; ${song} &amp;lt;/li&amp;gt;&lt;/code&gt; where songUL is a UL with that id, and ‘song’ is the output of iteration in ‘songs’ array.&lt;/p&gt;

&lt;p&gt;If we fetch data from a URL of our server, for instance here I want to fetch the list of songs in my database, it will return the array with special characters replaced with encoding. For example: spacebar (‘ ‘) will be returned with ‘%20’, so while returning the output we need to use replaceAll (not ‘replace’ because it will only replace the first instance). Also, using ‘split’ to break the string into 2 parts will give an array with 2 elements, one left part of the string and another one right part, so use [1] in the output array to get the right part of the string.&lt;/p&gt;

&lt;p&gt;I wanted to put a ‘play now’ text to appear if i am hovering over an associated image of the play icon. The hovering happening on one element to bring effect on another element can be brought by keeping the text element’s display as none and then keeping the following CSS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#imgToBeHovered:hover ~ #textToBeDisplayedUponHover{
    display: block;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;//here imgToBeHovered and textToBeDisplayedUponHover are id names of the elements.&lt;/p&gt;

&lt;p&gt;Associated github repository: &lt;a href="https://github.com/Harshitnitw/spotify-clone/" rel="noopener noreferrer"&gt;https://github.com/Harshitnitw/spotify-clone/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;– I am Harshit from Varanasi, India, anyone interested in science, technology, etc and would like to learn and grow together, feel free to DM 😊&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvczfv8uups165grs9wxg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvczfv8uups165grs9wxg.png" alt="Image description" width="800" height="449"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Created a Weather web app using HTML, CSS and Javascript</title>
      <dc:creator>Harshit Kedia</dc:creator>
      <pubDate>Thu, 11 Jan 2024 15:09:27 +0000</pubDate>
      <link>https://forem.com/harshit_kedia/created-a-weather-web-app-using-html-css-and-javascript-52f3</link>
      <guid>https://forem.com/harshit_kedia/created-a-weather-web-app-using-html-css-and-javascript-52f3</guid>
      <description>&lt;p&gt;Basic idea is, we have an input field and submit button in a div, styled with CSS. Clicking the submit button invokes a function which inputs the city using document object model (DOM) query selector and we fetch an API with API key and city name as a query. Relevant data is extracted and displayed with a CSS styled div again selected using DOM.&lt;/p&gt;

&lt;p&gt;Link of the weather app: &lt;a href="https://weather-app-using-html-css-and-javascript.vercel.app/" rel="noopener noreferrer"&gt;https://weather-app-using-html-css-and-javascript.vercel.app/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We have an error display message which is styled as &lt;code&gt;display: none&lt;/code&gt; by default, and is changed to &lt;code&gt;display: block&lt;/code&gt; if the fetch method returns a 404 response, if the user enters an incorrect city name.&lt;/p&gt;

&lt;p&gt;We also have an associated image displayed corresponding to the weather, which the instructor selected using if-else statement based on the weather property returned by the API, however, I used string interpolation with placeholder ${} to use the weather property to output file names directly, somewhat like images/${weather}.png and thus improved the code efficiency.&lt;/p&gt;

&lt;p&gt;Link of associated code: &lt;a href="https://github.com/Harshitnitw/Weather-App-using-HTML--CSS-and-Javascript" rel="noopener noreferrer"&gt;https://github.com/Harshitnitw/Weather-App-using-HTML--CSS-and-Javascript&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks to GreatStack youtube channel for providing the learning experience: &lt;a href="https://youtu.be/G0jO8kUrg-I?si=PxYmpNP420Et9LAp" rel="noopener noreferrer"&gt;https://youtu.be/G0jO8kUrg-I?si=PxYmpNP420Et9LAp&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Feel free to reach me out if you would like to learn and grow together 😄&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvxq7aw43emzqkj98fezo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvxq7aw43emzqkj98fezo.png" alt="Image description" width="800" height="449"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Made a shopping cart web app using HTML, CSS and Javascript</title>
      <dc:creator>Harshit Kedia</dc:creator>
      <pubDate>Sat, 06 Jan 2024 12:32:55 +0000</pubDate>
      <link>https://forem.com/harshit_kedia/made-a-shopping-cart-web-app-using-html-css-and-javascript-4b80</link>
      <guid>https://forem.com/harshit_kedia/made-a-shopping-cart-web-app-using-html-css-and-javascript-4b80</guid>
      <description>&lt;p&gt;erent items, and the total amount along with the items is displayed on the cart page. The website is dynamic and allows editing the choice of items both on the store and on the cart page.&lt;/p&gt;

&lt;p&gt;Link to the web app: &lt;a href="https://shopping-cart-app-with-html-css-and-javascript.vercel.app/index.html" rel="noopener noreferrer"&gt;https://shopping-cart-app-with-html-css-and-javascript.vercel.app/index.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We have unique IDs of the shopping items whose details are stored in a &lt;code&gt;js&lt;/code&gt; file, which behaves as a key for identifying the quantity, price, etc of the item which the user selects. Javascript is used to generate a loop which renders the details based on the HTML template designed.&lt;/p&gt;

&lt;p&gt;Associated cards are dynamically programmed to identify specific elements, and results are rendered using the document object model (DOM). User’s selections are saved in the browser memory so that they reload after refresh.&lt;/p&gt;

&lt;p&gt;Link to the source code: &lt;a href="https://github.com/Harshitnitw/shopping-cart-app-with-HTML--CSS-and-Javascript" rel="noopener noreferrer"&gt;https://github.com/Harshitnitw/shopping-cart-app-with-HTML--CSS-and-Javascript&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks to Freecodecamp and the instructor Joy Shaheb for providing the learning opportunity. Associated tutorial: &lt;a href="https://youtu.be/cT_ZYrS3tKc" rel="noopener noreferrer"&gt;https://youtu.be/cT_ZYrS3tKc&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It was delightful for me to be able to apply my own ideas to reduce redundancy, avoid unused code and apply alternative techniques to load the pages faster, to improve upon the tutor’s project, which enhanced my learning experience manyfolds!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>100daysofcode</category>
    </item>
    <item>
      <title>Useful Javascript ES6 nuggets</title>
      <dc:creator>Harshit Kedia</dc:creator>
      <pubDate>Sat, 09 Dec 2023 09:34:28 +0000</pubDate>
      <link>https://forem.com/harshit_kedia/useful-javascript-es6-nuggets-497g</link>
      <guid>https://forem.com/harshit_kedia/useful-javascript-es6-nuggets-497g</guid>
      <description>&lt;p&gt;Important points I noted while  revising Javascript ES6:&lt;/p&gt;

&lt;p&gt;:&amp;gt; Adding external script to webpage:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script type="module" src="index.js"&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;:&amp;gt; Exporting function to Share a Code Block:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const add = (x, y) =&amp;gt; {
  return x + y;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;*Export multiple things by repeating for each export.&lt;/p&gt;

&lt;p&gt;:&amp;gt; Reusing JavaScript Code Using import:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { add, subtract } from './math_functions.js';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;*Here ./ tells the import to look for the math_functions.js file in the same folder as the current file.&lt;/p&gt;

&lt;p&gt;:&amp;gt; Import Everything from a File and use specific functions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import * as myMathModule from "./math_functions.js";
myMathModule.add(2,3);
myMathModule.subtract(5,3);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;:&amp;gt; For default export functions, while importing, no need to add braces {}, and name can be anything, not compulsorily the name of the function.&lt;/p&gt;

&lt;p&gt;:&amp;gt; Promise: task completes, you either fulfill your promise or fail to do so, with two parameters - resolve and reject, to determine the outcome of the promise. Syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const myPromise = new Promise((resolve, reject) =&amp;gt; {
  if(condition here) {
    resolve("Promise was fulfilled");
  } else {
    reject("Promise was rejected");
  }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;:&amp;gt; When you make a server request it takes some amount of time, and after it completes you usually want to do something with the response from the server. The then method is executed immediately after your promise is fulfilled with resolve, eg:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myPromise.then(result =&amp;gt; {});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;:&amp;gt; Catch can be executed if after a promise's reject method is called:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myPromise.catch(error =&amp;gt; {});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Useful javascript ES6 nuggets</title>
      <dc:creator>Harshit Kedia</dc:creator>
      <pubDate>Fri, 08 Dec 2023 07:18:26 +0000</pubDate>
      <link>https://forem.com/harshit_kedia/useful-javascript-es6-nuggets-29ac</link>
      <guid>https://forem.com/harshit_kedia/useful-javascript-es6-nuggets-29ac</guid>
      <description>&lt;p&gt;Some important points I summarized while revising ES6 from freecodecamp:&lt;/p&gt;

&lt;p&gt;:&amp;gt; Using Destructuring Assignment to Assign Variables from Nested Objects:&lt;br&gt;
Eg: we have object LOCAL_FORECAST:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const LOCAL_FORECAST = {
  yesterday: { low: 61, high: 75 },
  today: { low: 64, high: 77 },
  tomorrow: { low: 68, high: 80 }
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We assign variables lowToday and highToday with values LOCAL_FORECAST.today.low and LOCAL_FORECAST.today.high wusing this one liner code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const {today:{low:lowToday,high:highToday}}=LOCAL_FORECAST
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;:&amp;gt; We can access the value at any index in an array with destructuring by using commas to reach the desired index:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const [a, b,,, c] = [1, 2, 3, 4, 5, 6];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The values of a, b, and c become 1, 2 and 5 respectively.&lt;/p&gt;

&lt;p&gt;*Using destructuring assignment to swap the values of a and b, if we re-declare a or b while destructuring if already declared in the first let statement, then it will give an error. Eg, below code will give error:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let a = 8, b = 6;
const [b,a]=[a,b]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Correct way is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let a = 8, b = 6;
[b,a]=[a,b]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;*also, using &lt;code&gt;const&lt;/code&gt; instead of &lt;code&gt;let&lt;/code&gt; will give error above&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const [a, b, ...arr] = [1, 2, 3, 4, 5, 7];&lt;/code&gt;&lt;br&gt;
Here a, b and arr are new objects declared and their values are 1, 2 and [3, 4, 5, 7] respectively.&lt;br&gt;
*behavior is similar to Array.prototype.slice()&lt;/p&gt;

&lt;p&gt;:&amp;gt; Using Destructuring Assignment to Pass an Object as a Function's Parameters&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const profileUpdate = (profileData) =&amp;gt; {
  const { name, age, nationality, location } = profileData;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;can be effectively written as:&lt;br&gt;
&lt;code&gt;const profileUpdate = ({ name, age, nationality, location }) =&amp;gt; {}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;:&amp;gt; Creating Strings using Template Literals:&lt;br&gt;
Syntax: &lt;code&gt;Can add ${obj.prop}&lt;/code&gt;&lt;br&gt;
*We use backticks, not inverted commas, put the value as ${object.property} and there is no need of putting \n for new line, we can include expressions in string literal, eg: ${a + b}&lt;/p&gt;

&lt;p&gt;:&amp;gt; ES6 provides syntax to eliminate the redundancy of having to write x: x. You can simply write x once, and it will be converted tox: x (or something equivalent) for and as in the following:&lt;br&gt;
&lt;code&gt;const getMousePosition = (x, y) =&amp;gt; ({ x, y });&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;:&amp;gt; Example of using function in an object in ES6:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const bicycle = {
  gear: 2,
  setGear(newGear) {
    this.gear = newGear;
  }
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Useful Javascript ES6 nuggets</title>
      <dc:creator>Harshit Kedia</dc:creator>
      <pubDate>Sun, 03 Dec 2023 15:41:48 +0000</pubDate>
      <link>https://forem.com/harshit_kedia/useful-javascript-es6-nuggets-2g6h</link>
      <guid>https://forem.com/harshit_kedia/useful-javascript-es6-nuggets-2g6h</guid>
      <description>&lt;p&gt;Useful Javascript ES6 nuggets:&lt;/p&gt;

&lt;p&gt;Started learning ES6 from freecodecamp, some useful points I Summarized:&lt;/p&gt;

&lt;p&gt;:&amp;gt; Global scope of var vs local scope of let:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var printNumTwo;
for (var i = 0; i &amp;lt; 3; i++) {
  if (i === 2) {
    printNumTwo = function() {
      return i;
    };
  }
}
console.log(printNumTwo());
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, printNumTwo() prints 3 and not 2. This is because the value assigned to i was updated and the printNumTwo() returns the global i and not the value i had when the function was created in the for loop. The let keyword does not follow this behavior:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let printNumTwo;
for (let i = 0; i &amp;lt; 3; i++) {
  if (i === 2) {
    printNumTwo = function() {
      return i;
    };
  }
}
console.log(printNumTwo());
console.log(i);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here the console will display the value 2, and an error that i is not defined, because let's scope is limited to the block, function or statement in which you declare it.&lt;/p&gt;

&lt;p&gt;*I noticed that we need to change javascript to strict mode by writing "use strict" at the beginning of the code for the solution of 'let' keyword to work.&lt;/p&gt;

&lt;p&gt;:&amp;gt; Const declaration alone doesn't really protect your data from mutation, like adding/changing elements or properties in arrays or objects respectively. To ensure your data doesn't change, JavaScript provides a freeze function to prevent data mutation. Syntax: Object.freeze(arr)&lt;/p&gt;

&lt;p&gt;:&amp;gt; Syntax of inline function without name:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const myFunc = function(argument) {
  const myVar = "value";
  return myVar;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;OR&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const myFunc = (argument) =&amp;gt; {
  const myVar = "value";
  return myVar;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;:&amp;gt; Default parameters in function kick in when the argument is not specified (it is undefined). Ex:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const greeting = (name = "Anonymous") =&amp;gt; "Hello " + name;

console.log(greeting("John"));
console.log(greeting()); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;:&amp;gt; Rest parameter (...args) helps create functions that take a variable number of arguments, eg:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function howMany(...args) {
  return "You have passed " + args.length + " arguments.";
}
console.log(howMany(0, 1, 2));
console.log(howMany("string", null, [1, 2, 3], { }));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;:&amp;gt; Spread operator allows us to expand arrays and other expressions, eg:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const arr = [6, 89, 3, 45];
const maximus = Math.max(...arr);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;*can also use Math.max.apply(null,arr)&lt;/p&gt;

&lt;p&gt;:&amp;gt; Spread operator only works in-place, like in an argument to a function or in an array literal, i.e. the following code will not work:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const spreaded = ...arr; // use [...arr]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;:&amp;gt; Equivalent for&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const name = user.name;
const age = user.age;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;is&lt;br&gt;
&lt;code&gt;const { name, age } = user;&lt;/code&gt;&lt;br&gt;
OR&lt;br&gt;
&lt;code&gt;const { name: userName, age: userAge } = user;&lt;/code&gt;&lt;br&gt;
*new variable names are userName and userAge&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>100daysofcode</category>
    </item>
    <item>
      <title>Useful Javascript nuggets</title>
      <dc:creator>Harshit Kedia</dc:creator>
      <pubDate>Sat, 02 Dec 2023 10:36:10 +0000</pubDate>
      <link>https://forem.com/harshit_kedia/useful-javascript-nuggets-2fgk</link>
      <guid>https://forem.com/harshit_kedia/useful-javascript-nuggets-2fgk</guid>
      <description>&lt;p&gt;Finished revising basic javascript from freecodecamp, noted some important points:&lt;/p&gt;

&lt;p&gt;-&amp;gt; For a multi-dimensional array, we can use the following logic to loop through both the array and any sub-arrays, when the length of the arrays vary or is unknown:&lt;/p&gt;

&lt;p&gt;const arr = [ [1, 2], [3, 4], [5, 6] ];&lt;/p&gt;

&lt;p&gt;for (let i = 0; i &amp;lt; arr.length; i++) {&lt;br&gt;
  for (let j = 0; j &amp;lt; arr[i].length; j++) {&lt;br&gt;
    console.log(arr[i][j]);&lt;br&gt;
  }&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;-&amp;gt; Recursion (function calling upon itself): For multiplying the first n elements of an array:&lt;br&gt;
multiply(arr, n) == multiply(arr, n - 1) * arr[n - 1]&lt;br&gt;
Therefore the code can be:&lt;br&gt;
  function multiply(arr, n) {&lt;br&gt;
    if (n &amp;lt;= 0) {&lt;br&gt;
      return 1;&lt;br&gt;
    } else {&lt;br&gt;
      return multiply(arr, n - 1) * arr[n - 1];&lt;br&gt;
    }&lt;br&gt;
  }&lt;br&gt;
*Recursive functions must have a base case when they return without calling the function again (in this example, when n &amp;lt;= 0), otherwise they can never finish executing.&lt;/p&gt;

&lt;p&gt;-&amp;gt; Formula to generate a random whole number in the range from given min to max:&lt;br&gt;
Math.floor(Math.random() * (max - min + 1)) + min&lt;/p&gt;

&lt;p&gt;-&amp;gt; parseInt(string, radix)&lt;br&gt;
Radix specifies the base of the number in the string, which can be an integer between 2 and 36, stores the parsed input as integer. Eg: in the following code, 11 is in the binary system, or base 2:&lt;br&gt;
const a = parseInt("11", 2);&lt;/p&gt;

&lt;p&gt;-&amp;gt; Code for an array of 1 to N using recursion:&lt;br&gt;
function countup(n) {&lt;br&gt;
  if (n &amp;lt; 1) {&lt;br&gt;
    return [];&lt;br&gt;
  } else {&lt;br&gt;
    const countArray = countup(n - 1);&lt;br&gt;
    countArray.push(n);&lt;br&gt;
    return countArray;&lt;br&gt;
  }&lt;br&gt;
}&lt;br&gt;
*The array returned here is from 1 to N and not from N to 1 because at the point where n is pushed into the array, countup(n - 1) has already been evaluated and returned.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>100daysofcode</category>
      <category>coding</category>
    </item>
    <item>
      <title>Useful javascript nuggets</title>
      <dc:creator>Harshit Kedia</dc:creator>
      <pubDate>Thu, 30 Nov 2023 15:49:18 +0000</pubDate>
      <link>https://forem.com/harshit_kedia/useful-javascript-nuggets-1lbe</link>
      <guid>https://forem.com/harshit_kedia/useful-javascript-nuggets-1lbe</guid>
      <description>&lt;p&gt;Revised javascript objects, noted some useful points:&lt;/p&gt;

&lt;p&gt;We can omit the quotes for single-word string properties, like &lt;code&gt;make&lt;/code&gt; in the following example-&lt;br&gt;
const anotherObject = {&lt;br&gt;
  make: "Ford",&lt;br&gt;
  5: "five",&lt;br&gt;
  "model": "focus"&lt;br&gt;
};&lt;br&gt;
*Notice &lt;code&gt;5&lt;/code&gt;, we can also use numbers as properties.&lt;/p&gt;

&lt;p&gt;If the property of the object we are trying to access has a space in its name, we need to use bracket notation, ex: myObj["Space Name"];    &lt;/p&gt;

&lt;p&gt;We can add new properties to existing JavaScript objects the same way you would modify them. Ex: ourDog.bark = "bow-wow"; // &lt;code&gt;bark&lt;/code&gt; property was not declared initially&lt;/p&gt;

&lt;p&gt;delete properties from objects like this: delete ourDog.bark;&lt;/p&gt;

&lt;p&gt;someObject.hasOwnProperty(someProperty) returns true or false depending on if the property is found on the object or not&lt;/p&gt;

&lt;p&gt;*In a code, records[id][prop].push(value) was giving error because the array was not defined in some cases, so changed the code to:&lt;br&gt;
    const arr = records[id][prop] || []&lt;br&gt;
    arr.push(value)&lt;br&gt;
    records[id][prop]=arr&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
