INNER CODE UNIT · Python

llm_chat

usepr/eva · eva.py:469

def llm_chat(messages, tools=None, temperature=0.6, thinking=True):
    url = f"{EVA_BASE_URL}/chat/completions"
    data = _build_request_data(messages, tools, temperature, thinking, stream=False)
    body = json.dumps(data).encode('utf-8')
    req = urllib.request.Request(
        url, data=body,
        headers={**COMMON_HEADER, "Content-Type": "application/json"}
    )
    try:
        with urllib.request.urlopen(req) as resp:
            out = json.loads(resp.read().decode('utf-8', errors='replace'))
    except urllib.error.HTTPError as e:
        raw = e.read().decode('utf-8', errors='replace')
        raise Exception(f"HTTP {e.code}: {raw}")

    try:
        return out["choices"][0]["message"], out['usage']
    except Exception as e:

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…