cxumol commited on
Commit
1b4d3b3
1 Parent(s): 9087846

enrich debug mode

Browse files
Files changed (3) hide show
  1. app.py +2 -2
  2. taskAI.py +18 -7
  3. taskNonAI.py +2 -1
app.py CHANGED
@@ -196,8 +196,7 @@ with gr.Blocks(
196
  cover_letter_text = gr.Textbox(label="Cover Letter")
197
  cover_letter_pdf = gr.File(
198
  label="Cover Letter PDF",
199
- file_count="single",
200
- file_types=[".pdf"],
201
  type="filepath",
202
  )
203
  infer_btn = gr.Button("Go!", variant="primary")
@@ -246,6 +245,7 @@ with gr.Blocks(
246
  jd_info,
247
  cv_text,
248
  cover_letter_text,
 
249
  ],
250
  outputs=[debug_jobapp, cover_letter_pdf],
251
  )
 
196
  cover_letter_text = gr.Textbox(label="Cover Letter")
197
  cover_letter_pdf = gr.File(
198
  label="Cover Letter PDF",
199
+ file_count="multiple",
 
200
  type="filepath",
201
  )
202
  infer_btn = gr.Button("Go!", variant="primary")
 
245
  jd_info,
246
  cv_text,
247
  cover_letter_text,
248
+ is_debug,
249
  ],
250
  outputs=[debug_jobapp, cover_letter_pdf],
251
  )
taskAI.py CHANGED
@@ -65,7 +65,7 @@ Before officially write the letter, think step by step. First, list what makes a
65
 
66
  ## tasks
67
  class TaskAI(OpenAILike):
68
- def __init__(self, api: dict[str, str], **kwargs):
69
  log = logger.info
70
 
71
  def guess_window_size(model=api["model"]):
@@ -83,6 +83,7 @@ class TaskAI(OpenAILike):
83
  return window_size
84
 
85
  checkAPI(api_base, api_key)
 
86
 
87
  super().__init__(
88
  api_base=api["base"],
@@ -93,18 +94,28 @@ class TaskAI(OpenAILike):
93
  **kwargs,
94
  )
95
 
 
 
 
 
 
 
96
  def jd_preprocess(self, input: str):
97
- return self.stream_chat(
98
- EXTRACT_INFO.format_messages(
99
- to_extract="the job description part`", input=input
100
- )
101
  )
102
 
 
 
103
  def cv_preprocess(self, input: str):
104
- return self.stream_chat(SIMPLIFY_MD.format_messages(input=input))
 
 
105
 
106
  def compose_letter_CoT(self, resume: str, jd: str):
107
- return self.stream_chat(LETTER_COMPOSE.format_messages(resume=resume, jd=jd))
 
 
108
 
109
  def get_jobapp_meta(self, JD, CV):
110
  meta_JD = self.chat(
 
65
 
66
  ## tasks
67
  class TaskAI(OpenAILike):
68
+ def __init__(self, api: dict[str, str], is_debug: bool, **kwargs):
69
  log = logger.info
70
 
71
  def guess_window_size(model=api["model"]):
 
83
  return window_size
84
 
85
  checkAPI(api_base, api_key)
86
+ self.is_debug = is_debug
87
 
88
  super().__init__(
89
  api_base=api["base"],
 
94
  **kwargs,
95
  )
96
 
97
+ def _debug_print_msg(self, msg):
98
+ if not self.is_debug:
99
+ return
100
+ for m in msg:
101
+ print(m.content)
102
+
103
  def jd_preprocess(self, input: str):
104
+ msg = EXTRACT_INFO.format_messages(
105
+ to_extract="the job description part", input=input
 
 
106
  )
107
 
108
+ return self.stream_chat(msg)
109
+
110
  def cv_preprocess(self, input: str):
111
+ msg = SIMPLIFY_MD.format_messages(input=input)
112
+ # if self.is_debug: logger.info(msg)
113
+ return self.stream_chat(msg)
114
 
115
  def compose_letter_CoT(self, resume: str, jd: str):
116
+ msg = LETTER_COMPOSE.format_messages(resume=resume, jd=jd)
117
+ _debug_print_msg(msg)
118
+ return self.stream_chat(msg)
119
 
120
  def get_jobapp_meta(self, JD, CV):
121
  meta_JD = self.chat(
taskNonAI.py CHANGED
@@ -56,7 +56,8 @@ def _typst_escape(s) -> str:
56
  def compile_pdf(
57
  context: dict, tmpl_path: str, output_path="/tmp/cover_letter.pdf", is_debug=False
58
  ) -> list[str]:
59
- letter_src_filepath = "typst/letter.typ"
 
60
  with open(tmpl_path, "r", encoding="utf8") as f:
61
  tmpl = Template(f.read())
62
  context = {k: _typst_escape(v) for k, v in context.items()}
 
56
  def compile_pdf(
57
  context: dict, tmpl_path: str, output_path="/tmp/cover_letter.pdf", is_debug=False
58
  ) -> list[str]:
59
+ # letter_src_filepath = "typst/letter.typ"
60
+ letter_src_filepath = "typst/" + output_path.split("/")[-1][: -len(".pdf")] + ".typ"
61
  with open(tmpl_path, "r", encoding="utf8") as f:
62
  tmpl = Template(f.read())
63
  context = {k: _typst_escape(v) for k, v in context.items()}