Hello everyone,
I am currently building a chatbot using Dialogflow CX and integrating it with GPT-3.5 Turbo model. The intent and the fallback are working fine, and I can even see the generated responses in the console logs. However, the chatbot isn’t displaying the responses.
Here’s a snippet of my code:
const txtFilename = "./xxxxx";
const txtPath = `./${txtFilename}.txt`;
const VECTOR_STORE_PATH = `${txtFilename}.index`;
console.log("txtFilename", txtFilename)
app.intent('Default Welcome Intent', (conv) => {
conv.ask('Hello! How can I assist you today?');
});
// Make sure to add a fallback intent
app.fallback((conv) => {
const runWithEmbeddings = async () => {
const text1 = conv.query;
console.log("text1", text1);
const textQuery = conv.body.text;
console.log("testim", textQuery);
const model = new OpenAI({ modelName: "gpt-3.5-turbo", streaming: true });
const dialogflowRequest = conv.request;
console.log("dialogflowRequest", dialogflowRequest);
// Vektör deposu dosyasının var olup olmadığını kontrol etmek için
let vectorStore;
if (fs.existsSync(VECTOR_STORE_PATH)) {
// Eğer vektör deposu dosyası varsa, belleğe yükler
console.log('Vector Exists..');
vectorStore = await HNSWLib.load(VECTOR_STORE_PATH, new OpenAIEmbeddings());
} else {
// Vektör deposu dosyası yoksa, oluşturuyo
// Giriş metin dosyasını okumak için
const text = fs.readFileSync(txtPath, 'utf8');
// Belirli bir parça boyutuyla RecursiveCharacterTextSplitter oluştur
const textSplitter = new RecursiveCharacterTextSplitter({ chunkSize: 1000 });
// Giriş metnini belgelere böl
const docs = await textSplitter.createDocuments([text]);
// txt kullanarak yeni bir vektör deposu oluştur
vectorStore = await HNSWLib.fromDocuments(docs, new OpenAIEmbeddings());
// Vektör deposunu bir dosyaya kaydet
await vectorStore.save(VECTOR_STORE_PATH);
}
// başlatılmış OpenAI modelini ve vektör deposu alıcıyı geçirerek bir RetrievalQAChain oluştur
const chain = RetrievalQAChain.fromLLM(model, vectorStore.asRetriever());
// giriş sorusuyla RetrievalQAChain'i çağır ve sonucu 'res' değişkeninde sakla
const res1 = await chain.call({
query: textQuery,
});
var parameters = conv.contexts.get('parameter_context');
console.log("parameters", parameters);
console.log("test1", { res1 });
console.log("test2:", res1.text)
return res1.text;
};
return runWithEmbeddings()
.then((resultText) => {
conv.ask(resultText); // Make sure to set a response
})
.catch((error) => {
console.error(error);
conv.close('An error occurred.');
});
});
The function runWithEmbeddings
seems to be executing properly and I am able to log the response res1.text
. However, the chatbot interface doesn’t display this text.
Is there anything I am missing or doing wrong? Any insights would be appreciated. Thank you!