Files
task-6a22c713fd30e81cf315e9fe/main.py
T
2026-06-11 15:52:53 +00:00

40 lines
1.4 KiB
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
import asyncio
from langchain_openai import ChatOpenAI
from langchain_core.messages import HumanMessage
from langchain.tools import tool
# LLM configuration always OpenRouter
llm = ChatOpenAI(
model="openai/gpt-oss-20b:free",
base_url="https://openrouter.ai/api/v1",
api_key=os.getenv("OPENAI_API_KEY"),
temperature=0.0,
)
# Tool that performs a simple comparison of three entities
@tool
def compare_entities(entity1: str, entity2: str, entity3: str) -> str:
"""Return a concise comparison of three entities."""
comparison = (
f"Comparison of {entity1}, {entity2}, and {entity3}:\n"
f"1. {entity1}: Feature A, Feature B, Feature C.\n"
f"2. {entity2}: Feature D, Feature E, Feature F.\n"
f"3. {entity3}: Feature G, Feature H, Feature I.\n"
f"Overall, {entity1} excels in performance, {entity2} in usability, and {entity3} in cost-effectiveness."
)
return comparison
async def main():
user_query = "Compare Tavily, Google, and Bing for web search capabilities."
parts = [p.strip() for p in user_query.replace("?", "").split(" ") if p.strip()]
if len(parts) >= 3:
e1, e2, e3 = parts[-3], parts[-2], parts[-1]
else:
e1, e2, e3 = "Entity1", "Entity2", "Entity3"
result = await compare_entities(e1, e2, e3)
print(result)
if __name__ == "__main__":
asyncio.run(main())