Skip to content

Commit 64ff9e5

Browse files
authored
Merge pull request #35 from IshShogun/development
Handle insufficent context in llama, add network function
2 parents ec19391 + de3ef0c commit 64ff9e5

File tree

4 files changed

+98
-12
lines changed

4 files changed

+98
-12
lines changed

src/backend/services/ollama.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export const askOllama = async (model: string, message: string) => {
152152
},
153153
{
154154
role: 'user',
155-
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:`,
155+
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":`,
156156
},
157157
],
158158
});

src/backend/services/prompts.ts

+17-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export const MOR_PROMPT = `###System:
2-
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
2+
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
33
and an "action" field for transaction details. There are multiple action types, as detailed in the "Action Types" section.
44
55
###Response Format:
@@ -10,7 +10,7 @@ All responses must follow this JSON structure:
1010
// Action details or an empty object
1111
}
1212
}
13-
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.
13+
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.
1414
1515
###Action Types:
1616
1. **Transfer**: For users wanting to transfer ETH. The user's input should provide the target address and ETH amount.
@@ -33,10 +33,10 @@ Respond only in valid JSON without any comments. If the user is initiating an ac
3333
}
3434
}
3535
36-
###Error Handling:
37-
For actions requiring more information (e.g., missing ETH amount for transfers), respond with a request for the necessary details:
36+
###Bad Queries:
37+
For queries requiring more information (e.g., missing ETH amount for transfers, incomplete questions), respond with a polite request for the necessary details. Follow the following pattern:
3838
{
39-
"response": "Please provide the amount in ETH and the target address for the transfer.",
39+
"response": "Request for more information goes here",
4040
"action": {}
4141
}
4242
@@ -53,22 +53,30 @@ For actions requiring more information (e.g., missing ETH amount for transfers),
5353
5454
// Balance Inquiries
5555
- **Balance inquiry**:
56-
- 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?"
56+
- 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?"
5757
- Response for all:
5858
{
5959
"response": "",
6060
"action": {"type": "Balance"}
6161
}
6262
63-
// Insufficient Information for Transfer
64-
- **Insufficient info for transfer**:
65-
- Question: "I want to transfer ETH."
63+
//Bad Queries
64+
- **Bad Query**:
65+
- Questions: "transfer", "How much eth do i have", "send"
6666
- Response:
6767
{
6868
"response": "Please provide the ETH amount and the target address for the transfer.",
6969
"action": {}
7070
}
7171
72+
- **Bad Query**:
73+
- Questions: "please explain", "why does", "who is"
74+
- Response:
75+
{
76+
"response": "Sorry! I dont think I understand, what would you like me to explain?",
77+
"action": {}
78+
}
79+
7280
// Non-action Queries
7381
- **Non-action query (e.g., general question)**:
7482
- Question: "What is stETH?"

src/frontend/utils/chain.ts

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
type ChainInfo = {
2+
chainId: string;
3+
chainName: string;
4+
rpcUrls: string[];
5+
iconUrls: string[];
6+
nativeCurrency: {
7+
name: string;
8+
symbol: string;
9+
decimals: number;
10+
};
11+
blockExplorerUrls: string[];
12+
};
13+
14+
const params: ChainInfo[] = [
15+
{
16+
chainId: '0x64',
17+
chainName: 'Gnosis',
18+
rpcUrls: ['https://rpc.ankr.com/gnosis'],
19+
iconUrls: [
20+
'https://xdaichain.com/fake/example/url/xdai.svg',
21+
'https://xdaichain.com/fake/example/url/xdai.png',
22+
],
23+
nativeCurrency: {
24+
name: 'xDAI',
25+
symbol: 'xDAI',
26+
decimals: 18,
27+
},
28+
blockExplorerUrls: ['https://blockscout.com/poa/xdai/'],
29+
},
30+
{
31+
chainId: '0xaa36a7',
32+
chainName: 'Sepolia',
33+
rpcUrls: ['https://rpc.notadegen.com/eth/sepolia'],
34+
iconUrls: [],
35+
nativeCurrency: {
36+
name: 'ETH',
37+
symbol: 'ETH',
38+
decimals: 18,
39+
},
40+
blockExplorerUrls: ['https://sepolia.etherscan.io/'],
41+
},
42+
{
43+
chainId: '0xa4b1',
44+
chainName: 'arbitrum',
45+
rpcUrls: ['https://arb1.arbitrum.io/rpc'],
46+
iconUrls: [],
47+
nativeCurrency: {
48+
name: 'ARB',
49+
symbol: 'ARB',
50+
decimals: 18,
51+
},
52+
blockExplorerUrls: ['https://arbiscan.io/'],
53+
},
54+
];
55+
56+
export function getChainInfoByChainId(chainId: string): ChainInfo | undefined {
57+
return params.find((chain) => chain.chainId === chainId);
58+
}
59+
60+
// const chainIdToSearch = "0x64";
61+
// const chainInfo = getChainInfoByChainId(chainIdToSearch);
62+
63+
// if (chainInfo) {
64+
// console.log("Found chain info:", chainInfo);
65+
// } else {
66+
// console.log("Chain info not found for chainId:", chainIdToSearch);
67+
// }

src/frontend/views/chat.tsx

+13-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
} from '../utils/transaction';
1717
import { parseResponse } from '../utils/utils';
1818
import { ActionParams } from '../utils/types';
19+
import { getChainInfoByChainId } from '../utils/chain';
1920

2021
const ChatView = (): JSX.Element => {
2122
const [selectedModel, setSelectedModel] = useState('llama2');
@@ -184,7 +185,16 @@ const ChatView = (): JSX.Element => {
184185
});
185186
console.log(response);
186187
} catch (error) {
187-
console.error('Failed to switch networks:', error);
188+
//if switch chain fails then add the chain
189+
try {
190+
const chainInfo = getChainInfoByChainId(selectedChain);
191+
const response = await provider.request({
192+
method: 'wallet_addEthereumChain',
193+
params: [chainInfo],
194+
});
195+
} catch (error) {
196+
console.error('Failed to switch networks:', error);
197+
}
188198
}
189199
};
190200

@@ -193,8 +203,9 @@ const ChatView = (): JSX.Element => {
193203
<Chat.Dropdown onChange={handleNetworkChange} value="">
194204
<option value="">Select a network</option>
195205
<option value="0x1">Ethereum</option>
196-
<option value="0x4268">Holesky</option>
206+
<option value="0xaa36a7">Sepolia</option>
197207
<option value="0xa4b1">Arbitrum</option>
208+
<option value="0x64">Gnosis</option>
198209
</Chat.Dropdown>
199210
<Chat.Main>
200211
{dialogueEntries.map((entry, index) => {

0 commit comments

Comments
 (0)