How to make a replica of GPT Actions with the OpenAI API only ?

In recent years, large language models (LLMs) such as GPT-3 have shown incredible promise in generating human-like text, answering questions, and holding conversations. However, to transform an LLM into a fully functional AI assistant, we need more tha…


This content originally appeared on DEV Community and was authored by Abderrahmene Merzoug

In recent years, large language models (LLMs) such as GPT-3 have shown incredible promise in generating human-like text, answering questions, and holding conversations. However, to transform an LLM into a fully functional AI assistant, we need more than just text generation capabilities. That's where LLMKit comes in. LLMKit is a powerful library designed to help developers convert their text-to-text LLMs into fully functional AI assistants, enabling them to perform specific tasks and handle real-world scenarios.

LLMKit simplifies the integration of LLMs into your applications by providing a modular plugin system, built-in retry mechanisms, and customizable conversation configurations. In this article, we will walk you through the process of creating a conversation with an external function call using LLMKit. By the end of this guide, you'll have a solid understanding of how to extend the capabilities of your LLM and build a responsive AI assistant.

Getting Started with LLMKit

To start using LLMKit, you'll need to install it from GitHub using npm. Open your terminal and run the following command:

npm i obaydmerz/llmkit

A step-by-step guide to create a conversation

Step 1: Importing modules and creating instances

import { Conversation, retry } from "llmkit";
import { External, ExternalFunction } from "llmkit/plugins/external";
// Import the OpenAI module here

also, instantiate the OpenAI client:

const gpt = new OpenAI_Instance_Or_Any_LLM();

Step 2: Create the conversation

Don't worry, we will explain the code below later:

let conv = Conversation.create(
    (m) => retry({}, (num) => gpt.chatCompletion(/*or any function*/(m, {
      debug: true
    }))),
    {
      plugins: [
        External.create([
          ExternalFunction.create("purchase", {
            description: "Orders something",
            parameters: {
              name: "string, The name of the product"
            },
            hook: async ({ name }) => {
              if (name.toLowerCase() == "pizza") {
                return "Ordered! Tell the user that the pizza is yummy";
              }
              return "Product Not Found";
            },
          }),
        ]),
      ],
    }
  );

Conversation is the main class in LLMKit that hold the conversation between three parts: system, user, agent

The Conversation.create() static function accepts two arguments:

  • The first argument, which is the function that's called to pass the string message to the GPT. ( notice the retry function which repeats the function if it fails )
  • The second argument is the options object.

Here we added External to plugins, External provides a way for the GPT/LLM to execute functions your code.

Step 3: Send a Message to the Conversation

(async () => {
     await conv.start();
     let res = await conv.send("I wanna purchase a burger");

     // You can access messages through conv.messages
     console.log(res); // I'm sorry, I couldn't find the burger you were looking for. How can I assist you further?
})();

After that all

If you still have any question, post it in the comments.
Join our discord server for further assistance!

🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀


This content originally appeared on DEV Community and was authored by Abderrahmene Merzoug


Print Share Comment Cite Upload Translate Updates
APA

Abderrahmene Merzoug | Sciencx (2024-07-19T22:39:36+00:00) How to make a replica of GPT Actions with the OpenAI API only ?. Retrieved from https://www.scien.cx/2024/07/19/how-to-make-a-replica-of-gpt-actions-with-the-openai-api-only/

MLA
" » How to make a replica of GPT Actions with the OpenAI API only ?." Abderrahmene Merzoug | Sciencx - Friday July 19, 2024, https://www.scien.cx/2024/07/19/how-to-make-a-replica-of-gpt-actions-with-the-openai-api-only/
HARVARD
Abderrahmene Merzoug | Sciencx Friday July 19, 2024 » How to make a replica of GPT Actions with the OpenAI API only ?., viewed ,<https://www.scien.cx/2024/07/19/how-to-make-a-replica-of-gpt-actions-with-the-openai-api-only/>
VANCOUVER
Abderrahmene Merzoug | Sciencx - » How to make a replica of GPT Actions with the OpenAI API only ?. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/07/19/how-to-make-a-replica-of-gpt-actions-with-the-openai-api-only/
CHICAGO
" » How to make a replica of GPT Actions with the OpenAI API only ?." Abderrahmene Merzoug | Sciencx - Accessed . https://www.scien.cx/2024/07/19/how-to-make-a-replica-of-gpt-actions-with-the-openai-api-only/
IEEE
" » How to make a replica of GPT Actions with the OpenAI API only ?." Abderrahmene Merzoug | Sciencx [Online]. Available: https://www.scien.cx/2024/07/19/how-to-make-a-replica-of-gpt-actions-with-the-openai-api-only/. [Accessed: ]
rf:citation
» How to make a replica of GPT Actions with the OpenAI API only ? | Abderrahmene Merzoug | Sciencx | https://www.scien.cx/2024/07/19/how-to-make-a-replica-of-gpt-actions-with-the-openai-api-only/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.