Update main.py

This commit is contained in:
2026-05-28 09:28:56 +00:00
parent ba4ce57598
commit 9a6d3bb260
+26 -13
View File
@@ -1,16 +1,29 @@
#!/usr/bin/env python3 import os
""" from langchain_openai import ChatOpenAI
Solution for task 6997111cd6d3a5544a3deffd.
This file contains a minimal example implementation.
"""
def greet(name: str) -> str: # Configure LLM to connect to local LM Studio server
"""Return a greeting message for the given name.""" llm = ChatOpenAI(
return f"Hello, {name}!" 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__": if __name__ == "__main__":
import sys print("Simple AI Agent type your question (Ctrl+C to exit).")
if len(sys.argv) > 1: while True:
print(greet(sys.argv[1])) try:
else: user_input = input("\n> ")
print("Usage: python main.py <name>") if not user_input.strip():
continue
response = ask(user_input)
print(f"\nAnswer: {response}")
except KeyboardInterrupt:
print("\nExiting.")
break