-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
87 lines (74 loc) · 2.73 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import agenta as ag
from typing import Optional
from langchain.chains.openai_functions import (
create_openai_fn_chain,
create_structured_output_chain,
)
from langchain.chat_models import ChatOpenAI
from langchain.prompts import ChatPromptTemplate, HumanMessagePromptTemplate
from langchain.schema import HumanMessage, SystemMessage
from pydantic import BaseModel, Field
CHAT_LLM_GPT = [
"gpt-3.5-turbo-16k-0613",
"gpt-3.5-turbo-16k",
"gpt-3.5-turbo-0613",
"gpt-3.5-turbo-0301",
"gpt-3.5-turbo",
"gpt-4",
]
ag.init()
ag.config.default(
system_message=ag.TextParam(
"You are a world class algorithm for extracting information in structured formats."
),
human_message=ag.TextParam(
"Please extract the following information from the given input:"
),
content_message=ag.TextParam("Tips: Make sure to answer in the correct format"),
company_desc_message=ag.TextParam("The name of the company"),
position_desc_message=ag.TextParam("The name of the position"),
salary_range_desc_message=ag.TextParam("The salary range of the position"),
temperature=ag.FloatParam(0.9),
top_p=ag.FloatParam(0.9),
presence_penalty=ag.FloatParam(0.0),
frequency_penalty=ag.FloatParam(0.0),
model=ag.MultipleChoiceParam("gpt-3.5-turbo-0613", CHAT_LLM_GPT),
)
def create_job_class(company_desc: str, position_desc: str, salary_range_desc: str):
"""Create a job class to be used in langchain"""
class Job(BaseModel):
company_name: str = Field(..., description=company_desc)
position_name: str = Field(..., description=position_desc)
salary_range: Optional[str] = Field(None, description=salary_range_desc)
return Job
@ag.entrypoint
def generate(
job_description: str,
) -> str:
"""Extract information from a job description"""
llm = ChatOpenAI(
model=ag.config.model,
temperature=ag.config.temperature,
top_p=ag.config.top_p,
presence_penalty=ag.config.presence_penalty,
frequency_penalty=ag.config.frequency_penalty,
)
prompt_msgs = [
SystemMessage(content=ag.config.system_message),
HumanMessage(content=ag.config.human_message),
HumanMessagePromptTemplate.from_template("{input}"),
HumanMessage(content=ag.config.content_message),
]
prompt = ChatPromptTemplate(messages=prompt_msgs)
chain = create_structured_output_chain(
create_job_class(
company_desc=ag.config.company_desc_message,
position_desc=ag.config.position_desc_message,
salary_range_desc=ag.config.salary_range_desc_message,
),
llm,
prompt,
verbose=False,
)
output = chain.run(job_description)
return str(output)