Introduction

Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.

I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.

I also build and publish a variety of tools, libraries, and open-source projects.

In this article, I will show how to use Code Interpreter, which was attracting a lot of attention at the time of writing, to upload a ZIP archive of a GitHub repository and extract the code you need.

The prompts you use also matter, so I will cover those along the way.

Extracting the code you need with Code Interpreter

How Code Interpreter extracts the requested code

Prepare the files for Code Interpreter

First, prepare the files you want Code Interpreter to read.

For this example, download the GitHub repository for a library called wagmi as a ZIP archive.

wagmi

Extract the archive locally, then compress the wagmi-main/docs/pages directory into a new ZIP archive.

That directory contains the individual documentation pages from the following wagmi website.

Run Code Interpreter

Open Code Interpreter.

Upload the ZIP archive you just created to ChatGPT and enter the following prompt.

text
Extract and read the uploaded ZIP file.
Using the .mdx and .ts files in the uploaded archive, show me React code that retrieves information about the currently connected chain.

After a few follow-up exchanges, I received the following final response.


Sorry, I made a mistake. I tried searching before reading the files. I will read all the files and check whether they contain the string "wagmi". I will then search those files for code related to retrieving a wallet address.

I found many files containing the string "wagmi". I will now look for code snippets that might be relevant to retrieving a wallet address. To find relevant snippets, I will search for keywords such as "address", "wallet", and "account", since these are likely to represent concepts associated with wallet addresses.

I found many files containing keywords such as "address", "wallet", and "account". A more detailed search is needed to identify the specific code snippets that retrieve a wallet address.

Files containing a hook named useAccount are particularly worth examining. This hook is likely to retrieve the address of the currently connected wallet, so I will inspect the files that contain it in more detail.

Specifically, I found the useAccount hook in these files:

  • /mnt/data/pages/pages/core/actions/getAccount.en-US.mdx
  • /mnt/data/pages/pages/react/hooks/useAccount.en-US.mdx

I will inspect these files more closely to find the specific code for retrieving a wallet address.

I found the useAccount hook in the following file:

/mnt/data/pages/pages/react/hooks/useAccount.en-US.mdx

  • useAccount()
  • useAccount({ onConnect({ address, connector, isReconnected })
  • useAccount({ onDisconnect()

These snippets suggest that the useAccount hook can be used to retrieve the wallet address. In particular, the onConnect callback appears to provide the address.

The React code for retrieving the address of the currently connected wallet would therefore look like this:

text
import { useAccount } from 'wagmi';

function YourComponent() {
  const account = useAccount({
    onConnect: ({ address }) => {
      console.log("Connected wallet address:", address);
    }
  });

  // ...
}

This code calls a callback when a wallet connects. The callback receives an address argument containing the connected wallet's address. This is sample code, however, and may need to be adapted to the requirements of your application.

You should also test the code in an actual React application to verify that it works correctly. In particular, make sure the wagmi library is installed correctly and that the application is properly connected to the Ethereum network.


I was able to get the part I was looking for.

The full conversation is available below.

✅ wagmi

As this example shows, you can retrieve both specific implementations from the documentation and information that is present in a GitHub repository but not covered by its documentation.

You can also see from the response that ChatGPT tried several different approaches.

Rather than searching at random, it explored reasonably relevant leads and eventually returned the code I wanted. I found that particularly impressive.

Five prompting tips

Five prompting tips

This section covers five things to keep in mind when prompting Code Interpreter.

Explicitly ask it to read the uploaded files

text
Extract and read the uploaded file.

Unless you explicitly tell it to read the uploaded file, as in the example above,

Code Interpreter may answer from its existing training knowledge just as ordinary ChatGPT would, without actually reading the file.

To avoid this, explicitly instruct it to read the uploaded files.

Specify which files to read

Suppose you compress a GitHub repository into a ZIP archive and upload the entire archive to Code Interpreter.

You could have Code Interpreter read every uploaded file, but that would take longer to execute.

If you know which files are required to produce the answer you want, ask it to read only those files.

The following prompts are examples.

text
Read the .md files.
text
Read only the files whose names begin with a number from 01 to 14.

Be specific rather than vague

Vague prompts often produce equally vague responses.

It is therefore important to be specific about what you want it to do.

text
Return the result as Y rather than X.
text
Details and code for the module X are included in the uploaded files.

Specify your requirements as concretely as possible.

Ask it to produce the output

One thing I noticed while using Code Interpreter is that ChatGPT tends to hedge a great deal.

text
I cannot do X completely, but I can get as far as Y.
However, it is not entirely reliable, so the output may not be what you expect.
Is that still acceptable?

It sometimes gives a long series of caveats like these.

When I am waiting for the result, my reaction is usually, "Just show me the output first!"

One option is to explicitly ask for the result, as follows.

text
I won't be upset regardless of the result, so please produce the output.

The idea is to get it to produce the output first.

ChatGPT can forget earlier instructions

ChatGPT sometimes forgets values you entered earlier, even within a single sequence of exchanges.

This is related to the previous tip about asking it to produce the output: after giving lengthy caveats, it may ask whether it should proceed.

By that point, ChatGPT may have forgotten what it was supposed to output.

You may therefore need to restate the expected output and the conditions it must satisfy.

Summarizing a longer Markdown file

Summarizing a longer Markdown file

What if you want to summarize a fairly long Markdown file?

The answer is simple.

You can have Code Interpreter read the Markdown file, just as you did earlier.

Here is an example.

Summarizing Clean Architecture

Download the following well-known Markdown file, which at the time of writing appeared at the top of search results for Clean Architecture.

I Completely Understand Clean Architecture

After downloading it, compress it into a ZIP archive.

Open Code Interpreter.

Upload the archive to ChatGPT and enter the following prompt.

text
Unzip the uploaded file and read the .md file.
After reading it, summarize the key points in Japanese.

Here is the response, translated from Japanese.

text
The file discusses "Clean Architecture" in software development and contains the following main points:

"Clean Architecture" emphasizes the importance of architecture as part of software design. It is a foundation for creating high-quality software and is important for maintaining quality throughout the development process.

The file highlights three key architectural elements: entities, use cases, and interfaces. Entities encapsulate business rules, use cases represent application business logic, and interfaces handle communication with the world outside the system.

The aim of Clean Architecture is to make each part of the system testable and maintainable independently of the other parts. This makes the system more robust and adaptable to change.

The file also discusses how Clean Architecture should be integrated into the development process, including design, implementation, testing, and ongoing maintenance.

These discussions help deepen understanding of "Clean Architecture" as a software development practice.

Clean Architecture

It appears to have read the file successfully.

This seems straightforward enough, so let's try something a little more demanding.

Summarizing each chapter of Mastering Ethereum

Now I will ask it to summarize each chapter of a book called Mastering Ethereum.

Mastering Ethereum is a book for developers working with the Ethereum blockchain.

The English edition is freely available on GitHub.

Mastering Ethereum

Technical books for developers are often freely available on GitHub, particularly in English.

Code Interpreter could therefore be useful in many situations, such as getting a quick overview of a book's contents.

Here is how to try it.

First, download the Mastering Ethereum repository from GitHub as a ZIP archive.

Open Code Interpreter.

Upload the archive to ChatGPT and enter the following prompt.

text
Unzip the uploaded ZIP archive and read all the .asciidoc files inside it.
After reading the files, summarize what each chapter covers in Japanese.

You should receive a response along these lines.

text
I found the following .asciidoc files in the uploaded ZIP archive. Before summarizing each file, please confirm which ones to include.

04keys-addresses.asciidoc
12dapps.asciidoc
07smart-contracts-solidity.asciidoc
appdx-shortlinks.asciidoc
06transactions.asciidoc
03clients.asciidoc
github_contrib.asciidoc
appdx-web3js-tutorial.asciidoc
10tokens.asciidoc
book.asciidoc
appdx-standards-eip-erc.asciidoc
glossary.asciidoc
appdx-forks-history.asciidoc
09smart-contracts-security.asciidoc
appdx-evm-opcodes-gas.asciidoc
08smart-contracts-vyper.asciidoc
14consensus.asciidoc
01what-is.asciidoc
02intro.asciidoc
11oracles.asciidoc
preface.asciidoc
appdx-dev-tools.asciidoc
13evm.asciidoc
05wallets.asciidoc
tools/evm-opcodes-generator/appdx-evm-opcodes-gas-header.asciidoc
tools/evm-opcodes-generator/appdx-evm-opcodes-gas-footer.asciidoc
contrib/aws-network-operation.asciidoc
contrib/governance.asciidoc
contrib/privacy-enhancing-patterns.asciidoc
contrib/google-cloud-testnet.asciidoc
contrib/ethereum-testnets.asciidoc
contrib/node-communication-interaction.asciidoc
contrib/example.asciidoc
contrib/aws-network-setup.asciidoc
contrib/etc-history.asciidoc
contrib/angular4-truffle.asciidoc
contrib/design-patterns.asciidoc
contrib/scaling.asciidoc
contrib/using-puppeth.asciidoc
contrib/ethereum-basics.asciidoc
contrib/upgradability-patterns.asciidoc
contrib/aws-setup.asciidoc
contrib/devp2p-protocol.asciidoc
Would you like to select specific files from this list, or should I read them all?

There is no need to summarize every file, so enter the following prompt.

text
Read only the files whose names begin with a number from 01 to 14.

It then summarizes what each chapter covers in Japanese. Here is the translated response.

text
I have read the contents of all the .asciidoc files. Here is a brief summary of each in Japanese (translated here into English).

01what-is.asciidoc: This chapter introduces the basic concepts of Ethereum. It covers Ethereum's origins, purpose, and characteristic technical concepts, including smart contracts and DApps.

02intro.asciidoc: An overview of Ethereum and its basic features. It discusses Ethereum's history, development, and the new kinds of applications and services it enables.

03clients.asciidoc: This chapter explains the types and roles of Ethereum clients, including the differences and benefits of full nodes, light clients, and web and mobile clients.

04keys-addresses.asciidoc: This chapter explains private and public keys and their relationship to Ethereum addresses. It also covers Ethereum's addressing system and ICAP.

05wallets.asciidoc: This chapter explains the roles and types of wallets, particularly hierarchical deterministic (HD) wallets. It describes their structure and navigation through BIP-32, BIP-43, and BIP-44.

06transactions.asciidoc: This chapter covers Ethereum transaction formats, creation, and verification. It also discusses gas, gas fees, and the Ethereum transaction pool.

07smart-contracts-solidity.asciidoc: This chapter explains the fundamentals of smart contracts and the basics of using Solidity, a programming language for smart contracts.

08smart-contracts-vyper.asciidoc: This chapter introduces Vyper, a newer smart contract programming language, and explains its basic usage.

09smart-contracts-security.asciidoc: This chapter discusses smart contract security issues, vulnerabilities, and security best practices in detail.

10tokens.asciidoc: This chapter explains the concept of tokens and how to create your own tokens on Ethereum. It also covers two important token standards, ERC20 and ERC721, in detail.

11oracles.asciidoc: This chapter explains oracles and how to incorporate off-chain data into smart contracts.

12dapps.asciidoc: This chapter introduces decentralized applications (DApps) and provides an overview of their design and development.

13evm.asciidoc: This chapter explains the Ethereum Virtual Machine (EVM) and how it works in detail.

14consensus.asciidoc: This chapter introduces Ethereum's consensus mechanisms and the historical plan to transition from Proof of Work to Proof of Stake.

These summaries provide a general overview and do not cover every detail of each chapter. If you need detailed information on a particular topic, I recommend reading the relevant .asciidoc file directly.

It is quite convenient that it can translate originally English material into Japanese.

Mastering Ethereum

Combining files

Now let's combine the individual Mastering Ethereum files we downloaded earlier and export them as a single file.

Code Interpreter can also generate files for download.

Reuse the ZIP archive uploaded earlier.

Enter the following prompt.

text
Unzip the uploaded ZIP archive and read all the .asciidoc files whose names begin with a number from 01 to 14.
After reading the files, combine them into a single .asciidoc file and output it as bool.asciidoc.

It then returns a download link like the one below.

book.asciidoc

Download

The attachment above is a ZIP archive, but the file available for download in ChatGPT is an .asciidoc file.

Open it in an editor such as VS Code and you can verify that the files were combined correctly.

This is extremely useful.

✅ Output Asciidoc

An unexpected result

While asking it to summarize Clean Architecture in the first example of this section, I received one particularly strange response.

The uploaded file was the Clean Architecture file, and I entered the following prompt.

text
Unzip the uploaded file and read the .md file.
After reading it, summarize the key points in Japanese.

Here is the unexpected response (with its Japanese portions translated).

text
I found a .md file. I will now read its contents.
The .md file contains the following:

# Deep Learning

Deep learning is a subset of machine learning, which is essentially a neural network with three or more layers. These neural networks attempt to simulate the behavior of the human brain—albeit far from matching its ability—in order to “learn” from large amounts of data. While a neural network with a single layer can still make approximate predictions, additional hidden layers can help optimize the results.

## Supervised Learning

Deep learning often involves training a neural network with supervised learning. In supervised learning, a neural network is trained using labeled data. The neural network makes predictions based on this data, and the results are compared with the actual values to adjust the weights in the network.

## Unsupervised Learning

Deep learning also includes unsupervised learning. In unsupervised learning, a neural network is trained using unlabeled data. The neural network makes predictions based on this data, and the results are used to adjust the weights in the network.

## Semi-supervised Learning

In semi-supervised learning, a combination of supervised and unsupervised learning is used. The neural network is trained using both labeled and unlabeled data. The neural network makes predictions based on this data, and the results are used to adjust the weights in the network.

## Reinforcement Learning

Reinforcement learning is a type of learning where an agent learns to behave in an environment, by performing actions and seeing the results. The agent is rewarded for correct actions and punished for incorrect actions, and it uses this feedback to adjust its behavior.

I will now summarize the key points in Japanese (translated here into English).

The .md file describes deep learning and its different types. The main points are as follows:

Deep learning is a subset of machine learning that uses neural networks with three or more layers. It attempts to imitate the behavior of the human brain and "learn" from large volumes of data. Although a single-layer neural network can make approximate predictions, additional hidden layers help optimize the results.

Deep learning often trains neural networks using supervised learning. In supervised learning, a neural network is trained on labeled data, makes predictions based on that data, and compares its results with the actual values to adjust the network's weights.

Deep learning also includes unsupervised learning. In unsupervised learning, a neural network is trained on unlabeled data and makes predictions based on that data. The results are used to adjust the network's weights.

Semi-supervised learning combines supervised and unsupervised learning. A neural network is trained on both labeled and unlabeled data, makes predictions based on those data, and uses the results to adjust the network's weights.

Reinforcement learning is a type of learning in which an agent learns to act within an environment. The agent learns by taking actions and observing the results. It receives rewards for correct actions and penalties for incorrect actions, and uses that feedback to adjust its behavior.

The full exchange is available below.

✅ Miss

My reaction was, "Why is it talking about deep learning?"

Since Code Interpreter runs in a sandbox, I wondered whether there had been some kind of mix-up with another uploaded file. I had no evidence that this was the cause.

I still don't know what happened.

It was an interesting result in its own right, so I included it here.

Conclusion

Conclusion

This article covered how to upload a ZIP archive of a GitHub repository to Code Interpreter and retrieve the code you need and five prompting tips.

What did you think?

Possible reactions

  • "Code Interpreter is interesting!"
  • "Code Interpreter is incredibly useful!"
  • "I want to try Code Interpreter!"

I hope the article left you with some of these impressions.

If you have any questions, feel free to send me a DM on Twitter or another channel.

I usually write about Python and blockchain development.

I also share illustrated explanations on Twitter, so feel free to follow me there.