ALIRI Labs

Customer Focused >>> Structured Approach >>> On-spot Delivery

At ALIRI, we always try to test out new things and learn from them. Feel free to check out some of the experiments we have done and the lessons we have learned.

Alter Ego – 150+ personalities answer questions using OpenAI

https://www.aliritech.se/alterego

It’s hard to have missed the hype of ChatGPT and what type of benefits that can give you. We have built a web application that emulates different personalities and responds to user questions using the OpenAI API in the background.

Try it out here: https://www.aliritech.se/alterego

The Alter Ego application operates as follows:

  1. A PHP script loads a JSON file containing a list of personalities and example questions for each one.
  2. The user can modify an existing question or add a new one.
  3. A JavaScript function calls a backend PHP script when the user submits a query. The script uses the personality and question to look up the corresponding character from the JSON file and prepare a prompt describing how that character might respond to the question.
  4. The prompt is designed for a natural language processing (NLP) technique called GPT-3, part of the OpenAI API. GPT-3 generates responses based on a sizeable pre-trained language model that can understand and develop human-like text.
  5. The prompt is sent to the OpenAI API for processing using a unique API token.
  6. As of 2023-03-04, it’s using the latest gpt-3.5-turbo model
  7. The backend PHP script receives the response from the OpenAI API and sends it back to the JavaScript function.
  8. Finally, another JavaScript function on the Alter Ego homepage converts the response text to an HTML version, creates a list, and converts it to hyperlinks.

This process involves several technologies, including HTML, JavaScript, and PHP, as well as the OpenAI API and prompt engineering techniques. Creating high-quality prompts that generate accurate and relevant responses from the OpenAI API can be challenging.

Lessons learned:

  • Easy API: Very easy to utilize the OpenAI API
  • Prompting is hard: Not so easy to write good prompts to the OpenAI engines – since it’s more or less an advanced pattern-matching engine – it can sometimes imagine things to fill the pattern it sees.
  • Cost: The OpenAI API is a paid service, and this cost can be a limiting factor for some projects.
  • Size of the request: Currently, a limit on the size of requests to the OpenAI API makes it hard to process more important documents, for instance. But there are ways around that – splitting up documents and having the engine summarise before processing, for example.
  • Other information: The model used in this test was gpt-3.5-turbo. See all models from OpenAI that are available now on this page we have: https://www.aliritech.se/openai/