У меня возникла ошибка
ValueError(f"Отсутствуют некоторые входные клавиши: {missing_keys}")
в этом коде, и я пытаюсь проанализировать резюме, в которых не должно быть ключевого слова Имя телефона about_me в нем.
Однако он анализирует ключевое слово, которое находит похожим на класс pydantic. Если используется приглашение там, где я упоминаю, что в полях нет информации, нужно указать значение null.Traceback (последний последний вызов):
Файл «C:\Users\Sarthak\PycharmProjects\API Resume parser\main.py», строка 188, в
info = ExtractInformationFromResume( извлеченный_текст)
Файл «C:\Users\Sarthak\PycharmProjects\API Resume parser\main.py», строка 120, в ExtractInformationFromResume
response = Chain.run({"resume": резюме})Файл «C:\Users\Sarthak\PycharmProjects\API Resume parser\venv\lib\site-packages\langchain_core_api\deprecation.py», строка 179, в alert_emitting_wrapper
return завернутый(*args, ** kwargs)
Файл «C:\Users\Sarthak\PycharmProjects\API Resume parser\venv\lib\site-packages\langchain\chains\base.py», строка 606, при запуске
return self( args[0], callbacks=обратные вызовы, tags=tags, метаданные=метаданные)[
Файл "C:\Users\Sarthak\PycharmProjects\API Resume parser\venv\lib\site-packages\langchain_core_api\deprecation.py ", строка 179, в alert_emitting_wrapper
возврат завернутый(*args, **kwargs)
Файл "C:\Users\Sarthak\PycharmProjects\API Resume parser\venv\lib\site-packages\langchain\ Chains\base.py", строка 389, в call
return self.invoke(
File "C:\Users\Sarthak\PycharmProjects\API Resume parser\venv\lib \site-packages\langchain\chains\base.py", строка 170, в вызове
raise e
файл "C:\Users\Sarthak\PycharmProjects\API Resume parser\venv\lib\site- packages\langchain\chains\base.py", строка 158, в вызове
self._validate_inputs(inputs)
файл "C:\Users\Sarthak\PycharmProjects\API Resume parser\venv\lib\site -packages\langchain\chains\base.py", строка 290, в _validate_inputs
raise ValueError(f"Отсутствуют некоторые входные ключи: {missing_keys}")
ValueError: Отсутствуют некоторые входные ключи: {'\ n «Контактная информация»'
ContactInformation: Optional[ContactInformation] = None
About_Me: Optional[str] = None
Experience: Optional[Union[None, List[Experience]]] = None
Education: Optional[Union[None, List[Education]]] = None
Skills: Optional[List[str]] = None
Certificates: Optional[List[str]] = None
Projects: Optional[Union[None, List[Projects]]] = None
Achievements: Optional[List[str]] = None
Volunteer: Optional[List[str]] = None
PROMPT_2 = """You are given resume : ```{resume}```
Based on the given resume, extract information about the person.
The output should strictly follow the JSON schema below. If a field does not have information, set it to null.
Ensure that the email contains an "@" symbol and the contact number is a string of digits.
The name is usually found at the beginning of the resume without any labels.
Social links should be valid URLs.
{
"ContactInformation": {
"Name": string, // Name of the person, usually at the beginning
"Email": string, // Email address containing "@"
"Contact": string, // Contact number as a string of digits
"Links": [string] // Array of social profile URLs
},
"About_Me": string, // A brief summary about the person
"Experience": [
{
"title": string, // Title of the position
"company": string, // Company name
"duration": string // Duration of employment
}
],
"Education": [
{
"course": string, // Name of the course or subject studied
"branch": string, // Branch or faculty of study
"institute": string // Name of the educational institute
}
],
"Skills": [string], // Array of skills
"Certificates": [string], // Array of certificates
"Projects": [
{
"name": string, // Name of the project
"description": string, // Description of the project
"link": string // URL to the project
}
],
"Achievements": [string], // Array of achievements
"Volunteer": [string] // Array of volunteer work
}
"""
def ExtractInformationFromResume(resume: str) -> OutputFormat:
llm = ChatOpenAI(
openai_api_key='*********************************************',
temperature=0.5,
model_name="gpt-3.5-turbo")
# Define the output parser
parser = PydanticOutputParser(pydantic_object=OutputFormat)
# Create the prompt template with format instructions
prompt_template = PromptTemplate(
input_variables=["resume"],
template=PROMPT_2,
partial_variables={"format_instructions": parser.get_format_instructions()},
)
# Chain the LLM with the prompt
chain = LLMChain(llm=llm, prompt=prompt_template)
# Run the chain with the resume as input
print(f"Resume Length: {len(resume)} characters")
response = chain.run({"resume": resume})
try:
print("Raw LLM Response:", response)
except Exception as e:
print(f"Error: {str(e)}")
# Parse the LLM response into the expected output format
try:
return OutputFormat(**json.loads(response))
except json.JSONDecodeError:
raise ValueError("Failed to parse response as valid JSON: " + response)```
Подробнее здесь: https://stackoverflow.com/questions/790 ... ssing-keys