Overview
I am developing a chatbot using Google App Script and LINE chat.
I attached 2 pieces from my entire code in this post, where are responsible for
- creating a new thread.
- Send initial message to the AI in the thread just created.
After these 2 processes, there are code for run and get response from the AI.
Question
When the program runs “STEP02: CREATE MESSAGE”, it also auto generate untitled vector store which I can find it at openAI dashbord > storage > Vector Store.
I don’t mind the program to create a new vector store responsible for storing file needed for generating response in the conversation done in the thread.
But the problem is, I have no idea how to retrieve this newly created vector store ID, therefore I cannot delete it when I am done with conversation and delete the thread.
Does anyone know how to access vector store ID?
Perhaps find out vector store ID when it is generated?
Thank you for any thoughts and advices!
//[STEP01: CREATE THREAD]
function createNewThread() {
var options = {
'method': 'post',
'headers': {
'contentType': 'application/json',
'Authorization': 'Bearer ' + OpenAI_key,
'OpenAI-Beta': 'assistants=v2'
},
'muteHttpExceptions': true // HTTP例外をミュートにする
};
try {
let response = UrlFetchApp.fetch(OPENAI_ASSISTANT_END_POINT, options);
let responseCode = response.getResponseCode();
let content = response.getContentText();
if (responseCode == 200) {
Logger.log('Success: ' + content);
//[#TEST]FOR TEST PURPOSE, DELETE AFTER TEST
pc_threadId.setValue(JSON.parse(content)["id"]);
return JSON.parse(content)["id"];
} else {
Logger.log('Error: ' + responseCode + '\n' + content);
}
} catch (e) {
Logger.log('Exception: ' + e.toString());
}
}
//[STEP02: CREATE MESSAGE]
function createMessage(threadId,userMessage){
var data = {
"role":"user",
"content":userMessage,
"attachments": [
{
"file_id": fileId_01,
"tools" : [
{
"type": "file_search"
}
]
}
],
//"file_ids": [fileId_01],
};
var options = {
'method': 'post',
'headers': {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + OpenAI_key,
'OpenAI-Beta': 'assistants=v2'
},
'payload': JSON.stringify(data)
};
try {
var response = UrlFetchApp.fetch(OPENAI_ASSISTANT_END_POINT + "/" + threadId + "/messages", options);
var responseCode = response.getResponseCode();
var content = response.getContentText();
var result = JSON.parse(response.getContentText());
Logger.log(result.id); // 応答をログに記録します
if (responseCode == 200) {
Logger.log('Success: ' + content);
}else{
Logger.log('Error: ' + responseCode + '\n' + content);
}
return result;
} catch (e) {
Logger.log(e.toString());
}
}