Skip to content

Commit

Permalink
Merge branch 'development' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
betterbrand authored Mar 13, 2024
2 parents 021c520 + f59aa68 commit 4fd4142
Show file tree
Hide file tree
Showing 11 changed files with 206 additions and 72 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ MORPHEUS NODE

First, clone this repo.


Then, start yarn.

`yarn`
Expand All @@ -17,8 +16,9 @@ To build an executable to run on your current system's specs:

`yarn make`

Other run, test, and build scripts can be found in the package.json
Other run, test, and build scripts can be found in package.json

Please visit MOR.software to sign up as a developer to be rewarded for your merged contributions. Submit an MRC to get support for feature and improvement ideas.

Please visit MOR.software to sign up as a developer to be rewarded for your merged contributions. Submit an MRC to get support for feature and improvement ideas.

MOR.software is also the place to build, submit, deplloy, and manage all of your Smart Agents.
49 changes: 17 additions & 32 deletions forge.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { AutoUnpackNativesPlugin } from '@electron-forge/plugin-auto-unpack-nati
import { WebpackPlugin } from '@electron-forge/plugin-webpack';
import { PublisherGithub } from '@electron-forge/publisher-github';
import fs from 'fs';
import path from 'path';
import { exec } from 'child_process';

import { mainConfig, mainDevConfig } from './webpack.main.config';
Expand All @@ -18,7 +17,7 @@ const config: ForgeConfig = {
packagerConfig: {
asar: true,
name: 'morpheus',
extraResource: ['./src/executables/'],
extraResource: ['./executables/'],
icon: 'src/frontend/assets/images/circle-mor-logo',
osxSign: {
identity: process.env.APPLE_DEVELOPER_ID,
Expand All @@ -31,40 +30,34 @@ const config: ForgeConfig = {
...(process.env.APPLE_ID &&
process.env.APPLE_ID_PASSWORD &&
process.env.APPLE_TEAM_ID && {
osxNotarize: {
appleId: process.env.APPLE_ID,
appleIdPassword: process.env.APPLE_ID_PASSWORD,
teamId: process.env.APPLE_TEAM_ID,
},
}),
osxNotarize: {
appleId: process.env.APPLE_ID,
appleIdPassword: process.env.APPLE_ID_PASSWORD,
teamId: process.env.APPLE_TEAM_ID,
},
}),
},
hooks: {
postPackage: async (_, { platform, outputPaths }) => {
prePackage: async (_, platform) => {
const platformFile =
platform === 'darwin'
? 'ollama-darwin'
: platform === 'win32'
? 'ollama.exe'
: 'ollama-linux';

const outputResourceFolder = `${outputPaths[0]}${platform === 'darwin' ? '/morpheus.app/Contents' : ''}/resources/executables/`;

fs.readdir(outputResourceFolder, (err, files) => {
if (err) {
throw err;
}
const filePath = `src/executables/${platformFile}`;

files.forEach((file) => {
const localPath = path.join(outputResourceFolder, file);
platform !== 'win32'
? exec(`chmod +x ${filePath}`)
: fs.chmodSync(filePath, 755);

if (file !== platformFile) {
//fs.unlinkSync(localPath);
} else {
platform !== 'win32' ? exec(`chmod +x ${localPath}`) : fs.chmodSync(localPath, 755);
}
});
});
fs.mkdirSync('executables');
fs.copyFileSync(filePath, `executables/${platformFile}`);
},
postPackage: async () => {
fs.rmSync('executables', { recursive: true, force: true });
}
},
rebuildConfig: {},
makers: [
Expand Down Expand Up @@ -94,14 +87,6 @@ const config: ForgeConfig = {
},
},
},
// contents: [
// {
// x: 410,
// y: 220,
// type: 'link',
// path: '/Applications',
// },
// ],
}),
],
publishers: [
Expand Down
2 changes: 1 addition & 1 deletion src/backend/services/ollama.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export const askOllama = async (model: string, message: string) => {
},
{
role: 'user',
content: `Answer the following question in a valid formatted JSON object without comments with both the response and action fields deduced from the user's question. Adhere strictly to JSON syntax without comments. Question: ${message}. Response:`,
content: `Answer the following query in a valid formatted JSON object without comments with both the response and action fields deduced from the user's question. Adhere strictly to JSON syntax without comments. Query: ${message}. Response: { "response":`,
},
],
});
Expand Down
37 changes: 33 additions & 4 deletions src/backend/services/prompts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const MOR_PROMPT = `###System:
You are MORPHEUS, but you prefer to be called a SmartAgent. You are designed to assist users with MetaMask transactions and queries in a consistent JSON format. Your responses should always contain a "response" field for textual feedback
You are MORPHEUS, but you prefer to be called a SmartAgent. You are designed to assist users with MetaMask transactions and queries in a consistent JSON format. You handle bad queries gracefully as detailed in the "Bad Queries" section. Your responses should always contain a "response" field for textual feedback
and an "action" field for transaction details. There are multiple action types, as detailed in the "Action Types" section.
###Response Format:
Expand All @@ -10,7 +10,7 @@ All responses must follow this JSON structure:
// Action details or an empty object
}
}
Respond only in valid JSON without any comments. If the user is initiating an action, create a valid transaction JSON object from their question. If the user is not initiating an action, the "action" field should be an empty object. The object should be structured based on the type of action they wish to initiate. Keep the "response" field short, using 3 sentences maximum.
Respond only in valid JSON without any comments. If the user is initiating an action, create a valid transaction JSON object from their query. If the user is not initiating an action, the "action" field should be an empty object. The object should be structured based on the type of action they wish to initiate. Keep the "response" field short, using 3 sentences maximum.
###Action Types:
1. **Transfer**: For users wanting to transfer ETH. The user's input should provide the target address and ETH amount.
Expand All @@ -33,10 +33,21 @@ Respond only in valid JSON without any comments. If the user is initiating an ac
}
}
3. **Address Inquiry**: For users inquiring about their wallet address. For all Address inquiries, the "action" field should contain only the "type" key with the value "Address". The "response" field should be set to empty.
- **Format**:
{
"response": "",
"action": {
"type": "Address"
}
}
###Error Handling:
For actions requiring more information (e.g., missing ETH amount for transfers), respond with a request for the necessary details:
{
"response": "Please provide the amount in ETH and the target address for the transfer.",
"response": "Request for more information goes here",
"action": {}
}
Expand All @@ -53,22 +64,40 @@ For actions requiring more information (e.g., missing ETH amount for transfers),
// Balance Inquiries
- **Balance inquiry**:
- Questions: "What's my balance?", "Could you tell me my current balance, please?", "how much eth I got?", "Hey Morpheus, can you show me my balance now?", "I need to see my ETH balance, can you help?"
- Questions: "What's my balance?", "Could you tell me my current balance, please?", "how much eth I got?", "Hey Morpheus, can you show me my balance now?", "I need to see my ETH balance, can you help?", "balance?"
- Response for all:
{
"response": "",
"action": {"type": "Balance"}
}
// Address Inquiries
- **Address inquiry**:
- Question: "What is my wallet address?", "What is my public Eth address?", "Can you show me my wallet address?", "Hey Morpheus, can you tell me my wallet address?"
- Response for all:
{
"response": "",
"action": {"type": "Address"}
}
// Insufficient Information for Transfer
- **Insufficient info for transfer**:
- Question: "I want to transfer ETH."
- Response:
{
"response": "Please provide the ETH amount and the target address for the transfer.",
"action": {}
}
- **Bad Query**:
- Questions: "please explain", "why does", "who is"
- Response:
{
"response": "Sorry! I dont think I understand, what would you like me to explain?",
"action": {}
}
// Non-action Queries
- **Non-action query (e.g., general question)**:
- Question: "What is stETH?"
Expand Down
2 changes: 0 additions & 2 deletions src/frontend/components/buttons/connect-wallet-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export default forwardRef<HTMLDivElement>((props: Props, ref) => {
<ConnectWalletButton.Wrapper onClick={onClick} ref={ref}>
<ConnectWalletButton.Logo src={wallet} />
<ConnectWalletButton.Text>{connected ? 'connected' : 'connect'}</ConnectWalletButton.Text>
{!connecting && <ConnectWalletButton.Badge $connected={connected} $connecting={connecting} />}
</ConnectWalletButton.Wrapper>
);
});
Expand Down Expand Up @@ -60,7 +59,6 @@ const ConnectWalletButton = {
font-family: ${(props) => props.theme.fonts.family.primary.regular};
font-size: ${(props) => props.theme.fonts.size.small};
color: ${(props) => props.theme.colors.notice};
margin-right: 10px;
`,
Badge: Styled.div<BadgeProps>`
display: flex;
Expand Down
5 changes: 3 additions & 2 deletions src/frontend/components/buttons/navigation-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ const MainNavButton = {
height: 100%;
margin: 0 15px;
align-items: center;
color: ${(props) => (props.active === 'active' ? props.theme.colors.emerald : props.theme.colors.balance)};
color: ${(props) => props.theme.colors.balance};
opacity: ${(props) => (props.active === 'active' ? 1 : 0.5)};
font-family: ${(props) => props.theme.fonts.family.primary.bold};
font-size: ${(props) => props.theme.fonts.size.medium};
text-decoration: none;
transition: border 0.25s, color 0.25s;
&:hover span {
color: ${(props) => props.theme.colors.emerald};
opacity: 0.75;
}
`,
Icon: Styled.img`
Expand Down
8 changes: 6 additions & 2 deletions src/frontend/components/layout/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,22 @@ const Main = {
display: flex;
width: 100%;
height: ${(props) => props.theme.layout.topBarHeight}px;
flex-shrink: 0;
`,
MainWrapper: Styled.div`
display: flex;
width: 80%;
height: 70%;
max-width: 850px;
flex-grow: 1;
border-radius: 30px;
border: 5px solid ${(props) => props.theme.colors.hunter};
padding: 10px;
overflow: hidden;
`,
BottomWrapper: Styled.div`
display: flex;
width: 100%;
height: 20%;
height: ${(props) => props.theme.layout.bottomBarHeight}px;
flex-shrink: 0;
`,
};
3 changes: 2 additions & 1 deletion src/frontend/theme/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface ITheme {
};
layout: {
topBarHeight: number;
bottomBarHeight: number;
};
fonts: {
family: {
Expand Down Expand Up @@ -38,8 +39,8 @@ const common = {
balance: '#FFFFFF',
},
layout: {
leftBarWidth: 200,
topBarHeight: 130,
bottomBarHeight: 130,
},
fonts: {
size: {
Expand Down
67 changes: 67 additions & 0 deletions src/frontend/utils/chain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
type ChainInfo = {
chainId: string;
chainName: string;
rpcUrls: string[];
iconUrls: string[];
nativeCurrency: {
name: string;
symbol: string;
decimals: number;
};
blockExplorerUrls: string[];
};

const params: ChainInfo[] = [
{
chainId: '0x64',
chainName: 'Gnosis',
rpcUrls: ['https://rpc.ankr.com/gnosis'],
iconUrls: [
'https://xdaichain.com/fake/example/url/xdai.svg',
'https://xdaichain.com/fake/example/url/xdai.png',
],
nativeCurrency: {
name: 'xDAI',
symbol: 'xDAI',
decimals: 18,
},
blockExplorerUrls: ['https://blockscout.com/poa/xdai/'],
},
{
chainId: '0xaa36a7',
chainName: 'Sepolia',
rpcUrls: ['https://rpc.notadegen.com/eth/sepolia'],
iconUrls: [],
nativeCurrency: {
name: 'ETH',
symbol: 'ETH',
decimals: 18,
},
blockExplorerUrls: ['https://sepolia.etherscan.io/'],
},
{
chainId: '0xa4b1',
chainName: 'arbitrum',
rpcUrls: ['https://arb1.arbitrum.io/rpc'],
iconUrls: [],
nativeCurrency: {
name: 'ARB',
symbol: 'ARB',
decimals: 18,
},
blockExplorerUrls: ['https://arbiscan.io/'],
},
];

export function getChainInfoByChainId(chainId: string): ChainInfo | undefined {
return params.find((chain) => chain.chainId === chainId);
}

// const chainIdToSearch = "0x64";
// const chainInfo = getChainInfoByChainId(chainIdToSearch);

// if (chainInfo) {
// console.log("Found chain info:", chainInfo);
// } else {
// console.log("Chain info not found for chainId:", chainIdToSearch);
// }
13 changes: 4 additions & 9 deletions src/frontend/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,17 @@ 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, '');
// jsonString = jsonString.replace(/(?<!\\)\/\/.*?(?=\n|$)/gm, '');
let parsed: string;
try {
parsed = JSON.parse(jsonString);
} catch (error) {
try {
jsonString = jsonString + '}'; //llama often forgets this
parsed = JSON.parse(jsonString);
} catch (error) {
new Error('Ollama error');
return { response: 'error', action: {} };
}
new Error('Ollama error');
return { response: 'error', action: {} };
}

if (isModelResponse(parsed)) {
return { response: parsed.response, action: parsed.action };
} else {
Expand Down
Loading

0 comments on commit 4fd4142

Please sign in to comment.