asyncwebio / strapi-chatgpt

Integrate ChatGPT into your Strapi application. You get both a UI to interact with ChatGPT and an API end-points to integrate into your applications.
MIT License
17 stars 5 forks source link

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

Open ChrisMichaelPerezSantiago opened 1 year ago

ChrisMichaelPerezSantiago commented 1 year ago

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! :)

koliapp2019 commented 1 year ago

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

arun-hel commented 1 year ago

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 hello@higheredlab.com

ChrisMichaelPerezSantiago commented 1 year ago

@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


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,
  },
];
koliapp2019 commented 1 year ago

How do we integrate this langchain into this chatgpt plugin?

ChrisMichaelPerezSantiago commented 1 year ago

@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: '' }),
koliapp2019 commented 1 year ago

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

ChrisMichaelPerezSantiago commented 1 year ago

@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
koliapp2019 commented 1 year ago

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.

idesignzone commented 1 year ago

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.

koliapp2019 commented 1 year ago

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 commented 1 year ago

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.