My Blog

  Web3 for the Nigerian Context

February 23, 2023 by Enwerem Udochukwu

What exactly is web 3 and how can it be applied to the Nigerian context with respect to Education, Finance, Healthcare, Entertainment, Production and several other aspests of the Nigerian economy?

The Importance of Context

The above question is important when you take into cognisance that this relatively new technology (web 3) did not originate from Nigeria and that we [particularly in Africa] have a culture of copying anything new from the [west] without putting it into the context of our own culture, values and challenges.

A Brief on web 3

Firstly, web 3 or Web3 as it is fondly called is the latest iteration of the internet which is build on the concept of decentralization. It gets its roots from distributed computing where resources and participants in a system can be physically distributed but still communicate, share resources and contribute compute power to carry out a computational task. However, Web3 incorporates several new concepts that are not found in distributed systems. Among them include the decentralization of trust, where no single entity or node in the system controls the activities of any group of nodes or the entire system; in this way all nodes acts as peers to each and every other node. Also, Web3 vigorously utilizes encryption and advanced cryptographic methods. Firstly, it uses this to ensure data stored in the system, however distributed it is, is also immutable. Also, the concept of public and private key pairs is used to ensure that assets on the system while being publicly viewable (using a public key) are only manipulable by the owner of the asset (using a private key); this ensures transparency and security at the same time.

Difficulty of Adopting web 3 in Nigeria

Regardless of the benefits which are evident in web 3, there are some attendant problems in adopting any relatively new technology in Nigeria:

  1. Firstly, the level of Education is the country is relatively low. Consequently, most of the pupolation do not understand the benefits the new technology which hinders early adoption.
  2. The level of Poverty in the country is also alarming. This further correlates with low literacy levels, inadequate access to information and inability to afford tools such as mobile devices and personal computer that provide access to these emerging technologies.
  3. The level of Corruption and Crime in the country is very high. While those who already have access to wealth engage in corrupt practices due to greed, those who are lacking of the basic necessities of life engage in crime due to poverty. These scenerios are synonymous and they affect the adoption of emerging technologies in the same way. For instance, a corrupt person may see the anonymity provided by blockchain technology as a means of committing theft while evading detection.
  4. Lastly, there is the lack of infrastructure to support emerging technologies. For instance, the current telecommuncation infrastructure in the country have proven to be inadequate with outages occuring on a daily bases. Also, the electricity provision by the government even though now privatised still has the problem of frequent outages and excessive high billing which most businesses can not afford.

The Way Forward

If all the above problems are addressed, there is a good possibility of early wide spread adoption of web 3 technologies. However, regardless of how effective we curb these problems, there is the important need of regulation if we are to apply web 3 to the Nigerian context. This will ensure adoption without breaking the existing laws in the country. Check my co-authored publication on Springer for some of the benefits of Regulation and some suggested strategies to employ: https://doi.org/10.1007/978-3-030-80216-5_18.

  Using ChatGPT API with Node.js and Python

June 27, 2023 by Ayerhan Msughter and Enwerem Udochukwu

This article aims to introduce you to the Openai ChatGPT API and explains how to generate accurate responses using inference parameter tuning and advanced prompt engineering. The examples in this article are in Node.js and Python, but are applicable to other programming languages as well.

Signing Up

Before we start using the API we need to sign up with Openai at https://openai.com/api/ to get access.

Getting your API Secret Key

After signing up we can login and create our secret API key which would be used for calling the API from our program by clicking on the user icon at the top left. Thereafter, click on the view api keys option from the drop down.

Click on the create new secret key button to generate your secret key and copy it.

Installing Required Libraries

Openai libraries are available in all major programming languages for interacting with their API. But in this article we would be focusing on Node.js and Python.

Node.js Installation

You can simply run this command from your Node.js application folder:

$ npm install openai

Head on to https://www.npmjs.com/package/openai for more details.

Python Installation

You can simply run this command from your Linux operating system or environment:

$ pip install --upgrade openai

Head on to https://pypi.org/project/openai for more installation details.

Setting API Key in Envrionment Variable

After installing the library, we have to save our new API key in a platfrom environment variable first before using it in our application code. Because the key is meant to be private, it is advisable to set them in a different private code from our main public code as shown below.

Setting API Key in Node.js

Save the following code snippet in a file and run it to set the API key in a Node.js environment variable. Replace the 'key' string with the API key you copied earlier.

process.env['OPENAI_API_KEY'] = 'key';

There are several other ways you can set an environment variable in Node.js. See here.

Setting API Key in Python

Save the following code snippet in a file and run it to set the API key in a Python environment variable. Replace the 'key' string with the API key you copied earlier.

import os
os.environ['OPENAI_API_KEY'] = 'key'

There are several other ways you can set an environment variable in Python. See here.

Using ChatGPT API Key

After setting the appropriate key in an environment variable, we can now use the API key in our code to generate responses.

Node.js Code Example

The code snippet below is an example of how to use the API in Node.js.

source: https://platform.openai.com/examples/default-summarize?lang=node.js

Python Code Example

The code snippet below is an example of how to use the API in Python.

source: https://platform.openai.com/examples/default-summarize?lang=python

API Parameters and their Meaning

As you can see from the above examples the API contains some parameters that are provided when making an API call.

Model

There are basically five models of varying sizes we can choose from. The bigger models are generally more accurate and more expensive to use while the smaller models are faster, less accurate and cheaper to run.

The models are listed below arranged from biggest to smallest:

  1. text_davinci_003 (code-davinci-002 for programming )
  2. text_curie_001
  3. text_babbage_001
  4. text_ada_001

Prompt

This is the snippet of text you would like the API to complete. The AI looks at the prompt and gives it a completion that logically fits it. For example a prompt such as “ what is the definition of a computer” would make it to return the definition of a computer as the logical completion.

Temperature

This is a value between 0 and 1 that controls the creativity or randomness of the completions you get from the AI. When the value is closer to 1 the AI gives completions in a more creative way and it tries as much as possible to avoid repeating words. When the values is closer to 0 the completions would be less creative and tend to have a lot of repeated words.

Max Tokens

This parameter is used to set a maximum number of tokens for the prompt and completions to avoid long prompts.

Top P

This parameter is also used to control the randomness of the completions. It is recommended that when using top p, temperature should be set to 0 and when using temperature, top p should be set to 0.

Frequency Penalty

The frequency penalty reduces the models tendency to repeat words in a sentence. It is usually a value between 0 and 1.

Prescence Penalty

The presence penalty allows the model to make novel predictions by lowering the probability of a word if it already appeared in the text. Unlike Frequency penalty presence penalty does not depend on the frequency at which the word appeared in the past. It is also a value between 0 and 1. These parameter should be set to 0 for most tasks.

Advanced Prompt Design

The quality of our prompts usually determines the accuracy of the responses or completions we get. Thus there is a need to put good efforts in designing quality prompts. In most cases you would have to experiment with different prompts to see the ones that yield the most accurate and consistent responses. Different problems require different styles of prompt and could be classified into:

  1. question answering
  2. chat
  3. summary
  4. code completion

In this article we will focus on the chat prompt.

Chat Prompt Design

Chatting prompts are usually very similar to question answering prompts, but unlike question answering prompt you also have give the AI a personality that would help it center its discussion around. The prompt text can be as follows:


The following is a conversation with an AI assistant. The assistant is helpful, creative, clever, and very friendly.
Human: Hello, who are you?
AI: I am an AI created by OpenAI. How can I help you today?
Human: I'd like to cancel my subscription.
AI:

Other parameter settings are as follows:

Engine:text-davinci-003
Max tokens:150
Temperature:0.9
Top p:1
Frequency penalty:0.0
Presence penalty:0.6

source: https://platform.openai.com/examples/default-chat

Notice how the first sentence in the prompt gives the AI a personality.

Summary

In this article we have explored how to setup the Openai API on your local development environment, how to use your custom API key within your application and how to design custom prompts for use with the ChatGPT API. If you are really enthusiastic about ChatGPT and AI in general, head on to openai.com to explore more uses of these technologies. We also hope to feature more interesting articles on other applications of ChatGPT in the future.