From 7fcfe77bbe7b32b0051c5a93c6ece2fc69c8353b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D0=B5=D0=BC=20=D0=92=D0=BB=D0=B0=D0=B4?= =?UTF-8?q?=D0=B8=D0=BC=D0=B8=D1=80=D0=BE=D0=B2=D0=B8=D1=87=20=D0=91=D0=B0?= =?UTF-8?q?=D0=B1=D0=B0=D0=B9=D0=BA=D0=B8=D0=BD?= Date: Thu, 28 May 2026 16:37:33 +0000 Subject: [PATCH] feat: solution for 6a1865008a94f887e50d471c --- .../6a1865008a94f887e50d471c/solution.py | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 solutions/6a1865008a94f887e50d471c/solution.py diff --git a/solutions/6a1865008a94f887e50d471c/solution.py b/solutions/6a1865008a94f887e50d471c/solution.py new file mode 100644 index 0000000..43953a5 --- /dev/null +++ b/solutions/6a1865008a94f887e50d471c/solution.py @@ -0,0 +1,82 @@ +from langchain_openai import ChatOpenAI +from pydantic import BaseModel, Field, SecretStr +from langchain_core.output_parsers import PydanticOutputParser +from langchain_core.prompts import PromptTemplate +import sys + +# LLM placeholder +llm = ChatOpenAI( + model="openai/gpt-oss-20b", + base_url='https://platform.brojs.ru/jrnl-bh/api/inference/v1', + api_key=SecretStr("jrnl_30283ab953615cbb6846ff9940a1eedce0b76d7b2f59a2394f29e74643e6a90d"), + temperature=0.7, +) + +class PersonInfo(BaseModel): + name: str = Field(description="Full name") + age: int | None = Field(default=None, description="Age in years") + profession: str = Field(description="Job title") + skills: list[str] = Field(description="List of technical skills") + +class MeetingNotes(BaseModel): + date: str = Field(description="Meeting date in ISO format") + participants: list[str] = Field(description="Names of attendees") + topics: list[str] = Field(description="Discussion topics") + decisions: list[str] = Field(description="Decisions made") + next_steps: list[str] = Field(description="Action items") + +# Prompt templates +person_prompt = PromptTemplate( + input_variables=["text"], + template=( + "Extract a PersonInfo object from the following text. " + "Return only JSON matching the schema.\n\n" + "{format_instructions}\n\nText: {text}" + ), +) +meeting_prompt = PromptTemplate( + input_variables=["text"], + template=( + "Extract a MeetingNotes object from the following text. " + "Return only JSON matching the schema.\n\n" + "{format_instructions}\n\nText: {text}" + ), +) + +# Parsers +person_parser = PydanticOutputParser(pydantic_object=PersonInfo) +meeting_parser = PydanticOutputParser(pydantic_object=MeetingNotes) + +def route_and_parse(text: str): + # Simple heuristic: presence of "meeting" or date-like pattern + if "meeting" in text.lower() or any(c.isdigit() for c in text[:10]): + prompt = meeting_prompt.partial( + format_instructions=meeting_parser.get_format_instructions() + ) + chain = prompt | llm | meeting_parser + result = chain.invoke({"text": text}) + return MeetingNotes(**result) + else: + prompt = person_prompt.partial( + format_instructions=person_parser.get_format_instructions() + ) + chain = prompt | llm | person_parser + result = chain.invoke({"text": text}) + return PersonInfo(**result) + +def main(): + examples = [ + "Анна, 28 лет, Python-разработчик. Навыки: FastAPI, Docker.", + "Meeting on 2024-05-27 with Alice and Bob. Topics: budget, timeline. Decisions: approve Q3 plan. Next steps: send email to stakeholders." + ] + if len(sys.argv) > 1: + inputs = [" ".join(sys.argv[1:])] + else: + inputs = examples + for txt in inputs: + print("\nInput:", txt) + obj = route_and_parse(txt) + print(obj.model_dump()) + +if __name__ == "__main__": + main() \ No newline at end of file