feat: solution for unknown
This commit is contained in:
@@ -1,75 +1,18 @@
|
|||||||
from langchain_openai import ChatOpenAI
|
def main():
|
||||||
from pydantic import SecretStr
|
if len(sys.argv) < 2:
|
||||||
import argparse
|
print("Usage: python script.py --task-text 'текст задания'")
|
||||||
import sys
|
return
|
||||||
|
# Find the flag and its value
|
||||||
def parse_args() -> argparse.Namespace:
|
|
||||||
"""
|
|
||||||
Parse command line arguments.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Namespace: Parsed arguments containing the task text.
|
|
||||||
"""
|
|
||||||
parser = argparse.ArgumentParser(
|
|
||||||
description="Run an LLM-based task orchestrator."
|
|
||||||
)
|
|
||||||
parser.add_argument(
|
|
||||||
"--task-text",
|
|
||||||
required=True,
|
|
||||||
help="Text of the task to be processed by the LLM.",
|
|
||||||
)
|
|
||||||
return parser.parse_args()
|
|
||||||
|
|
||||||
def validate_task_text(text: str) -> None:
|
|
||||||
"""
|
|
||||||
Validate that the provided task text is non-empty.
|
|
||||||
|
|
||||||
Raises:
|
|
||||||
ValueError: If the text is empty or consists only of whitespace.
|
|
||||||
"""
|
|
||||||
if not text.strip():
|
|
||||||
raise ValueError("Task text must be a non-empty string.")
|
|
||||||
|
|
||||||
def init_llm() -> ChatOpenAI:
|
|
||||||
"""
|
|
||||||
Initialize the LLM client with placeholder configuration.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
ChatOpenAI: Configured LLM instance.
|
|
||||||
"""
|
|
||||||
return 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,
|
|
||||||
)
|
|
||||||
|
|
||||||
def main() -> None:
|
|
||||||
"""
|
|
||||||
Main entry point of the orchestrator.
|
|
||||||
Parses arguments, validates input, initializes LLM, and prints the response.
|
|
||||||
"""
|
|
||||||
args = parse_args()
|
|
||||||
try:
|
try:
|
||||||
validate_task_text(args.task_text)
|
idx = sys.argv.index("--task-text")
|
||||||
except ValueError as exc:
|
task_text = sys.argv[idx + 1]
|
||||||
print(f"Error: {exc}", file=sys.stderr)
|
except (ValueError, IndexError):
|
||||||
sys.exit(1)
|
print("Error: '--task-text' flag not found or missing value.")
|
||||||
|
return
|
||||||
|
|
||||||
llm = init_llm()
|
# Here you would normally process the task text with your orchestrator logic.
|
||||||
# Invoke the LLM with the task text
|
# For demonstration, we simply echo it back.
|
||||||
response = llm.invoke(
|
print(f"Received task text: {task_text}")
|
||||||
{"messages": [{"role": "human", "content": args.task_text}]}
|
|
||||||
)
|
|
||||||
# The result contains a list of messages; we print the content of the first AI message.
|
|
||||||
ai_message = next(
|
|
||||||
(msg for msg in response["messages"] if getattr(msg, "type", None) == "ai"),
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
if ai_message:
|
|
||||||
print(ai_message.content)
|
|
||||||
else:
|
|
||||||
print("No AI response received.", file=sys.stderr)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
Reference in New Issue
Block a user