Files
brojs-task-6997111cd6d3a554…/main.py
T
2026-05-28 09:28:56 +00:00

30 lines
877 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import os
from langchain_openai import ChatOpenAI
# 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__":
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