Newline missing from beginning code suggestion for generation
Problems to solve
When generating code from code suggestions, the suggestion appears on the same line
This can be reproduced with the following input:
{
"prompt_version": 2,
"project_path": "awesome_project",
"project_id": 46678122,
"current_file": {
"file_name": "hello.py",
"content_above_cursor": "def foo():\n # generate a function for the square root",
"content_below_cursor": ""
}
}
This is categorised as Code Generations and the prompt sent to Anthoric claude-2
See the full prompt
Human: You are a coding autocomplete agent. We want to generate new Python code inside the
file 'hello.py' based on instructions from the user.
The existing code is provided in <existing_code></existing_code> tags.
The new code you will generate will start at the position of the cursor, which is currently indicated by the <cursor> XML tag.
In your process, first, review the existing code to understand its logic and format. Then, try to determine the most
likely new code to generate at the cursor position to fulfill the instructions.
When generating the new code, please ensure the following:
1. It is valid Python code.
2. It matches the existing code's variable, parameter and function names.
3. It does not repeat any existing code. Do not repeat code that comes before or after the cursor tags. This includes cases where the cursor is in the middle of a word.
4. If the cursor is in the middle of a word, it finishes the word instead of repeating code before the cursor tag.
Return new code enclosed in <new_code></new_code> tags. We will then insert this at the <cursor> position.
If you are not able to write code based on the given instructions return an empty result like <new_code></new_code>.
Here are a few examples of successfully generated code by other autocomplete agents:
<examples>
<example>
<existing_code>
class Project:
def __init__(self, name, public):
self.name = name
self.visibility = 'PUBLIC' if public
# is this project public?
<cursor>
# print name of this project
</existing_code>
<new_code> def is_public(self):
self.visibility == 'PUBLIC'</new_code>
</example>
<example>
<existing_code>
# get the current user's name from the session data
def get_user(session):
<cursor>
# is the current user an admin
</existing_code>
<new_code>username = None
if 'username' in session:
username = session['username']
return username</new_code>
</example>
</examples>
<existing_code>
def foo:
# generate a function for the square root<cursor>
</existing_code>
Here are instructions provided in <instruction></instruction> tags.
<instruction>
generate a function for the square root
</instruction>
Assistant: <new_code>
Output from model (before post-processing in AI Gateway)
{
"id": "id",
"model": {
"engine": "anthropic",
"name": "claude-2",
"lang": "python"
},
"experiments": [],
"object": "text_completion",
"created": 1700125283,
"choices": [
{
"text": "import math\n\ndef square_root(num):\n return math.sqrt(num)\n",
"index": 0,
"finish_reason": "length"
}
]
}
Edited by Tan Le