blah = ({
prefix:
'# Path: codeviz\\app.py\n# Compare this snippet from codeviz\\predictions.py:\n# import json\n# import sys\n# import time\n# from manifest import Manifest\n# \n# sys.path.append(__file__ + "/..")\n# from common import module_codes, module_deps, module_categories, data_dir, cur_dir\n# \n# gold_annots = json.loads(open(data_dir / "gold_annotations.js").read().replace("let gold_annotations = ", ""))\n# \n# M = Manifest(\n# client_name = "openai",\n# client_connection = open(cur_dir / ".openai-api-key").read().strip(),\n# cache_name = "sqlite",\n# cache_connection = "codeviz_openai_cache.db",\n# engine = "code-davinci-002",\n# )\n# \n# def predict_with_retries(*args, **kwargs):\n# for _ in range(5):\n# try:\n# return M.run(*args, **kwargs)\n# except Exception as e:\n# if "too many requests" in str(e).lower():\n# print("Too many requests, waiting 30 seconds...")\n# time.sleep(30)\n# continue\n# else:\n# raise e\n# raise Exception("Too many retries")\n# \n# def collect_module_prediction_context(module_id):\n# module_exports = module_deps[module_id]["exports"]\n# module_exports = [m for m in module_exports if m != "default" and "complex-export" not in m]\n# if len(module_exports) == 0:\n# module_exports = ""\n# else:\n# module_exports = "It exports the following symbols: " + ", ".join(module_exports)\n# \n# # get module snippet\n# module_code_snippet = module_codes[module_id]\n# # snip to first 50 lines:\n# module_code_snippet = module_code_snippet.split("\\n")\n# if len(module_code_snippet) > 50:\n# module_code_snippet = "\\n".join(module_code_snippet[:50]) + "\\n..."\n# else:\n# module_code_snippet = "\\n".join(module_code_snippet)\n# \n# return {"exports": module_exports, "snippet": module_code_snippet}\n# \n# #### Name prediction ####\n# \n# def _get_prompt_for_module_name_prediction(module_id):\n# context = collect_module_prediction_context(module_id)\n# module_exports = context["exports"]\n# module_code_snippet = context["snippet"]\n# \n# prompt = f"""\\\n# Consider the code snippet of an unmodule named.\n# \nimport json\nfrom flask import Flask, render_template, request, send_from_directory\nfrom common import *\nfrom predictions import predict_snippet_description, predict_module_name\n\napp = Flask(__name__)\n\n@app.route(\'/\')\ndef home():\n return render_template(\'code-viz.html\')\n\n@app.route(\'/data/<path:filename>\')\ndef get_data_files(filename):\n return send_from_directory(data_dir, filename)\n\n@app.route(\'/api/describe_snippet\', methods=[\'POST\'])\ndef describe_snippet():\n module_id = request.json[\'module_id\']\n module_name = request.json[\'module_name\']\n snippet = request.json[\'snippet\']\n description = predict_snippet_description(\n module_id,\n module_name,\n snippet,\n )\n return json.dumps({\'description\': description})\n\n# predict name of a module given its id\n@app.route(\'/api/predict_module_name\', methods=[\'POST\'])\ndef suggest_module_name():\n module_id = request.json[\'module_id\']\n module_name = predict_module_name(module_id)\n',
suffix: "if __name__ == '__main__':\r\n app.run(debug=True)",
isFimEnabled: true,
promptElementRanges: [
{ kind: "PathMarker", start: 0, end: 23 },
{ kind: "SimilarFile", start: 23, end: 2219 },
{ kind: "BeforeCursor", start: 2219, end: 3142 }
]
})