Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix development build #68

Open
wants to merge 4 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion forge.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({}),
Expand Down
15 changes: 6 additions & 9 deletions src/backend/services/ollama.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion src/backend/services/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
`;
Expand Down
18 changes: 9 additions & 9 deletions src/backend/services/rag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -87,7 +93,6 @@ const serviceContext = serviceContextFromDefaults({
chunkSize: 4096,
});


async function indexCreation() {
var index = await VectorStoreIndex.fromDocuments(documentsContractsMetadata, { serviceContext });
console.log('Index:', index);
Expand All @@ -108,7 +113,6 @@ async function loadContractABIs() {

console.log('Formatted Contracts:', formattedContracts);
return createInMemoryVectorStore(formattedContracts);

} catch (error) {
console.error('Error loading contracts:', error);
throw error;
Expand All @@ -130,16 +134,14 @@ const createInMemoryVectorStore = async (contracts: string[]): Promise<any> => {

console.log('Loading Contract ABIs...');

export async function contractsRetreival() {

export async function contractsAbiRetrieval() {
// Load Contract ABIs
const abiInMemoryVectorStore = await loadContractABIs();

// Create ABI Retriever
const contractAbiRetriever = await abiInMemoryVectorStore.asRetriever({ k: TOP_K_ABIS });

return contractAbiRetriever;

}

// Load Metamask Examples
Expand Down Expand Up @@ -169,7 +171,6 @@ const createFaissStoreFromExamples = async (examples: any[]): Promise<any> => {
};

export async function metamaskExamplesRetrieval() {

// Metamask Examples
const metamaskExamplesInMemoryVectorStore = await loadMetamaskExamples();

Expand All @@ -179,5 +180,4 @@ export async function metamaskExamplesRetrieval() {
});

return metamaskExamplesRetriever;

};
}
12 changes: 4 additions & 8 deletions src/frontend/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -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(/(?<!\\)\/\/.*?(?=\n|$)/gm, '');
let parsed: string;
let parsed: any;
try {
parsed = JSON.parse(jsonString);
} catch (error) {
new Error('Ollama error');
console.log(error);
return { response: 'error', action: {} };
}

if (isModelResponse(parsed)) {
return { response: parsed.response, action: parsed.action };
} else {
Expand All @@ -23,5 +19,5 @@ export const parseResponse = (jsonString: string) => {
};

const isModelResponse = (object: any): object is ModelResponse => {
return 'response' in object && 'action' in object;
return typeof object.response === 'string' && typeof object.action === 'object';
};
6 changes: 6 additions & 0 deletions webpack.rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,10 @@ export const rules: Required<ModuleOptions>['rules'] = [
},
},
},
{
test: /\.js$/,
resolve: {
fullySpecified: false,
},
},
];
37 changes: 21 additions & 16 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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==
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
Loading