feat: solution for unknown

This commit is contained in:
+78 -14
View File
@@ -1,18 +1,82 @@
def main():
if len(sys.argv) < 2:
print("Usage: python script.py --task-text 'текст задания'")
return
# Find the flag and its value
try:
idx = sys.argv.index("--task-text")
task_text = sys.argv[idx + 1]
except (ValueError, IndexError):
print("Error: '--task-text' flag not found or missing value.")
return
from langchain_openai import ChatOpenAI
from pydantic import BaseModel, Field, SecretStr
from langchain.agents import create_agent
import sys
# Here you would normally process the task text with your orchestrator logic.
# For demonstration, we simply echo it back.
print(f"Received task text: {task_text}")
# LLM placeholder configuration
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,
)
# ---------- Pydantic models ----------
class PersonInfo(BaseModel):
"""Information about a person."""
name: str = Field(description="Full name of the person")
age: int | None = Field(default=None, description="Age in years, optional")
profession: str = Field(description="Current occupation or job title")
skills: list[str] = Field(description="List of professional skills")
class MeetingNotes(BaseModel):
"""Summary of a meeting."""
date: str = Field(description="Date of the meeting (ISO format)")
participants: list[str] = Field(description="Names of attendees")
topics: list[str] = Field(description="Main discussion topics")
decisions: list[str] = Field(description="Decisions made during the meeting")
next_steps: list[str] = Field(description="Action items for followup")
# ---------- Agent creation ----------
agent_person = create_agent(
model=llm,
response_format=PersonInfo,
system_prompt="You are an assistant that extracts structured person information from a single sentence.",
)
agent_meeting = create_agent(
model=llm,
response_format=MeetingNotes,
system_prompt="You are an assistant that extracts structured meeting notes from a paragraph of text.",
)
# ---------- Simple heuristic to choose schema ----------
def detect_schema(text: str) -> str:
"""Return 'person' or 'meeting' based on simple keyword heuristics."""
lower = text.lower()
if any(word in lower for word in ("profession", "skills", "age")):
return "person"
if any(word in lower for word in ("meeting", "participants", "decisions", "next steps")):
return "meeting"
# Default to person if ambiguous
return "person"
# ---------- CLI ----------
def main():
examples = [
"Анна, 28 лет, Python-разработчик. Навыки: FastAPI, Docker.",
("Встреча с командой по проекту X прошла 2024-05-20.\n"
"Участники: Иван, Мария, Алексей.\n"
"Темы: планирование спринта, распределение задач.\n"
"Решения: назначить ответственных за каждый модуль.\n"
"Next steps: подготовить спецификации к 2024-05-27."),
]
if len(sys.argv) > 1:
texts = [" ".join(sys.argv[1:])]
else:
texts = examples
for txt in texts:
print("\n=== Input ===")
print(txt)
schema_type = detect_schema(txt)
agent = agent_person if schema_type == "person" else agent_meeting
result = agent.invoke({"messages": [{"role": "user", "content": txt}]})
structured = result["structured_response"]
print("\n=== Output ===")
print(structured.model_dump(indent=2))
print("\n---")
if __name__ == "__main__":
main()