Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions crates/stringflow-py/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@ use pyo3::prelude::*;

fn to_py_err(e: stringflow::Error) -> PyErr {
match &e {
stringflow::Error::Unavailable(_) => PyErr::new::<PyConnectionError, _>(e.to_string()),
stringflow::Error::RequestFailed(_) => PyErr::new::<PyRuntimeError, _>(e.to_string()),
stringflow::Error::EmptyResponse => PyErr::new::<PyRuntimeError, _>(e.to_string()),
stringflow::Error::Unavailable(_) => {
PyErr::new::<PyConnectionError, _>(format!("[connection] {e}"))
}
stringflow::Error::RequestFailed(_) => {
PyErr::new::<PyRuntimeError, _>(format!("[request] {e}"))
}
stringflow::Error::EmptyResponse => {
PyErr::new::<PyRuntimeError, _>(format!("[empty_response] {e}"))
}
}
}

Expand Down
17 changes: 15 additions & 2 deletions py/stringflow/core.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,22 @@ def chat(
auth_header: str | None = None,
auth_value: str | None = None,
) -> str:
"""Low-level: send a chat request. Returns the response text."""
"""Low-level: send a chat request. Returns the response text.

Raises:
ConnectionError: ``[connection] ...`` when the server is unreachable.
RuntimeError: ``[request] ...`` when the API returns an error, or
``[empty_response] ...`` when the model returns no content.
ValueError: When *wire_format* is not a recognised format.
"""
...

def health_check(base_url: str) -> str:
"""Low-level: send a health check. Returns the status string."""
"""Low-level: send a health check. Returns the status string.

Raises:
ConnectionError: ``[connection] ...`` when the server is unreachable.
RuntimeError: ``[request] ...`` when the server returns an error, or
``[empty_response] ...`` when the response has no content.
"""
...
Loading