Skip to content

Forward AI

forward_sdk._sync.services.ai.AiService

Bases: Service

Ask Forward questions about a network in plain language.

See the module docstring: unpublished, and unavailable to an organization without Forward AI, which answers 403.

list

list() -> list[AiConversation]

The calling user's chats, most recent first as Forward returns them.

start

start(
    prompt: str,
    *,
    network_id: str | None = None,
    snapshot_id: str | None = None,
    busy_timeout: float = 0.0,
) -> AiConversation

Start a chat and ask its first question.

Returns as soon as Forward accepts the question, with the chat in PROCESSING. Call :meth:AiConversation.wait for the answer, or use :meth:ask to do both.

busy_timeout is how long to wait for your turn if another of your chats is still answering; 0 raises :class:~forward_sdk.errors.ForwardRateLimitError at once. See the module docstring.

Note this creates something: a chat is stored against your user until deleted.

ask

ask(
    prompt: str,
    *,
    network_id: str | None = None,
    snapshot_id: str | None = None,
    timeout: float | None = DEFAULT_TIMEOUT,
    busy_timeout: float = 0.0,
) -> AiMessage | None

Ask one question and wait for the answer.

The convenience form: start a chat, wait, and return the answer. Use :meth:start when you want to keep asking follow-ups in the same conversation, which keeps them grounded in the same snapshot.

generate_nqe_query

generate_nqe_query(prompt: str) -> AnalysisNqeQueryAssist

Turn a plain-language request into an NQE query.

summarize_nqe_query

summarize_nqe_query(query: str) -> AnalysisNqeSummaryAssist

Describe what an NQE query does, in plain language.

ask_nqe_docs

ask_nqe_docs(
    question: str,
    *,
    previous_messages: Sequence[Mapping[str, Any]]
    | None = None,
) -> AnalysisNqeDocAssist

Ask a question about NQE, answered from its documentation.

suggest_nqe_doc_followups

suggest_nqe_doc_followups(
    doc_assist_id: str, answer: str
) -> AnalysisNqeDocAssistFollowup

Suggest follow-up questions for an answer from :meth:ask_nqe_docs.

forward_sdk._sync.services.ai.AiConversation

A live handle on one conversation, grounded in a single snapshot.

Named apart from the :class:~forward_sdk.models.AiChat model it wraps: that is the data Forward returned, this is the thing you poll and ask follow-up questions of.

Obtained from :meth:AiService.start or :meth:AiService.get.

chat property

chat: AiChat

The chat as last seen, without making a request.

is_done property

is_done: bool

Whether the last status seen was terminal, without making a request.

snapshot_id property

snapshot_id: str | None

The snapshot the answers are grounded in.

Worth reading: a chat is pinned to one snapshot for its lifetime, so a follow-up question is answered against the same model as the first.

refresh

refresh() -> AiChat

Fetch the chat's current state.

wait

wait(
    *,
    poll_interval: float = POLL_INTERVAL,
    timeout: float | None = DEFAULT_TIMEOUT,
) -> AiChat

Poll until Forward has finished answering.

Raises:

Type Description
ForwardTimeoutError

timeout elapsed first. Forward keeps working; the handle stays usable.

messages

messages(*, since: str | None = None) -> list[AiMessage]

The questions asked and the answers given, oldest first.

ask

ask(prompt: str, *, busy_timeout: float = 0.0) -> None

Ask a follow-up question.

Returns as soon as Forward accepts it. Call :meth:wait for the answer. busy_timeout is how long to wait while another chat is answering; see the module docstring.

latest_answer

latest_answer() -> AiMessageAnswer | None

The answer to the most recent question, if there is one yet.

ask_and_wait

ask_and_wait(
    prompt: str,
    *,
    timeout: float | None = DEFAULT_TIMEOUT,
    busy_timeout: float = 0.0,
) -> AiMessage | None

Ask a follow-up and return the answer, or None if there is none.

transcript

transcript(*, format: str = 'MARKDOWN') -> str

Render the whole conversation as Markdown, HTML or JSON.