File size: 2,914 Bytes
df13dd1
4889e00
65fb958
 
4889e00
 
 
 
 
 
 
 
 
 
 
 
 
65fb958
abd7a41
 
 
e55a1c1
4889e00
2c005b1
4889e00
2c005b1
43d2fe2
4889e00
e55a1c1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from transformers import pipeline
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
import streamlit as st

tokenizer = AutoTokenizer.from_pretrained("microsoft/GODEL-v1_1-large-seq2seq")
model = AutoModelForSeq2SeqLM.from_pretrained("microsoft/GODEL-v1_1-large-seq2seq")


def generate(instruction, knowledge, dialog):
    if knowledge != '':
        knowledge = '[KNOWLEDGE] ' + knowledge
    dialog = ' EOS '.join(dialog)
    query = f"{instruction} [CONTEXT] {dialog} {knowledge}"
    input_ids = tokenizer(f"{query}", return_tensors="pt").input_ids
    outputs = model.generate(input_ids, max_length=128, min_length=8, top_p=0.9, do_sample=True)
    output = tokenizer.decode(outputs[0], skip_special_tokens=True)
    return output

text_init = st.text_area('Enter init description')
text_deploy = st.text_area('Enter deploy description')
text_invariant = st.text_area('Enter invariant description')
if text_init and text_deploy and text_invariant:
    # Instruction for a chitchat task
    instruction = f'Using the descriptions, write the init code, deploy code and invariant code'
    # Leave the knowldge empty
    knowledge = 'EXAMPLE:{init description: [“Create a new address called “user”. Give the “user” “AMOUNT” of LP tokens. Using the “user” as the sender approve the “StaxLPStaking” contract to use his LP tokens and stake all the LP tokens into the “StaxLPStaking” contract.“],\n deploy description: [“Create a new address called “owner”. Using the “owner” as the sender deploy the “StaxLP” contract and the “StaxLPStaking” contract.“],\n invariant description: [“Using the “user” address as sender withdraw all the LP tokens from the “StaxLPStaking” contract and check the balance of the LP tokens of the “user” is not less than “AMOUNT”.“],\n init code: [{\naddress public user;\nuint256 public constant AMOUNT = 10e18;\nfunction init() public {\n    user = makeAddr(“USER”);\n    deal(address(lp), user, AMOUNT);\n    vm.startPrank(user);\n    lp.approve(address(lpStaking), lp.balanceOf(user));\n    lpStaking.stakeAll();\n    vm.stopPrank();\n}\n    }],\n deploy code: [{\nStaxLP public lp;\nStaxLPStaking public lpStaking;\naddress public owner;\nfunction deploy() public {\n    owner = makeAddr(“OWNER”);\n    vm.startPrank(owner);\n    lp = new StaxLP(“Stax Frax/Temple LP Token”, “xFraxTempleLP”);\n    lpStaking = new StaxLPStaking(address(lp), owner);\n    vm.stopPrank();\n}\n    }],\n invariant code: [{\nfunction invariant() public {\n    vm.prank(user);\n    lpStaking.withdrawAll(false);\n    assert(lp.balanceOf(user) >= AMOUNT);\n}\n    }],\n}\n]'
    dialog = [f'\{init description: [“{text_init}“],\n deploy description: [“{text_deploy}“],\n invariant description: [“{text_invariant}“],\n\}']
    response = generate(instruction, knowledge, dialog)
    print(response)