Ahmad-Moiz commited on
Commit
3752fed
·
1 Parent(s): e74d51c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -4
app.py CHANGED
@@ -1,6 +1,6 @@
1
  import streamlit as st
2
  from pathlib import Path
3
- from typing import List, Optional
4
  from llama_index.llms.base import LLM
5
  from llama_index.llms import OpenAI
6
  from llama_index.readers import PDFReader
@@ -20,10 +20,28 @@ Your job is to decide if the candidate passes the resume screen given the job de
20
  {criteria_str}
21
  """
22
 
23
- # Define the BaseModel and other classes you provided
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
 
26
- # Function to format criteria list into a string
27
  def _format_criteria_str(criteria: List[str]) -> str:
28
  criteria_str = ""
29
  for criterion in criteria:
@@ -32,7 +50,35 @@ def _format_criteria_str(criteria: List[str]) -> str:
32
 
33
 
34
  class ResumeScreenerPack(BaseLlamaPack):
35
- # ... (your existing code for ResumeScreenerPack)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
 
38
  def main():
 
1
  import streamlit as st
2
  from pathlib import Path
3
+ from typing import Any, Dict, List, Optional
4
  from llama_index.llms.base import LLM
5
  from llama_index.llms import OpenAI
6
  from llama_index.readers import PDFReader
 
20
  {criteria_str}
21
  """
22
 
23
+
24
+ class CriteriaDecision(BaseModel):
25
+ """The decision made based on a single criterion"""
26
+
27
+ decision: bool = Field(description="The decision made based on the criterion")
28
+ reasoning: str = Field(description="The reasoning behind the decision")
29
+
30
+
31
+ class ResumeScreenerDecision(BaseModel):
32
+ """The decision made by the resume screener"""
33
+
34
+ criteria_decisions: List[CriteriaDecision] = Field(
35
+ description="The decisions made based on the criteria"
36
+ )
37
+ overall_reasoning: str = Field(
38
+ description="The reasoning behind the overall decision"
39
+ )
40
+ overall_decision: bool = Field(
41
+ description="The overall decision made based on the criteria"
42
+ )
43
 
44
 
 
45
  def _format_criteria_str(criteria: List[str]) -> str:
46
  criteria_str = ""
47
  for criterion in criteria:
 
50
 
51
 
52
  class ResumeScreenerPack(BaseLlamaPack):
53
+ def __init__(
54
+ self,
55
+ job_description: str,
56
+ criteria: List[str],
57
+ llm: Optional[LLM] = None,
58
+ ) -> None:
59
+ self.reader = PDFReader()
60
+ llm = llm or OpenAI(model="gpt-4")
61
+ service_context = ServiceContext.from_defaults(llm=llm)
62
+ self.synthesizer = TreeSummarize(
63
+ output_cls=ResumeScreenerDecision, service_context=service_context
64
+ )
65
+ criteria_str = _format_criteria_str(criteria)
66
+ self.query = QUERY_TEMPLATE.format(
67
+ job_description=job_description, criteria_str=criteria_str
68
+ )
69
+
70
+ def get_modules(self) -> Dict[str, Any]:
71
+ """Get modules."""
72
+ return {"reader": self.reader, "synthesizer": self.synthesizer}
73
+
74
+ def run(self, resume_path: str, *args: Any, **kwargs: Any) -> Any:
75
+ """Run pack."""
76
+ docs = self.reader.load_data(Path(resume_path))
77
+ output = self.synthesizer.synthesize(
78
+ query=self.query,
79
+ nodes=[NodeWithScore(node=doc, score=1.0) for doc in docs],
80
+ )
81
+ return output.response
82
 
83
 
84
  def main():