miaoyibo commited on
Commit
5d0be2a
·
1 Parent(s): 450e847
.gitignore CHANGED
@@ -5,4 +5,5 @@ __pycache__
5
  *.pyo
6
 
7
  .gradio
8
- local_path/
 
 
5
  *.pyo
6
 
7
  .gradio
8
+ local_path/
9
+ images/
app.py CHANGED
@@ -28,7 +28,7 @@ from kimi_dev.serve.templates import post_process,get_loc_prompt, clone_github_r
28
 
29
  TITLE = """<h1 align="left" style="min-width:200px; margin-top:0;">Chat with Kimi-Dev-72B🔥 </h1>"""
30
  DESCRIPTION_TOP = """<a href="https://github.com/MoonshotAI/Kimi-Dev" target="_blank">Kimi-Dev-72B</a> is a strong and open-source coding LLM for software engineering tasks."""
31
- USAGE_TOP = """Usage: 1. Input a Github url like "https://github.com/astropy/astropy" and submit it. \n2. Input your issue description and chat with Kimi-Dev-72B!"""
32
  ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
33
  DEPLOY_MODELS = dict()
34
  logger = configure_logger()
@@ -88,6 +88,7 @@ def highlight_thinking(msg: str) -> str:
88
  def predict(
89
  text,
90
  url,
 
91
  chatbot,
92
  history,
93
  top_p,
@@ -122,16 +123,20 @@ def predict(
122
 
123
  prompt = text
124
  repo_name = url.split("/")[-1]
 
 
125
 
126
  repo_path = './local_path/'+repo_name # Local clone path
127
 
128
- clone_github_repo(url, repo_path)
 
129
  structure = build_repo_structure(repo_path)
 
130
  string_struture = show_project_structure(structure)
 
131
 
132
  loc_prompt = get_loc_prompt(prompt,string_struture)
133
 
134
-
135
  messages = [
136
  {"role": "system", "content": "You are a helpful assistant."},
137
  {"role": "user", "content": loc_prompt}
@@ -247,6 +252,7 @@ def predict(
247
  def retry(
248
  text,
249
  url,
 
250
  chatbot,
251
  history,
252
  top_p,
@@ -270,6 +276,7 @@ def retry(
270
  yield from predict(
271
  text,
272
  url,
 
273
  chatbot,
274
  history,
275
  top_p,
@@ -284,6 +291,7 @@ def build_demo(args: argparse.Namespace) -> gr.Blocks:
284
  history = gr.State([])
285
  input_text = gr.State()
286
  upload_url = gr.State()
 
287
 
288
  with gr.Row():
289
  gr.HTML(TITLE)
@@ -313,11 +321,13 @@ def build_demo(args: argparse.Namespace) -> gr.Blocks:
313
  retry_btn = gr.Button("🔄 Regenerate")
314
  # del_last_btn = gr.Button("🗑️ Remove Last Turn")
315
  def respond(message):
316
- return f"Url submitted!"
317
  with gr.Column():
318
  url_box = gr.Textbox(label="Please input a Github url here",placeholder="Input your url", lines=1)
 
 
319
  url_submit_btn = gr.Button("Submit")
320
- output = gr.Textbox(label="Submitted url")
321
  url_submit_btn.click(fn=respond, inputs=upload_url, outputs=output)
322
 
323
  # Parameter Setting Tab for control the generation parameters
@@ -332,13 +342,14 @@ def build_demo(args: argparse.Namespace) -> gr.Blocks:
332
 
333
  gr.Examples(
334
  examples=get_examples(ROOT_DIR),
335
- inputs=[url_box, text_box],
336
  )
337
  # gr.Markdown()
338
 
339
  input_widgets = [
340
  input_text,
341
  upload_url,
 
342
  chatbot,
343
  history,
344
  top_p,
@@ -349,8 +360,8 @@ def build_demo(args: argparse.Namespace) -> gr.Blocks:
349
 
350
  transfer_input_args = dict(
351
  fn=transfer_input,
352
- inputs=[text_box, url_box],
353
- outputs=[input_text, upload_url, text_box, upload_url, submit_btn],
354
  show_progress=True,
355
  )
356
 
@@ -376,17 +387,17 @@ def main(args: argparse.Namespace):
376
  reload_javascript()
377
 
378
  favicon_path = os.path.join("kimi_dev/serve/assets/favicon.ico")
379
- demo.queue().launch(
380
- favicon_path=favicon_path,
381
- server_name=args.ip,
382
- server_port=args.port,
383
- )
384
  # demo.queue().launch(
385
  # favicon_path=favicon_path,
386
  # server_name=args.ip,
387
  # server_port=args.port,
388
- # share=True
389
  # )
 
 
 
 
 
 
390
 
391
  if __name__ == "__main__":
392
  args = parse_args()
 
28
 
29
  TITLE = """<h1 align="left" style="min-width:200px; margin-top:0;">Chat with Kimi-Dev-72B🔥 </h1>"""
30
  DESCRIPTION_TOP = """<a href="https://github.com/MoonshotAI/Kimi-Dev" target="_blank">Kimi-Dev-72B</a> is a strong and open-source coding LLM for software engineering tasks."""
31
+ USAGE_TOP = """Usage: 1. Input a Github url like "https://github.com/astropy/astropy" and a commit id and submit them. \n2. Input your issue description and chat with Kimi-Dev-72B!"""
32
  ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
33
  DEPLOY_MODELS = dict()
34
  logger = configure_logger()
 
88
  def predict(
89
  text,
90
  url,
91
+ commit_hash,
92
  chatbot,
93
  history,
94
  top_p,
 
123
 
124
  prompt = text
125
  repo_name = url.split("/")[-1]
126
+ print(url)
127
+ print(commit_hash)
128
 
129
  repo_path = './local_path/'+repo_name # Local clone path
130
 
131
+ clone_github_repo(url, repo_path, commit_hash)
132
+ print("repo cloned")
133
  structure = build_repo_structure(repo_path)
134
+ # print("type(structure)",type(structure))
135
  string_struture = show_project_structure(structure)
136
+ # print("string_struturem,",string_struture)
137
 
138
  loc_prompt = get_loc_prompt(prompt,string_struture)
139
 
 
140
  messages = [
141
  {"role": "system", "content": "You are a helpful assistant."},
142
  {"role": "user", "content": loc_prompt}
 
252
  def retry(
253
  text,
254
  url,
255
+ commit_hash,
256
  chatbot,
257
  history,
258
  top_p,
 
276
  yield from predict(
277
  text,
278
  url,
279
+ commit_hash,
280
  chatbot,
281
  history,
282
  top_p,
 
291
  history = gr.State([])
292
  input_text = gr.State()
293
  upload_url = gr.State()
294
+ commit_hash = gr.State()
295
 
296
  with gr.Row():
297
  gr.HTML(TITLE)
 
321
  retry_btn = gr.Button("🔄 Regenerate")
322
  # del_last_btn = gr.Button("🗑️ Remove Last Turn")
323
  def respond(message):
324
+ return f"Url and commit hash submitted!"
325
  with gr.Column():
326
  url_box = gr.Textbox(label="Please input a Github url here",placeholder="Input your url", lines=1)
327
+ commit_hash_box = gr.Textbox(label="Please input a commit hash here",placeholder="Input your commit hash", lines=1)
328
+ # url_submit_btn = gr.Button("Submit")
329
  url_submit_btn = gr.Button("Submit")
330
+ output = gr.Textbox(label="Submitted url and commit")
331
  url_submit_btn.click(fn=respond, inputs=upload_url, outputs=output)
332
 
333
  # Parameter Setting Tab for control the generation parameters
 
342
 
343
  gr.Examples(
344
  examples=get_examples(ROOT_DIR),
345
+ inputs=[url_box, text_box, commit_hash_box],
346
  )
347
  # gr.Markdown()
348
 
349
  input_widgets = [
350
  input_text,
351
  upload_url,
352
+ commit_hash,
353
  chatbot,
354
  history,
355
  top_p,
 
360
 
361
  transfer_input_args = dict(
362
  fn=transfer_input,
363
+ inputs=[text_box, url_box,commit_hash_box],
364
+ outputs=[input_text, upload_url, text_box, commit_hash, submit_btn],
365
  show_progress=True,
366
  )
367
 
 
387
  reload_javascript()
388
 
389
  favicon_path = os.path.join("kimi_dev/serve/assets/favicon.ico")
 
 
 
 
 
390
  # demo.queue().launch(
391
  # favicon_path=favicon_path,
392
  # server_name=args.ip,
393
  # server_port=args.port,
 
394
  # )
395
+ demo.queue().launch(
396
+ favicon_path=favicon_path,
397
+ server_name=args.ip,
398
+ server_port=args.port,
399
+ share=True
400
+ )
401
 
402
  if __name__ == "__main__":
403
  args = parse_args()
images/demo1.jpeg DELETED

Git LFS Details

  • SHA256: 8fc81bcaf75321eb871827fb0cad556cc5d3fe304864516c3dbace377fb82b64
  • Pointer size: 132 Bytes
  • Size of remote file: 5.31 MB
images/demo2.jpeg DELETED

Git LFS Details

  • SHA256: fddde8fc86f53fce4625f8defb54640c7fb885f1049eb0fb631d6234ac0e994b
  • Pointer size: 131 Bytes
  • Size of remote file: 450 kB
images/demo3.jpeg DELETED

Git LFS Details

  • SHA256: fcdb329b5deb032607f8b109f7340ae272adc779051da2785940fee029d367ab
  • Pointer size: 131 Bytes
  • Size of remote file: 776 kB
images/demo4.jpeg DELETED

Git LFS Details

  • SHA256: 2761a3226f9cd4d894e822c6dc98a4a418a89c4f82e1cc00a57d960fb66fc51f
  • Pointer size: 131 Bytes
  • Size of remote file: 223 kB
images/demo5.jpeg DELETED

Git LFS Details

  • SHA256: 927541679993f7bd2bcd344c04d648bed64ba1a97a4473a16eab1647fa190e8d
  • Pointer size: 131 Bytes
  • Size of remote file: 264 kB
images/demo6.jpeg DELETED

Git LFS Details

  • SHA256: 90ba53ccbc16bc711a11eb3a0e00c7f3c01dd1fcfdd3c29e8c19181811dbb419
  • Pointer size: 130 Bytes
  • Size of remote file: 80.1 kB
kimi_dev/serve/examples.py CHANGED
@@ -6,21 +6,24 @@ EXAMPLES_LIST = [
6
  [
7
  "https://github.com/astropy/astropy",
8
  "units.quantity_input decorator fails for constructors with type hinted return value -> None\n### Summary\r\nI am using the `units.quantity_input` decorator with typing hints for constructors, however when I add the correct return value for the constructor (`None`) then I get an exception, because `None` has no attribute `to`.\r\n\r\n### Reproducer\r\nThe issue can be reproduced with the following file:\r\n``` Python\r\nimport astropy.units as u\r\n\r\n\r\nclass PoC(object):\r\n\r\n @u.quantity_input\r\n def __init__(self, voltage: u.V) -> None:\r\n pass\r\n\r\n\r\nif __name__ == '__main__':\r\n poc = PoC(1.*u.V)\r\n```\r\nwhich results in the following error:\r\n```\r\n$ python3 poc.py\r\nTraceback (most recent call last):\r\n File \"poc.py\", line 12, in <module>\r\n poc = PoC(1.*u.V)\r\n File \"/usr/lib64/python3.6/site-packages/astropy/utils/decorators.py\", line 868, in __init__\r\n func = make_function_with_signature(func, name=name, **wrapped_args)\r\n File \"/usr/lib64/python3.6/site-packages/astropy/units/decorators.py\", line 225, in wrapper\r\n return return_.to(wrapped_signature.return_annotation)\r\nAttributeError: 'NoneType' object has no attribute 'to'\r\n```\r\n\r\nThis has been tested on Fedora 27 with python 3.6.3, astropy 2.0.2 and numpy 1.13.3 all from Fedora's repository.\r\n\r\n### Workaround\r\nThe issue can be circumvented by not adding the return type typing hint. Unfortunately, then a static type checker cannot infer that this function returns nothing.\r\n\r\n### Possible fix\r\nMaybe the decorator could explicitly check whether None is returned and then omit the unit check.\n\n\n",
 
9
  ],
10
  [
11
  "https://github.com/sympy/sympy",
12
  "evalf does not call _imp_ recursively\nExample from https://stackoverflow.com/questions/41818842/why-cant-i-evaluate-a-composition-of-implemented-functions-in-sympy-at-a-point:\r\n\r\n```\r\n>>> from sympy.utilities.lambdify import implemented_function\r\n>>> f = implemented_function('f', lambda x: x ** 2)\r\n>>> g = implemented_function('g', lambda x: 2 * x)\r\n>>> print(f( 2 ).evalf())\r\n4.00000000000000\r\n>>> print( g(2) .evalf())\r\n4.00000000000000\r\n>>> print(f(g(2)).evalf())\r\nf(g(2))\r\n```\r\n\r\nThe code for this is in `Function._eval_evalf`. It isn't calling evalf recursively on the return of `_imp_`. \n\n\n",
 
13
  ],
14
  [
15
  "https://github.com/matplotlib/matplotlib",
16
- "[ENH]: ContourSet.set_paths\n### Problem\n\nTo get contour labelling working with its special transforms, Cartopy has a [workaround](https://github.com/SciTools/cartopy/blob/2ed668c17b4e52421f15c5be3761719c75c5311a/lib/cartopy/mpl/contour.py#L89-L108) where it replaces all the paths on the `ContourSet` with transformed versions. This currently looks like\r\n\r\n```python\r\npaths = cs.get_paths()\r\npaths[:] = transformed_paths\r\n``` \r\n\r\nwhich doesn’t smell very good.\n\n### Proposed solution\n\nThe above would smell better as \r\n\r\n```python\r\ncs.set_paths(transformed_paths)\r\n``` \n\n\n"
 
17
  ]
18
  ]
19
 
20
 
21
  def get_examples(root_dir: str = None):
22
  examples = []
23
- for github_url, instance_id in EXAMPLES_LIST:
24
- examples.append([github_url, instance_id])
25
 
26
  return examples
 
6
  [
7
  "https://github.com/astropy/astropy",
8
  "units.quantity_input decorator fails for constructors with type hinted return value -> None\n### Summary\r\nI am using the `units.quantity_input` decorator with typing hints for constructors, however when I add the correct return value for the constructor (`None`) then I get an exception, because `None` has no attribute `to`.\r\n\r\n### Reproducer\r\nThe issue can be reproduced with the following file:\r\n``` Python\r\nimport astropy.units as u\r\n\r\n\r\nclass PoC(object):\r\n\r\n @u.quantity_input\r\n def __init__(self, voltage: u.V) -> None:\r\n pass\r\n\r\n\r\nif __name__ == '__main__':\r\n poc = PoC(1.*u.V)\r\n```\r\nwhich results in the following error:\r\n```\r\n$ python3 poc.py\r\nTraceback (most recent call last):\r\n File \"poc.py\", line 12, in <module>\r\n poc = PoC(1.*u.V)\r\n File \"/usr/lib64/python3.6/site-packages/astropy/utils/decorators.py\", line 868, in __init__\r\n func = make_function_with_signature(func, name=name, **wrapped_args)\r\n File \"/usr/lib64/python3.6/site-packages/astropy/units/decorators.py\", line 225, in wrapper\r\n return return_.to(wrapped_signature.return_annotation)\r\nAttributeError: 'NoneType' object has no attribute 'to'\r\n```\r\n\r\nThis has been tested on Fedora 27 with python 3.6.3, astropy 2.0.2 and numpy 1.13.3 all from Fedora's repository.\r\n\r\n### Workaround\r\nThe issue can be circumvented by not adding the return type typing hint. Unfortunately, then a static type checker cannot infer that this function returns nothing.\r\n\r\n### Possible fix\r\nMaybe the decorator could explicitly check whether None is returned and then omit the unit check.\n\n\n",
9
+ "732d89c2940156bdc0e200bb36dc38b5e424bcba",
10
  ],
11
  [
12
  "https://github.com/sympy/sympy",
13
  "evalf does not call _imp_ recursively\nExample from https://stackoverflow.com/questions/41818842/why-cant-i-evaluate-a-composition-of-implemented-functions-in-sympy-at-a-point:\r\n\r\n```\r\n>>> from sympy.utilities.lambdify import implemented_function\r\n>>> f = implemented_function('f', lambda x: x ** 2)\r\n>>> g = implemented_function('g', lambda x: 2 * x)\r\n>>> print(f( 2 ).evalf())\r\n4.00000000000000\r\n>>> print( g(2) .evalf())\r\n4.00000000000000\r\n>>> print(f(g(2)).evalf())\r\nf(g(2))\r\n```\r\n\r\nThe code for this is in `Function._eval_evalf`. It isn't calling evalf recursively on the return of `_imp_`. \n\n\n",
14
+ "d7c3045115693e887bcd03599b7ca4650ac5f2cb",
15
  ],
16
  [
17
  "https://github.com/matplotlib/matplotlib",
18
+ "[ENH]: ContourSet.set_paths\n### Problem\n\nTo get contour labelling working with its special transforms, Cartopy has a [workaround](https://github.com/SciTools/cartopy/blob/2ed668c17b4e52421f15c5be3761719c75c5311a/lib/cartopy/mpl/contour.py#L89-L108) where it replaces all the paths on the `ContourSet` with transformed versions. This currently looks like\r\n\r\n```python\r\npaths = cs.get_paths()\r\npaths[:] = transformed_paths\r\n``` \r\n\r\nwhich doesn’t smell very good.\n\n### Proposed solution\n\nThe above would smell better as \r\n\r\n```python\r\ncs.set_paths(transformed_paths)\r\n``` \n\n\n",
19
+ "2aee6ccd7c7e1f8d282c1e7579f4ee546b838542",
20
  ]
21
  ]
22
 
23
 
24
  def get_examples(root_dir: str = None):
25
  examples = []
26
+ for github_url, issue_description, commit_hash in EXAMPLES_LIST:
27
+ examples.append([github_url, issue_description, commit_hash])
28
 
29
  return examples
kimi_dev/serve/gradio_utils.py CHANGED
@@ -12,11 +12,11 @@ import gradio as gr
12
  IMAGE_TOKEN = "<image>"
13
 
14
 
15
- def transfer_input(input_text, input_images):
16
  """
17
  Transfer the input text and images to the input text and images.
18
  """
19
- return (input_text, input_images, gr.update(value=""), gr.update(value=None), gr.Button(visible=True))
20
 
21
 
22
  def delete_last_conversation(chatbot, history):
 
12
  IMAGE_TOKEN = "<image>"
13
 
14
 
15
+ def transfer_input(input_text, input_url, input_commit_hash):
16
  """
17
  Transfer the input text and images to the input text and images.
18
  """
19
+ return (input_text, input_url, gr.update(value=""), input_commit_hash, gr.Button(visible=True))
20
 
21
 
22
  def delete_last_conversation(chatbot, history):
kimi_dev/serve/templates.py CHANGED
@@ -26,14 +26,26 @@ def show_project_structure(structure, spacing=0) -> str:
26
 
27
  return pp_string
28
 
29
- def clone_github_repo(github_url, local_path):
30
- """Clone GitHub repository to local path"""
 
 
 
 
 
 
 
 
31
  try:
32
  subprocess.run(['git', 'clone', github_url, local_path], check=True)
33
  print(f"Successfully cloned repository to: {local_path}")
 
 
 
 
34
  except subprocess.CalledProcessError as e:
35
- print(f"Warning: Repository cloning may have failed: {e}")
36
-
37
  def parse_python_file(file_path, file_content=None):
38
  """Parse a Python file to extract class and function definitions with their line numbers.
39
  :param file_path: Path to the Python file.
 
26
 
27
  return pp_string
28
 
29
+ # def clone_github_repo(github_url, local_path):
30
+ # """Clone GitHub repository to local path"""
31
+ # try:
32
+ # subprocess.run(['git', 'clone', github_url, local_path], check=True)
33
+ # print(f"Successfully cloned repository to: {local_path}")
34
+ # except subprocess.CalledProcessError as e:
35
+ # print(f"Warning: Repository cloning may have failed: {e}")
36
+
37
+ def clone_github_repo(github_url, local_path, commit_hash=None):
38
+ """Clone GitHub repository to local path and optionally checkout specific commit"""
39
  try:
40
  subprocess.run(['git', 'clone', github_url, local_path], check=True)
41
  print(f"Successfully cloned repository to: {local_path}")
42
+ # If commit hash is provided, checkout to that specific commit
43
+ if commit_hash:
44
+ subprocess.run(['git', 'checkout', commit_hash], cwd=local_path, check=True)
45
+ print(f"Successfully checked out to commit: {commit_hash}")
46
  except subprocess.CalledProcessError as e:
47
+ print(f"Warning: Repository cloning or checkout may have failed: {e}")
48
+
49
  def parse_python_file(file_path, file_content=None):
50
  """Parse a Python file to extract class and function definitions with their line numbers.
51
  :param file_path: Path to the Python file.