From 409d8b0c255266b8d048a61df1235cb81dd2e3c1 Mon Sep 17 00:00:00 2001 From: Adam Goth Date: Tue, 21 May 2024 08:43:42 +0200 Subject: [PATCH 1/4] Fix build errors --- src/backend/services/ollama.ts | 15 ++++++------- src/backend/services/prompts.ts | 2 +- src/backend/services/rag.ts | 10 ++------- yarn.lock | 37 +++++++++++++++++++-------------- 4 files changed, 30 insertions(+), 34 deletions(-) diff --git a/src/backend/services/ollama.ts b/src/backend/services/ollama.ts index 7dbe4ad..84a5e8b 100644 --- a/src/backend/services/ollama.ts +++ b/src/backend/services/ollama.ts @@ -4,18 +4,17 @@ import { execFile, ChildProcess } from 'child_process'; import fs from 'fs'; import { sendOllamaStatusToRenderer } from '..'; import { MOR_PROMPT } from './prompts'; - import { RAG_MOR_PROMPT } from './prompts'; import { ChatPromptTemplate, SystemMessagePromptTemplate, HumanMessagePromptTemplate, } from '@langchain/core/prompts'; -import { RunnableParallel, RunnableSequence, RunnablePassthrough } from '@langchain/core/runnables'; +import { RunnableSequence, RunnablePassthrough } from '@langchain/core/runnables'; import { StringOutputParser } from '@langchain/core/output_parsers'; // Imports -import { contractAbiRetriever, metamaskExamplesRetriever } from './rag'; +import { contractsAbiRetrieval, metamaskExamplesRetrieval } from './rag'; // events import { IpcMainChannel } from '../../events'; @@ -170,8 +169,7 @@ export const askOllama = async (model: string, message: string) => { }); }; -export const askOllamaRAG = async (model: string, message: string) => { - +export const askOllamaRAG = async (model: any, message: string) => { // Load Prompt Template let promptTemplate = RAG_MOR_PROMPT; let NLQ = message; @@ -186,11 +184,11 @@ export const askOllamaRAG = async (model: string, message: string) => { const prompt = ChatPromptTemplate.fromMessages(messages); // Create Chain - const chain = RunnableParallel.from([ + const chain = RunnableSequence.from([ { nlq: new RunnablePassthrough(), - context: contractAbiRetriever, - metamask_examples: metamaskExamplesRetriever, + context: contractsAbiRetrieval, + metamask_examples: metamaskExamplesRetrieval, }, prompt, model, @@ -199,7 +197,6 @@ export const askOllamaRAG = async (model: string, message: string) => { // Invoke the Chain for the NLQ response from the AI return await chain.invoke({ nlq: NLQ }); - }; export const getOrPullModel = async (model: string) => { diff --git a/src/backend/services/prompts.ts b/src/backend/services/prompts.ts index 388d631..9d34388 100644 --- a/src/backend/services/prompts.ts +++ b/src/backend/services/prompts.ts @@ -112,7 +112,7 @@ export const errorHandling = `###Error Handling: - For buy or transfer actions without a specified ETH amount, request the missing details. - For sell actions without a specified token amount, request the missing details. - Never include comments within the JSON objects returned. -- Plan for detailed error messages for unsupported or incomplete action requests to guide users effectively.`; +- Plan for detailed error messages for unsupported or incomplete action requests to guide users effectively. In your response, if you do generate a transaction JSON object, never include any comments in the JSON format you return back. `; diff --git a/src/backend/services/rag.ts b/src/backend/services/rag.ts index d7d61ad..f7b9e93 100644 --- a/src/backend/services/rag.ts +++ b/src/backend/services/rag.ts @@ -87,7 +87,6 @@ const serviceContext = serviceContextFromDefaults({ chunkSize: 4096, }); - async function indexCreation() { var index = await VectorStoreIndex.fromDocuments(documentsContractsMetadata, { serviceContext }); console.log('Index:', index); @@ -108,7 +107,6 @@ async function loadContractABIs() { console.log('Formatted Contracts:', formattedContracts); return createInMemoryVectorStore(formattedContracts); - } catch (error) { console.error('Error loading contracts:', error); throw error; @@ -130,8 +128,7 @@ const createInMemoryVectorStore = async (contracts: string[]): Promise => { console.log('Loading Contract ABIs...'); -export async function contractsRetreival() { - +export async function contractsAbiRetrieval() { // Load Contract ABIs const abiInMemoryVectorStore = await loadContractABIs(); @@ -139,7 +136,6 @@ export async function contractsRetreival() { const contractAbiRetriever = await abiInMemoryVectorStore.asRetriever({ k: TOP_K_ABIS }); return contractAbiRetriever; - } // Load Metamask Examples @@ -169,7 +165,6 @@ const createFaissStoreFromExamples = async (examples: any[]): Promise => { }; export async function metamaskExamplesRetrieval() { - // Metamask Examples const metamaskExamplesInMemoryVectorStore = await loadMetamaskExamples(); @@ -179,5 +174,4 @@ export async function metamaskExamplesRetrieval() { }); return metamaskExamplesRetriever; - -}; \ No newline at end of file +} diff --git a/yarn.lock b/yarn.lock index a2cb8e0..ed9ba37 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4661,6 +4661,11 @@ ansi-styles@^5.0.0: resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-5.2.0.tgz#07449690ad45777d1924ac2abb2fc8895dba836b" integrity sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA== +ansi-styles@^6.0.0, ansi-styles@^6.2.1: + version "6.2.1" + resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-6.2.1.tgz#0e62320cf99c21afff3b3012192546aacbfb05c5" + integrity sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug== + any-promise@^1.0.0, any-promise@^1.3.0: version "1.3.0" resolved "https://registry.yarnpkg.com/any-promise/-/any-promise-1.3.0.tgz#abc6afeedcea52e809cdc0376aed3ce39635d17f" @@ -5683,7 +5688,7 @@ color@^4.2.3: color-convert "^2.0.1" color-string "^1.9.0" -colorette@^2.0.10, colorette@^2.0.19: +colorette@^2.0.10, colorette@^2.0.19, colorette@^2.0.20: version "2.0.20" resolved "https://registry.yarnpkg.com/colorette/-/colorette-2.0.20.tgz#9eb793e6833067f7235902fcd3b09917a000a95a" integrity sha512-IfEDxwoWIjkeXL1eXcDiow4UbKjhLdq6/EuSVR9GMN7KVH3r9gQ83e73hsz1Nd1T3ijd5xv1wcWRYO+D6kCI2w== @@ -5703,6 +5708,11 @@ combined-stream@^1.0.8: dependencies: delayed-stream "~1.0.0" +commander@11.1.0: + version "11.1.0" + resolved "https://registry.yarnpkg.com/commander/-/commander-11.1.0.tgz#62fdce76006a68e5c1ab3314dc92e800eb83d906" + integrity sha512-yPVavfyCcRhmorC7rWlkHn15b4wDVgVmBA7kV4QVBsF7kv/9TKJAbAXVTxvTnwP8HHKjRCJDClKbciiYS7p0DQ== + commander@^10.0.1: version "10.0.1" resolved "https://registry.yarnpkg.com/commander/-/commander-10.0.1.tgz#881ee46b4f77d1c1dccc5823433aa39b022cbe06" @@ -7191,21 +7201,6 @@ execa@^5.0.0: signal-exit "^3.0.3" strip-final-newline "^2.0.0" -execa@^8.0.1: - version "8.0.1" - resolved "https://registry.yarnpkg.com/execa/-/execa-8.0.1.tgz#51f6a5943b580f963c3ca9c6321796db8cc39b8c" - integrity sha512-VyhnebXciFV2DESc+p6B+y0LjSm0krU4OgJN44qFAhBY0TJ+1V61tYD2+wHusZ6F9n5K+vl8k0sTy7PEfV4qpg== - dependencies: - cross-spawn "^7.0.3" - get-stream "^8.0.1" - human-signals "^5.0.0" - is-stream "^3.0.0" - merge-stream "^2.0.0" - npm-run-path "^5.1.0" - onetime "^6.0.0" - signal-exit "^4.1.0" - strip-final-newline "^3.0.0" - expand-template@^2.0.3: version "2.0.3" resolved "https://registry.yarnpkg.com/expand-template/-/expand-template-2.0.3.tgz#6e14b3fcee0f3a6340ecb57d2e8918692052a47c" @@ -9243,6 +9238,11 @@ lie@~3.3.0: dependencies: immediate "~3.0.5" +lilconfig@3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/lilconfig/-/lilconfig-3.0.0.tgz#f8067feb033b5b74dab4602a5f5029420be749bc" + integrity sha512-K2U4W2Ff5ibV7j7ydLr+zLAkIg5JJ4lPn1Ltsdt+Tz/IjQ8buJ55pZAxoP34lqIiwtF9iAvtLv3JGv7CAyAg+g== + lines-and-columns@^1.1.6: version "1.2.4" resolved "https://registry.yarnpkg.com/lines-and-columns/-/lines-and-columns-1.2.4.tgz#eca284f75d2965079309dc0ad9255abb2ebc1632" @@ -12601,6 +12601,11 @@ strict-uri-encode@^2.0.0: resolved "https://registry.yarnpkg.com/strict-uri-encode/-/strict-uri-encode-2.0.0.tgz#b9c7330c7042862f6b142dc274bbcc5866ce3546" integrity sha512-QwiXZgpRcKkhTj2Scnn++4PKtWsH0kpzZ62L2R6c/LUVYv7hVnZqcg2+sMuT6R7Jusu1vviK/MFsu6kNJfWlEQ== +string-argv@0.3.2: + version "0.3.2" + resolved "https://registry.yarnpkg.com/string-argv/-/string-argv-0.3.2.tgz#2b6d0ef24b656274d957d54e0a4bbf6153dc02b6" + integrity sha512-aqD2Q0144Z+/RqG52NeHEkZauTAUWJO8c6yTftGJKO3Tja5tUgIfmIl6kExvhtxSDP7fXB6DvzkfMpCd/F3G+Q== + string-collapse-leading-whitespace@^7.0.7: version "7.0.7" resolved "https://registry.yarnpkg.com/string-collapse-leading-whitespace/-/string-collapse-leading-whitespace-7.0.7.tgz#b47986dd7f96e8a6b5bbd0e08f14755bd60915f9" From 7b983541d28a8c49cc8ebc7d5c424038dbb177f8 Mon Sep 17 00:00:00 2001 From: Adam Goth Date: Tue, 21 May 2024 08:44:08 +0200 Subject: [PATCH 2/4] Handle string to json --- src/frontend/utils/utils.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/frontend/utils/utils.ts b/src/frontend/utils/utils.ts index 4282059..f99c34d 100644 --- a/src/frontend/utils/utils.ts +++ b/src/frontend/utils/utils.ts @@ -1,20 +1,16 @@ -import { json } from 'react-router-dom'; import { ModelResponse } from './types'; export const parseResponse = (jsonString: string) => { - // Assert the type of the parsed object. console.log(jsonString); - // uses regex to remove comments that llama sometimes includes in the JSON string - // ranges from // to the end of the line or the end of the string - // jsonString = jsonString.replace(/(? { }; const isModelResponse = (object: any): object is ModelResponse => { - return 'response' in object && 'action' in object; + return typeof object.response === 'string' && typeof object.action === 'object'; }; From e86988ece3c05f4705da803575571bd73909ee80 Mon Sep 17 00:00:00 2001 From: Adam Goth Date: Sat, 25 May 2024 11:08:11 +0200 Subject: [PATCH 3/4] Fix webpack rules, handle json parse error --- src/backend/services/rag.ts | 8 +++++++- webpack.rules.ts | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/backend/services/rag.ts b/src/backend/services/rag.ts index f7b9e93..c7d7ffa 100644 --- a/src/backend/services/rag.ts +++ b/src/backend/services/rag.ts @@ -53,7 +53,13 @@ function extractMetadataAbi(contract: any): any { contractFilenames.forEach((contractFilename) => { let filePath: string = path.join(CONTRACTS_DIR, contractFilename); let rawData: string = fs.readFileSync(filePath, 'utf8'); - let payload: any = JSON.parse(rawData); + let payload: any; + try { + payload = JSON.parse(rawData); + } catch (error) { + console.error(`Error parsing ${contractFilename}: ${error}`); + return; + } if (payload.contracts) { payload.contracts.forEach((contract: any) => { diff --git a/webpack.rules.ts b/webpack.rules.ts index b3253cb..54373eb 100644 --- a/webpack.rules.ts +++ b/webpack.rules.ts @@ -28,4 +28,10 @@ export const rules: Required['rules'] = [ }, }, }, + { + test: /\.js$/, + resolve: { + fullySpecified: false, + }, + }, ]; From b9e9f7ef2a7c24cc5d02250afa1f71bbf52378eb Mon Sep 17 00:00:00 2001 From: Adam Goth Date: Wed, 29 May 2024 17:23:20 +0200 Subject: [PATCH 4/4] Fix undefined string --- forge.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/forge.config.ts b/forge.config.ts index f50cd15..eac1650 100644 --- a/forge.config.ts +++ b/forge.config.ts @@ -63,7 +63,7 @@ const config: ForgeConfig = { makers: [ new MakerSquirrel({ setupIcon: 'src/frontend/assets/images/circle-mor-logo.ico', - loadingGif: 'undefined', // Disable the loading GIF + loadingGif: undefined, // Disable the loading GIF }), new MakerZIP({}, ['darwin']), new MakerRpm({}),