andrijdavid commited on
Commit
ecc8bf9
1 Parent(s): d313c91

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +38 -1
README.md CHANGED
@@ -28,7 +28,44 @@ Solidity Llama 3 is a Large Language Model specifically designed for Solidity co
28
 
29
  ### Direct Use
30
 
31
- Solidity Llama 3 can be used for code completion and infilling tasks within Solidity code editors.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
  ### Out-of-Scope Use
34
 
 
28
 
29
  ### Direct Use
30
 
31
+ Solidity Llama 3 can be used for code completion and infilling tasks within Solidity code editors. It was trained for this task using the fill-in-the-middle (FIM) objective, where you provide a prefix and a suffix as context for the completion. The following tokens are used to separate the different parts of the input:
32
+ <|reserved_special_token_11|> precedes the context before the completion we want to run.
33
+ <|reserved_special_token_10|> precedes the suffix. You must put this token exactly where the cursor would be positioned in an editor, as this is the location that will be completed by the model.
34
+ <|reserved_special_token_12|> is the prompt that invites the model to run the generation.
35
+
36
+
37
+ ```python
38
+ FIM_SUFFIX = "<|reserved_special_token_10|>"
39
+ FIM_PREFIX = "<|reserved_special_token_11|>"
40
+ FIM_MIDDLE = "<|reserved_special_token_12|>"
41
+ tokenizer = AutoTokenizer.from_pretrained("andrijdavid/Solidity-Llama3-8b")
42
+ model = AutoModelForCausalLM.from_pretrained("andrijdavid/Solidity-Llama3-8b")
43
+
44
+ prompt = f'''{FIM_PREFIX}contract SendEther {{
45
+ function sendViaTransfer(address payable _to) public payable {{
46
+ // This function is no longer recommended for sending Ether.
47
+ _to.transfer(msg.value);
48
+ }}
49
+
50
+ function sendViaSend(address payable _to) public payable {{
51
+ // Send returns a boolean value indicating success or failure.
52
+ // This function is not recommended for sending Ether.
53
+ {FIM_SUFFIX}
54
+ }}
55
+
56
+ function sendViaCall(address payable _to) public payable {{
57
+ // Call returns a boolean value indicating success or failure.
58
+ // This is the current recommended method to use.
59
+ (bool sent, bytes memory data) = _to.call{{value: msg.value}}("");
60
+ require(sent, "Failed to send Ether");
61
+ }}{FIM_MIDDLE}
62
+ '''
63
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
64
+ prompt_len = inputs["input_ids"].shape[-1]
65
+ outputs = model.generate(**inputs, max_new_tokens=1024)
66
+ print(tokenizer.decode(outputs[0][prompt_len:]))
67
+
68
+ ```
69
 
70
  ### Out-of-Scope Use
71