Arturo Jiménez de los Galanes Reguillos commited on
Commit
4952bf3
1 Parent(s): 005c893

Do not stream response, by now

Browse files
Files changed (1) hide show
  1. app.py +11 -1
app.py CHANGED
@@ -5,7 +5,7 @@ from threading import Thread
5
  import torch
6
 
7
  MODEL = "m-a-p/OpenCodeInterpreter-DS-33B"
8
- CHAT_TEMPLATE = "{% for message in messages %}\n{{'<|im_start|>' + message['role'] + '\n' + message['content'] + '<|im_end|>' + '\n'}}\n{% endfor %}\n{% if add_generation_prompt %}\n{{ '<|im_start|>assistant\n' }}\n{% endif %}"
9
 
10
  system_message = "You are a computer programmer that can translate python code to C++ in order to improve performance"
11
 
@@ -34,6 +34,15 @@ def translate(python):
34
  inputs = tokenizer.apply_chat_template(
35
  messages_for(python),
36
  return_tensors="pt").to(model.device)
 
 
 
 
 
 
 
 
 
37
  generation_kwargs = dict(
38
  inputs,
39
  streamer=streamer,
@@ -48,6 +57,7 @@ def translate(python):
48
  for chunk in streamer:
49
  cplusplus += chunk
50
  yield cplusplus
 
51
 
52
  demo = gr.Interface(fn=translate, inputs="code", outputs="markdown")
53
  demo.launch()
 
5
  import torch
6
 
7
  MODEL = "m-a-p/OpenCodeInterpreter-DS-33B"
8
+ CHAT_TEMPLATE = "{%- set found_item = false -%}\n{%- for message in messages -%}\n {%- if message['role'] == 'system' -%}\n {%- set found_item = true -%}\n {%- endif -%}\n{%- endfor -%}\n{%- if not found_item -%}\n{{'You are an AI programming assistant, utilizing the Deepseek Coder model, developed by Deepseek Company, and you only answer questions related to computer science. For politically sensitive questions, security and privacy issues, and other non-computer science questions, you will refuse to answer.\\n'}}\n{%- endif %}\n{%- for message in messages %}\n {%- if message['role'] == 'system' %}\n{{ message['content'] }}\n {%- else %}\n {%- if message['role'] == 'user' %}\n{{'### Instruction:\\n' + message['content'] + '\\n'}}\n {%- else %}\n{{'### Response:\\n' + message['content'] + '\\n<|EOT|>\\n'}}\n {%- endif %}\n {%- endif %}\n{%- endfor %}\n{{'### Response:\\n'}}\n"
9
 
10
  system_message = "You are a computer programmer that can translate python code to C++ in order to improve performance"
11
 
 
34
  inputs = tokenizer.apply_chat_template(
35
  messages_for(python),
36
  return_tensors="pt").to(model.device)
37
+ outputs = model.generate(
38
+ inputs,
39
+ max_new_tokens=1024,
40
+ do_sample=False,
41
+ pad_token_id=tokenizer.eos_token_id,
42
+ eos_token_id=tokenizer.eos_token_id,
43
+ )
44
+ return tokenizer.decode(outputs[0][len(inputs[0]):], skip_special_tokens=True)
45
+ '''
46
  generation_kwargs = dict(
47
  inputs,
48
  streamer=streamer,
 
57
  for chunk in streamer:
58
  cplusplus += chunk
59
  yield cplusplus
60
+ '''
61
 
62
  demo = gr.Interface(fn=translate, inputs="code", outputs="markdown")
63
  demo.launch()