Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
CedarMist committed Oct 19, 2024
1 parent 015d7cf commit 335b3d8
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 27 deletions.
4 changes: 2 additions & 2 deletions packages/frontend/.env.local
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
VITE_NETWORK=134
VITE_WEB3_GATEWAY=https://bellecour.iex.ec
VITE_CONTRACT_TASKRESULT_TX=0xa2572210bfcd11d2bfecb3f4a08fff0303a139a9b7077e0b33421f8cb2cc985a
VITE_CONTRACT_TASKRESULT=0x77B78c87FC2EeBE8D76C4D37d5091064B4a923F5
VITE_CONTRACT_TASKRESULT_TX=0xa530f91d9a5a3137459652f99841ba86271b464db384a44951930fc132fd6d9a
VITE_CONTRACT_TASKRESULT=0x1e35359854115f259d678142429F6659c49efBa1
VITE_CONTRACT_LLMQUESTION_TX=0xed0ccc8dbd57f5ac46c0489d76ebf919e8eb52213a878b64a1c251033aa2e610
VITE_CONTRACT_LLMQUESTION=0x3790add8f936F5066515fA60B63F1069bB58ED10
1 change: 0 additions & 1 deletion packages/frontend/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { RouterView } from 'vue-router';
<nav>
<RouterLink to="/">Home</RouterLink>
<RouterLink to="/questions">Questions</RouterLink>
<RouterLink to="/upload">Upload</RouterLink>
</nav>

<RouterView />
Expand Down
33 changes: 26 additions & 7 deletions packages/frontend/src/components/HelloWorld.vue
Original file line number Diff line number Diff line change
@@ -1,24 +1,43 @@
<script setup lang="ts">
import { ref, toValue } from 'vue'
import { ethersBrowserProvider } from '../wallet';
import { useIExec } from '../iexec';
import { ProtectedData } from '@iexec/dataprotector';
import { getTaskInfo } from '../taskresult';
import { getQuestion } from '../qlist';
const { dataProtectorCore, dataProtectorWallet } = useIExec();
const results = ref<ProtectedData[]>([]);
const isLoading = ref(false);
const extraData = ref<any[]>([]);
async function refreshData() {
isLoading.value = true;
try {
const browserOwner = (await toValue(ethersBrowserProvider)!.getSigner()).address;
const dpw = toValue(dataProtectorWallet)!
const browserOwner = dpw.address;
//const dpw = toValue(dataProtectorWallet)!
const dpc = toValue(dataProtectorCore)!;
const extra = [];
const blah = results.value = await dpc.getProtectedData({
owner: browserOwner
owner: browserOwner,
pageSize: 100,
requiredSchema: {
bulgariaIsCool: "bool"
}
});
for( const b of blah ) {
const i = await getTaskInfo(dpw, b.address)
const qid = i[2];
const taskid = i[0];
//const result = i[1];
const q = await getQuestion(dpw, qid);
const qtitle = q[1];
console.log(i, q);
extra.push({qid,taskid,qtitle});
}
extraData.value = extra as any;
console.log(blah);
} finally {
isLoading.value = false;
Expand All @@ -36,11 +55,10 @@ refreshData();
owner: {{ dataProtectorWallet?.address }}

<div class="card">
<div class="item" v-for="item in results">
<div class="item" v-for="(item, index) in results">
<h3>{{ toValue(extraData)[index].qtitle }}</h3>
Address: {{ item.address }}<br />
Schema: {{ item.schema }}<br />
Timestamp: {{ item.creationTimestamp }}<br />
Owner: {{ item.owner }}<br />
</div>

<button @click.prevent="refreshData">Refresh</button>
Expand All @@ -50,6 +68,7 @@ refreshData();
<style scoped>
div.item {
border: 1px solid #333;
margin-bottom: 5px;
margin-bottom: 20px;
padding-bottom: 20px;;
}
</style>
26 changes: 15 additions & 11 deletions packages/frontend/src/components/ProtectShit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async function loadQuestion() {
throw new Error('No qid!');
}
const x = questionnaire.value = await getQuestion(dpw, qid);
for( const _ in x.questions ) {
for( const _ in x[2] ) {
qv.push('');
}
console.log('Question loaded', x);
Expand All @@ -65,7 +65,7 @@ const isFormError = ref(false);
const formErrorFields = ref<string[]>([]);
/// Checks if the questions have been answered
const areAnswersValid = computed(()=> {
function areAnswersValid () {
let isValid = true;
formErrorFields.value = [];
const errors = [];
Expand All @@ -74,7 +74,7 @@ const areAnswersValid = computed(()=> {
return {isValid:false,errors:[]};
}
for( const i in x[2] ) {
const q = x.questions[i];
const q = x[2][i];
const v = qv[i as unknown as number];
const qt = q[1];
if( qt === 'prompt' || qt === 'info' ) {
Expand All @@ -86,7 +86,7 @@ const areAnswersValid = computed(()=> {
}
}
return {isValid, errors};
});
};
const isButtonDisabled = computed(() => {
const hasDataProtectorCore = toValue(dataProtectorCore) !== undefined;
Expand All @@ -96,7 +96,7 @@ const isButtonDisabled = computed(() => {
});
function validateQuestions() {
const {isValid,errors} = toValue(areAnswersValid);
const {isValid,errors} = areAnswersValid();
formErrorFields.value = errors;
isFormError.value = isValid === false;
console.log('isVaid', isValid);
Expand Down Expand Up @@ -155,9 +155,12 @@ async function doProtectData () {
isSuccess.value = false;
//const browserWalletAddress = (await ebp.getSigner()).address;
try {
const fakeResultPromise = evaluatePrompt(llm_input)
const result = dpcResult.value = await dpc.protectData({
data: {
email: llm_input
email: llm_input,
bulgariaIsCool: true
},
onStatusUpdate: ({title, isDone}) => {
console.log('Data Protector', title, isDone);
Expand Down Expand Up @@ -198,7 +201,10 @@ async function doProtectData () {
});
console.log(protectedResult);
const receipt = await associateTaskResults(dpw, result.address, protectedResult.taskId, '');
const fakeResult = await fakeResultPromise;
console.log('fakeResult s', fakeResult);
const receipt = await associateTaskResults(dpw, result.address, protectedResult.taskId, fakeResult, qid);
/*
const contract = getTaskRunnerContract(dpw); // new Contract(taskResultContractAddr, taskResultABI, dpw);
const tx = await contract.associate(result.address, protectedResult.taskId);
Expand All @@ -213,9 +219,6 @@ async function doProtectData () {
console.log('X is', x);
}
const fakeResult = await evaluatePrompt(llm_input)
console.log('fakeResult s', fakeResult);
// Finally transfer it to the browser owner
/*
dpcStatusText.value = 'Tansferring Ownership';
Expand Down Expand Up @@ -255,8 +258,9 @@ async function doProtectData () {
</ul>
</div>

<br />
<button type="button" :disabled="toValue(isButtonDisabled)" @click="doProtectData()">
Do Everything
Submit Answers
</button>
<br />

Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/components/QuestionField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const title = q[0];
const qtype = q[1];
const options = q[2] !== undefined ? (q[2][0] === '[' ? JSON.parse(q[2] as string) : q[2]) : '';
console.log('title', title, 'qtype', qtype, 'options', typeof options, options);
//console.log('title', title, 'qtype', qtype, 'options', typeof options, options);
const range:number[] = [];
if( qtype == 'range' && options ) {
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function evaluatePrompt(prompt :string) {
}

let result = await wllama.createCompletion(prompt, {
nPredict: 300
nPredict: 10
});

return result;
Expand Down
24 changes: 22 additions & 2 deletions packages/frontend/src/taskresult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import { Contract, ContractRunner, ContractTransactionResponse } from "ethers";
const taskResultContractAddr = import.meta.env.VITE_CONTRACT_TASKRESULT;

const taskResultABI = [
{
"inputs": [],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [
{
Expand All @@ -19,6 +24,11 @@ const taskResultABI = [
"internalType": "string",
"name": "data",
"type": "string"
},
{
"internalType": "uint256",
"name": "questionId",
"type": "uint256"
}
],
"name": "associate",
Expand All @@ -45,6 +55,11 @@ const taskResultABI = [
"internalType": "string",
"name": "data",
"type": "string"
},
{
"internalType": "uint256",
"name": "questionId",
"type": "uint256"
}
],
"stateMutability": "view",
Expand All @@ -69,14 +84,19 @@ export function getTaskRunnerContract (runner:ContractRunner) {
return new Contract(taskResultContractAddr, taskResultABI, runner);
}

export async function getTaskInfo(runner:ContractRunner, datasetAddress:string) {
const contract = getTaskRunnerContract(runner);
return contract.datasetTasks(datasetAddress);
}
export async function associateTaskResults (
runner:ContractRunner,
owner:string,
taskId:string,
result:string
result:string,
questionId:number
)
{
const contract = getTaskRunnerContract(runner);
const tx = await contract.associate(owner, taskId, result) as ContractTransactionResponse;
const tx = await contract.associate(owner, taskId, result, questionId) as ContractTransactionResponse;
return await tx.wait();
}
6 changes: 4 additions & 2 deletions packages/nft/contracts/TaskResult.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ contract TaskResult {
struct Response {
bytes32 taskId;
string data;
uint questionId;
}

mapping(address datasetAddress => Response response) public datasetTasks;
Expand All @@ -28,11 +29,12 @@ contract TaskResult {
registry = IERC721(0x799DAa22654128d0C64d5b79eac9283008158730);
}

function associate(address dataset, bytes32 taskId, string calldata data) external {
function associate(address dataset, bytes32 taskId, string calldata data, uint questionId) external {
require( registry.ownerOf(uint256(uint160(dataset))) == msg.sender, "not owner" );
datasetTasks[dataset] = Response({
taskId: taskId,
data: data
data: data,
questionId: questionId
});
}
}

0 comments on commit 335b3d8

Please sign in to comment.