Use XRay data for code generation
What does this MR do and why?
Address #434028 (closed)
Use XRay data for code generation
Expand code generation prompt with XRay data based on programming language
Screenshots or screen recordings
Without XRay data
curl -X POST -H "Content-Type: Application/json" -H "Authorization: Bearer glpat-xxxxxxx" http://gdk.test:3000/api/v4/code_suggestions/completions --data '{ "current_file": {
"file_name": "test.py",
"content_above_cursor": "# generate function that loads csv",
"content_below_cursor": ""
},
"project_path": "not/existent",
"intent": "generation"
}'
{"id":"id","model":{"engine":"anthropic","name":"claude-2.0","lang":"python"},"experiments":[],"object":"text_completion","created":1702069469,"choices":[{"text":"\nimport csv\n\ndef load_csv(filename):\n data = []\n with open(filename, 'r') as f:\n reader = csv.reader(f)\n for row in reader:\n data.append(row)\n return data\n","index":0,"finish_reason":"length"}]}%
With XRay Data
curl -X POST -H "Content-Type: Application/json" -H "Authorization: Bearer glpat-xxxxxxx" http://gdk.test:3000/api/v4/code_suggestions/completions --data '{ "current_file": {
"file_name": "test.py",
"content_above_cursor": "# generate function that loads csv",
"content_below_cursor": ""
},
"project_path": "gitlab-org/gitlab-test",
"intent": "generation"
}'
{"id":"id","model":{"engine":"anthropic","name":"claude-2.0","lang":"python"},"experiments":[],"object":"text_completion","created":1702069363,"choices":[{"text":"\nimport pandas as pd\n\ndef load_csv(filename):\n return pd.read_csv(filename)\n","index":0,"finish_reason":"length"}]}%
How to set up and validate locally
Generate XRay data
project = Project.find_by_full_path 'gitlab-org/gitlab-test'
payload = {
"scannerVersion" => "0.0.1",
"fileName" => "pyproject.toml",
"checksum" => "53b5964d32d30fc60089fb54cd73538003a487afdd5d6a3b549ae162ce4819cd",
"libs" =>
[
{
"name" => "python ~3.9",
"description" => "Python is a popular general-purpose programming language used for web development."
},
{
"name" => "pandas 2.1.4",
"description" => "pandas is a fast, powerful, flexible and easy to use open source data analysis and manipulation tool, built on top of the Python programming language."
}
]
xray = FactoryBot.create(:xray_report, project: project, lang: 'python', payload: payload)
curl -X POST -H "Content-Type: Application/json" -H "Authorization: Bearer glpat-xxxxxxx" http://gdk.test:3000/api/v4/code_suggestions/completions --data '{ "current_file": {
"file_name": "test.py",
"content_above_cursor": "# generate function that loads csv",
"content_below_cursor": ""
},
"project_path": "gitlab-org/gitlab-test",
"intent": "generation"
}'
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by Mikołaj Wawrzyniak