Anyone Can Create A Chatbot With Codex

Leveraging OpenAI API, GPT-3 API & Codex

Introduction

The GPT-3 based OpenAI Language API is a text-in-text out API. It is not a chatbot development framework.

The is an extract from the OpenAI playground, where a single line of training data is given. Each dialog turn is denoted with Human and AI.

A chatbot development development framework demands the existence of seven elements which constitutes fine-tuning (there can be more).

Training Data: “The following is a conversation with an AI assistant. The assistant is helpful, creative, clever, and very friendly.” Intent-less and natural language generation.
  1. Forms & Slots
  2. Intents
  3. Entities
  4. Natural Language Generation (NLG)
  5. Dialog Management
  6. Digression
  7. Disambiguation

The OpenAI API allows for basic training with a few lines of example utterances, giving the API a basic gist of your application.

Fine tuning is available, but again this is a way of influencing the text-out portion. And not comprehensive fine-tuning per se.

Fine-tuning in OpenAI Language API based on GPT-3 is currently in beta and might change considerably in the near future.

In this example I wanted to create a fairly complicated dual-player application. The red and blue block can be moved up and down with keyboard keys. The scores can be reset and the game stopped and started

The OpenAI API is impressive none the less; but implementation scenarios currently is limited. Some implementation scenarios:

  1. A standalone general chatbot for general conversation. Or a question-and-answer Wikipedia-like chatbot.
  2. The second implementation is a Support API for a conventional Chatbot implementation. These can cover:
  • Grammar Correction
  • Text Summarization
  • Keywords
  • Parse Unstructured Data
  • Classification
  • Extract Contact Information
  • Summarize For A Second Grader

However, this is not the case with Codex…

Codex Use-Cases

There are a few definite use-cases for Codex as an API, ready for implementation.

The utterance Add a dropdown list with the months of the year created this dropdown.

Some of these use scenarios can include:

  • As a general AI Assistant for general code questions by a company’s development team/s.
  • A real use-case is having Codex as a bot within a Slack or Teams environment and coders can pose general questions to the Codex interface.
  • As a code QA bot. This process can be automated where code is run against the Codex API and reports are generated on vulnerabilities or errors.
  • Solving coding challenge and problems in certain routines.
  • Establishing best practice.
  • Explaining code
  • Interactive Learning
  • Crafting code based on Natural Language Input for developers to try out.
  • Converting code from one language to another.

A Practical Example: JavaScript Chatbot

This is an implementation of a JavaScript chatbot. Users can ask the chatbot any question regarding JavaScript. A user can ask the chatbot a practical question and the chatbot responds in natural language actually explaining the implementation in natural language.

In this playground example, the user questions are marked in red blocks, with the Codex answer.

As with the other offerings from OpenAI, the natural language generation is smooth, coherent and truly natural. Should you ask for a practical implementation, the Codex JavaScript chatbot will return working code.

Below is a practical example of a simplistic Python implementation of the JavaScript chatbot with the prompt input.

pip install openai
import openai
openai.api_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"response = openai.Completion.create(
engine="davinci-codex",
prompt="JavaScript chatbot\n\n\nYou: How do I combine arrays?\nJavaScript chatbot: You can use the concat() method.\nYou: How do make an alert appear after 10 seconds?\nJavaScript chatbot: You can use the setTimeout() method.\nYou: Show me a practical implementiton of concat();",
temperature=0,
max_tokens=60,
top_p=1,
frequency_penalty=0.5,
presence_penalty=0,
stop=["You:"]
)
print (response)

You can see the typos in the user input, but it does not cause any fallback proliferation.

Below is the JSON response…

{
"choices": [
{
"finish_reason": "length",
"index": 0,
"logprobs": null,
"text": "\nJavaScript chatbot: You can use the following code:\n\n

var arr1 = [1, 2, 3];\n
var arr2 = [4, 5, 6];\n
var arr3 = arr1.concat(arr2);\n
console.log(arr3);"
}
],
"created": 1630678929,
"id": "cmpl-3e4Mz3L6Tfk0vc5",
"model": "davinci-codex:2021-08-03",
"object": "text_completion"
}

The JavaScript chatbot is diverse in responses understanding if a user wants code or an explanation. This a complete API ready for use.

Conclusion

Codex is exceptionally good at explaining code and debugging code. Creating an application using natural language input demands that the user to break down their requirement for larger application, into smaller modules or segments.

This approach does take some time to build the application layer by layer, but allows for neat and predictable outputs.

Something small I found interesting I each segment of code is very well described with comments. The Natural Language Generation (NLG) of these comments is extremely well formed, cohered and natural sounding.

This is testament to the astute NLG capabilities of OpenAI Language API.

NLP/NLU, Chatbots, Voice, Conversational UI/UX, CX Designer, Developer, Ubiquitous User Interfaces. www.cobusgreyling.me