INNER CODE UNIT · Python

answer

skyportal/skyportal · services/assistant/app.py:250

def answer(conversation, context_type, context_id, user, token):
    """The answer, the tools it took to get there, and any filter it built."""
    tools = list_tools(token, context_type)
    offered = {tool["function"]["name"] for tool in tools}
    messages = build_messages(conversation, MAX_CONTEXT, context_type, context_id, user)
    trace = []

    deadline = time.monotonic() + ANSWER_TIMEOUT
    # One round-trip can ask for several tools at once, so count the calls
    # themselves. Counting round-trips lets a paging model run four times over.
    calls_made = 0
    while calls_made < MAX_TOOL_CALLS:
        if (left := remaining(deadline)) is None:
            log("out of time before the model finished; answering from what it has")
            break
        message = chat(messages, tools, timeout=left)
        calls = message.get("tool_calls") or []
        if not calls:

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…