Skip to content

Commit

Permalink
Merge pull request #18 from jay-m-dev/NickGPTBranch
Browse files Browse the repository at this point in the history
update function to extract packages from given code.
  • Loading branch information
HyunjunA authored May 12, 2023
2 parents 3a1e514 + a8a68f1 commit 683cb08
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 12 deletions.
17 changes: 12 additions & 5 deletions lab/webapp/src/components/ChatGPT/ChatBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,16 @@ const ChatBox = () =>
const input = e.target.value;
console.log("input-length", input.length)

if (input.length <= 200) {


if (input.length <= 800) {
// document.querySelector(".submit").disabled = false;
// find child who has className .submit from current e.target
e.target.parentNode.querySelector(".submit").disabled = false;
setChatInput(input);
}

if (input.length > 200) {
if (input.length > 800) {

// make the submit button disabled
e.target.parentNode.querySelector(".submit").disabled = true;
Expand Down Expand Up @@ -803,9 +805,11 @@ const ChatMessage = ({key,message,datasetId,experimentId,updateAfterRuningCode,m

// console.log("code-findTheLastCodeMessageFromHTML", tempCode)


disableReadingInput();

await submitErrorWithCode(e, tempCode)
await submitErrorWithCode(e, tempCode);

enableReadingInput();

// // console.log("chatLog-Errno",chatLog)

Expand Down Expand Up @@ -1227,6 +1231,9 @@ const ChatMessage = ({key,message,datasetId,experimentId,updateAfterRuningCode,m
let packagesNotInstalled = await checkCodePackages(packageNames);

console.log("install-packagesNotInstalled", packagesNotInstalled)


// doubleCheckPackagesWithLLM(packagesNotInstalled);



Expand All @@ -1239,7 +1246,7 @@ const ChatMessage = ({key,message,datasetId,experimentId,updateAfterRuningCode,m



// console.log("resp_runExtractedCode", resp_runExtractedCode)
console.log("resp_runExtractedCode", resp_runExtractedCode)

// e.target.textContent = "Installed";

Expand Down
75 changes: 68 additions & 7 deletions lab/webapp/src/components/ChatGPT/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,9 @@ export default function ChatGPT({experiment}) {
// please remove "Please wait while I am thinking..." by system from chatLogNewFormat
let chatLogNewFormatFiltered = chatLogNewFormat.filter((item) => item.content !== "Please wait while I am thinking...")

// please remove item if item content includes "The tabular data is"
chatLogNewFormatFiltered = chatLogNewFormatFiltered.filter((item) => !item.content.includes("The tabular data is"))

console.log("chatLogNewFormatFiltered",chatLogNewFormatFiltered)

// remove the last message from user
Expand Down Expand Up @@ -831,19 +834,28 @@ export default function ChatGPT({experiment}) {
let codeSplit = code.split("\n");
codeSplit.forEach((item) => {
if ((item.includes("import") && item.includes("as")) || (item.includes("from") && item.includes("import")) ){
let itemSplit = item.split(" ");
// import sklearn.datasets as datasets
// for the above case.
let pack = itemSplit[1].split(".")[0];
// find the index where "import" or from are located
let index_import = item.indexOf("import");
let index_from = item.indexOf("from");

console.log("index_import",index_import)
console.log("index_from",index_from)
if (index_import === 0|| index_from === 0){
let itemSplit = item.split(" ");
// import sklearn.datasets as datasets
// for the above case.
let pack = itemSplit[1].split(".")[0];

packages.push(pack);
}
}
})

console.log("packages",packages)
return packages;
}

// check if the packages are already installed or not
async function checkCodePackages(packagesArray)
{

Expand Down Expand Up @@ -913,6 +925,42 @@ export default function ChatGPT({experiment}) {

}


async function doubleCheckPackagesWithLLM(packagesNotInstalled){

// my prompt eng
let preSet =`assume that you have the list of python packages: ${packagesNotInstalled}, that you want to install. However, you are not sure the list of python packages could be used to install the package. For example, let's assume that the list includes sklearn. However, when you install sklearn, you should use the official name, scikit-learn. For example, pip install sklearn does not work. But pip install scikit-learn works. So, you want to check if the list of python packages include official name of python packages. If not, you want to convert the list of python packages to the list of official name of python packages. Please give me the list of official name of python packages by unofficial name.Please return message in this format. {unofficial name:official name},
that is, {sklearn:scikit-learn}.
`;


console.log("doubleCheckPackagesWithLLM-packagesNotInstalled",packagesNotInstalled)

let data = await openaiChatCompletions(currentModel,preSet)

console.log("doubleCheckPackagesWithLLM-data",data)

var messageFromOpenai = data.choices[0].message['content'];

console.log("doubleCheckPackagesWithLLM-messageFromOpenai",messageFromOpenai)

return messageFromOpenai;



}

function convertToOfficialPackageName(listOfOfficialPackageName,packagesNotInstalled){
// listOfOfficialPackageName is string like {sklearn:scikit-learn}

// convert listOfOfficialPackageName to object
let listOfOfficialPackageNameObject = JSON.parse(listOfOfficialPackageName);

console.log("convertToOfficialPackageName-listOfOfficialPackageNameObject",listOfOfficialPackageNameObject)



}
// check there is first Three backticks and python

// function checkThreeBackticksFromMessage(message){
Expand Down Expand Up @@ -1188,6 +1236,15 @@ export default function ChatGPT({experiment}) {
let packagesOfCode = extractPackagesOfCode(extractedCodeTemp);

let packagesNotInstalled = await checkCodePackages(packagesOfCode)


// make official package names of the packagesNotInstalled using LLM
// let listOfOfficialPackageName=await doubleCheckPackagesWithLLM(packagesNotInstalled)

// convert to the official package names
// let officialPackagesNotInstalled=convertToOfficialPackageName(listOfOfficialPackageName,packagesNotInstalled)




if (packagesNotInstalled.length > 0){
Expand Down Expand Up @@ -1456,7 +1513,7 @@ export default function ChatGPT({experiment}) {



data= await openaiChatCompletions(currentModel,preSet)
data = await openaiChatCompletions(currentModel,preSet)

var messageFromOpenai = data.choices[0].message['content'];

Expand Down Expand Up @@ -2143,14 +2200,18 @@ export default function ChatGPT({experiment}) {

// make submit button disabled
let submitButton = document.getElementsByClassName("submit")[0];
console.log("submitButton", submitButton)
// console.log("submitButton", submitButton)
submitButton.disabled = true;

// document.querySelector(".submit").disabled = false;



// make chat-input-textarea disabled
let chatInputTextarea = document.getElementsByClassName("chat-input-textarea")[0];
// console.log("chat-input-textarea", chat-input-textarea)
chatInputTextarea.disabled = true;


}

Expand All @@ -2165,7 +2226,7 @@ export default function ChatGPT({experiment}) {
submitButton.disabled = false;

let chatInputTextarea = document.getElementsByClassName("chat-input-textarea")[0];
// make chatInputTextarea abled
// // make chatInputTextarea abled
chatInputTextarea.disabled = false;

}
Expand Down

0 comments on commit 683cb08

Please sign in to comment.