From 9a6d3bb2602f9d14009d3c8f36b6a1027835203c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D0=B8=D0=BD=D0=B0=D1=80=20=D0=9C=D0=B8=D1=80=D0=B7?= =?UTF-8?q?=D0=B0=D0=B3=D0=B8=D1=82=D0=BE=D0=B2?= Date: Thu, 28 May 2026 09:28:56 +0000 Subject: [PATCH] Update main.py --- main.py | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/main.py b/main.py index bc06b49..f9c3eb2 100644 --- a/main.py +++ b/main.py @@ -1,16 +1,29 @@ -#!/usr/bin/env python3 -""" -Solution for task 6997111cd6d3a5544a3deffd. -This file contains a minimal example implementation. -""" +import os +from langchain_openai import ChatOpenAI -def greet(name: str) -> str: - """Return a greeting message for the given name.""" - return f"Hello, {name}!" +# Configure LLM to connect to local LM Studio server +llm = ChatOpenAI( + model="gpt-4o-mini", # or any model name supported by the local server + temperature=0, + base_url="http://localhost:1234/v1", + api_key="lm-studio" +) + +def ask(prompt: str) -> str: + """Send a prompt to the LLM and return its response.""" + result = llm.invoke({"input": prompt}) + # The output is in result.content + return result.content if __name__ == "__main__": - import sys - if len(sys.argv) > 1: - print(greet(sys.argv[1])) - else: - print("Usage: python main.py ") + print("Simple AI Agent – type your question (Ctrl+C to exit).") + while True: + try: + user_input = input("\n> ") + if not user_input.strip(): + continue + response = ask(user_input) + print(f"\nAnswer: {response}") + except KeyboardInterrupt: + print("\nExiting.") + break