| import os |
| import re |
| import requests |
| from dotenv import load_dotenv |
| from langchain_openai import ChatOpenAI |
|
|
| load_dotenv() |
|
|
| llm = ChatOpenAI( |
| model="qwen3.5-35b-a3b", |
| openai_api_key=os.getenv("AGICTO_API_KEY"), |
| openai_api_base=os.getenv("AGICTO_BASE_URL", "https://api.agicto.cn/v1"), |
| temperature=0.0, |
| max_tokens=256, |
| ) |
|
|
| SYSTEM_PROMPT = ( |
| "Answer with one word or number.\n" |
| "No explanation.\n" |
| "No punctuation.\n" |
| "No units.\n" |
| "No tags." |
| ) |
|
|
| def clean(text: str) -> str: |
| text = re.sub(r".*?", "", text, flags=re.S) |
| return text.strip().splitlines()[0] |
|
|
| def agent(question: str, files=None) -> str: |
| try: |
| context = "" |
| if files: |
| for f in files: |
| r = requests.get(f, timeout=10) |
| if r.ok: |
| context += r.text[:6000] |
|
|
| res = llm.invoke([ |
| {"role": "system", "content": SYSTEM_PROMPT}, |
| {"role": "user", "content": f"{context}{question}"} |
| ]) |
|
|
| return clean(res.content) |
|
|
| except Exception: |
| return "0" |