# LineIterator

> **Class** in `langchain_aws`

📖 [View in docs](https://reference.langchain.com/python/langchain-aws/llms/sagemaker_endpoint/LineIterator)

A helper class for parsing the byte stream input.

    The output of the model will be in the following format:

    b'{"outputs": [" a"]}
'
    b'{"outputs": [" challenging"]}
'
    b'{"outputs": [" problem"]}
'
    ...

    While usually each PayloadPart event from the event stream will
    contain a byte array with a full json, this is not guaranteed
    and some of the json objects may be split acrossPayloadPart events.

    For example:

    {'PayloadPart': {'Bytes': b'{"outputs": '}}
    {'PayloadPart': {'Bytes': b'[" problem"]}
'}}

    This class accounts for this by concatenating bytes written via the 'write' function
    and then exposing a method which will return lines (ending with a '
' character)
    within the buffer via the 'scan_lines' function.
    It maintains the position of the last read position to ensure
    that previous bytes are not exposed again.

    For more details see:
    https://aws.amazon.com/blogs/machine-learning/elevating-the-generative-ai-experience-introducing-streaming-support-in-amazon-sagemaker-hosting/

## Signature

```python
LineIterator(
    self,
    stream: Any,
)
```

## Constructors

```python
__init__(
    self,
    stream: Any,
) -> None
```

| Name | Type |
|------|------|
| `stream` | `Any` |


## Properties

- `byte_iterator`
- `buffer`
- `read_pos`

---

[View source on GitHub](https://github.com/langchain-ai/langchain-aws/blob/10d18256d46953e5fc8dca313a2c41eee29c2a80/libs/aws/langchain_aws/llms/sagemaker_endpoint.py#L32)