strapi-chatgpt icon indicating copy to clipboard operation
strapi-chatgpt copied to clipboard

How can I make the plugin refer to the data of a content-type?

Open chrismichaelps opened this issue 2 years ago • 11 comments

Currently, from what I have tested, the plugin answers general questions about the web and not exclusively about the content-types defined in strapi.

For example, taking into consideration a content-type of hotels (title, description, prices, etc...)

I will appreciate your help! :)

chrismichaelps avatar Apr 18 '23 16:04 chrismichaelps

We have the same questions. How do we ingest the data from the collection(s) of Strapi for the chatGPT?

koliapp2019 avatar May 28 '23 06:05 koliapp2019

We can take the above requirement as a custom development and build it for a fee. If you are interested, please write to us at [email protected]

arun-hel avatar May 29 '23 05:05 arun-hel

@koliapp2019 @AsyncWeb

There is a way to access any database using the following library, here the documentation: js.langchain.com

My example is limited to asking/answering a table, Right now I’m using Postgres, you can use other DB

I understand that it can be configured for split data, embedding, vectorization.

I hope the example helped you.

Example of use

  • [x] IMPORTANT: include the OPENAI_API_KEY env
  • [x] After installing the typeorm go to the Install a database driver secction, you will find the package needed.

import express, { Router, Request, Response } from "express";
import { DataSource } from "typeorm";
import { OpenAI } from "langchain/llms/openai";
import { SqlDatabase } from "langchain/sql_db";
import { SqlDatabaseChain } from "langchain/chains";

const router = Router();

router.get("/", async (req: Request, res: Response) => {
  try {
    const datasource = new DataSource({
      type: "postgres",
      port: ,
      database: "",
      password: "",
      username: "",
      host: "",
    });

    const db = await SqlDatabase.fromDataSourceParams({
      appDataSource: datasource,
      includesTables: ["tableName"], // table name
    });

    const chain = new SqlDatabaseChain({
      llm: new OpenAI({ temperature: 0.7 }),
      database: db,
    });

    const response = await chain.call({
      query: "How many data are there?",
    });

    res.status(200).json(response);
  } catch (error) {
    console.error("Error:", error);
    res.status(500).json({ error: "Internal server error" });
  }
});

export default [
  {
    path: "/api",
    router: router,
  },
];

chrismichaelps avatar May 29 '23 12:05 chrismichaelps

How do we integrate this langchain into this chatgpt plugin?

koliapp2019 avatar May 29 '23 13:05 koliapp2019

@koliapp2019

The library does it for you, you just have to add the env OPENAI_API_KEY or set the key in the openAIApiKey property. Then you're good to go!

  llm: new OpenAI({ temperature: 0.7, openAIApiKey: '' }),

chrismichaelps avatar May 29 '23 13:05 chrismichaelps

What do you mean? Just set the open api key in the .env file before starting the strapi server? No coding involved?

koliapp2019 avatar May 31 '23 09:05 koliapp2019

@koliapp2019 The code is adapted for express but you can generate a custom strapi controller, use the whole body of the code as reference. ,

But you have to specify the tables as reference.

 includesTables: ["tableName", "..."], // table name

and the datasource type.

type: "postgres", // in this example I'm using postgres

chrismichaelps avatar May 31 '23 11:05 chrismichaelps

I see. Actually that defeats the very purpose of using the plugin itself. If we need to code ourselves, we do not need the plugin.

Thanks for the clarification. We will not use this plugin then. We are looking for a no code solution actually.

koliapp2019 avatar Jun 02 '23 03:06 koliapp2019

Currently I see only 2 models are available. In case of fine-tuning a model, there will be a custom fine-tuned version of text-davinci-003 that will be listed in OpenAI platform. It would be great to make custom fine-tuned models available via model selection.

idesignzone avatar Jul 11 '23 17:07 idesignzone

I get -

Failed to calculate number of tokens, falling back to approximate count [2023-07-16 08:25:08.190] error: Request failed with status code 404 Error: Request failed with status code 404

Any idea how to fix it?

thanks!

On Mon, May 29, 2023 at 9:30 PM Chris Michael @.***> wrote:

@koliapp2019 https://github.com/koliapp2019

The library does it for you, you just have to add the env OPENAI_API_KEY or set the key in the openAIApiKey property. Then you're good to go!

llm: new OpenAI({ temperature: 0.7, openAIApiKey: '' }),

— Reply to this email directly, view it on GitHub https://github.com/AsyncWeb/strapi-chatgpt/issues/3#issuecomment-1567143538, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANI4DPOW3ISHQVEITDDEFM3XISQGZANCNFSM6AAAAAAXC3ODO4 . You are receiving this because you were mentioned.Message ID: @.***>

koliapp2019 avatar Jul 15 '23 08:07 koliapp2019

Turned out to be if you set both OPEN_API_KEY and AZURE_OPEN_API_KEY, the chatGPT will get confused and give that error.

koliapp2019 avatar Jul 29 '23 07:07 koliapp2019