Skip to content

Conversation

@RawthiL
Copy link
Contributor

@RawthiL RawthiL commented Jun 24, 2025

Summary

Added streaming support for contentypes:

These are streams delimited by newlines (\n) that can be supported by Pocket Network without any change to the verification and accounting logic.

The first one, text/event-stream, is the one used by streaming LLM responses (OpenAI format) and is a functionality that we need asap.

Primary Changes:

  • Added new file http_stream.go that implements streaming responses of the mentioned types.
  • Added a custom delimiter for the Pocket Network streamed responses, necessary to avoid collision with arbitrary payloads and supplier signature.
  • Modified sync.go to check for the backend response headers and implement either this streaming protocol or respond normally (read full response first and then relay)

Secondary Changes:

  • Modified the order of some checks in the serveSyncRequest() function, to keep code more tidy.
  • Modified processStreamRequest to provide an example on how to support streaming responses by an app.
  • Modified processStreamRequest to make code more modular and re-use functions between normal and streamed response.

Checks:

I tested this in beta-testnet, against a vLLM enpoint, using this custom RM and the pocketd relayminer relay command:

pocketd relayminer relay \
    --app=pokt1wvn4a8kj4mfnq0cjakadskxwr2zkev35psjxh9 \
    --supplier=pokt19a3t4yunp0dlpfjrp7qwnzwlrzd5fzs2gjaaaj \
    --node=https://shannon-testnet-grove-rpc.beta.poktroll.com  \
    --grpc-addr=shannon-testnet-grove-grpc.beta.poktroll.com:443 \
    --grpc-insecure=false \
    --payload='{"messages": [{"role": "user", "content": "Tell me how to properly eat a Choripan."}],"max_tokens":200, "model":"pocket_network", "stream":true}' \
    --supplier-public-endpoint-override=http://localhost:8545/v1/chat/completions \
    --network=beta

response:

{"level":"warn","time":"2025-06-24T16:40:29-03:00","message":"⚠️ Using override endpoint URL: http://localhost:8546/v1/chat/completions"}
{"level":"info","time":"2025-06-24T16:40:29-03:00","message":"✅ JSON-RPC request payload serialized."}
{"level":"info","time":"2025-06-24T16:40:29-03:00","message":"✅ Relay request built."}
{"level":"info","time":"2025-06-24T16:40:29-03:00","message":"✅ Retrieved private key for app pokt1wvn4a8kj4mfnq0cjakadskxwr2zkev35psjxh9"}
{"level":"info","time":"2025-06-24T16:40:29-03:00","message":"✅ Relay request signed."}
{"level":"info","time":"2025-06-24T16:40:29-03:00","message":"✅ Relay request marshaled."}
{"level":"info","time":"2025-06-24T16:40:29-03:00","message":"✅ Endpoint URL parsed: http://localhost:8546/v1/chat/completions"}
{"level":"info","time":"2025-06-24T16:40:30-03:00","message":"🔍 Content-Type: text/event-stream; charset=utf-8"}
{"level":"info","time":"2025-06-24T16:40:30-03:00","message":"🌊 Handling streaming response with status:"}
{"level":"info","time":"2025-06-24T16:40:30-03:00","message":"📦 Read chunk of length 449"}
{"level":"info","time":"2025-06-24T16:40:30-03:00","message":"✅ Deserialized response body as JSON map: map[choices:[map[delta:map[content: role:assistant] finish_reason:<nil> index:0 logprobs:<nil>]] created:1.75079403e+09 id:chat-2b20014c1d124d1da32d6a71139ea77e model:pocket_network object:chat.completion.chunk]"}
{"level":"info","time":"2025-06-24T16:40:30-03:00","message":"📦 Read chunk of length 213"}
{"level":"info","time":"2025-06-24T16:40:30-03:00","message":"📦 Read chunk of length 432"}
{"level":"info","time":"2025-06-24T16:40:30-03:00","message":"✅ Deserialized response body as JSON map: map[choices:[map[delta:map[content:Ch] finish_reason:<nil> index:0 logprobs:<nil>]] created:1.75079403e+09 id:chat-2b20014c1d124d1da32d6a71139ea77e model:pocket_network object:chat.completion.chunk]"}
{"level":"info","time":"2025-06-24T16:40:30-03:00","message":"📦 Read chunk of length 213"}
{"level":"info","time":"2025-06-24T16:40:30-03:00","message":"📦 Read chunk of length 432"}
{"level":"info","time":"2025-06-24T16:40:31-03:00","message":"✅ Deserialized response body as JSON map: map[choices:[map[delta:map[content:or] finish_reason:<nil> index:0 logprobs:<nil>]] created:1.75079403e+09 id:chat-2b20014c1d124d1da32d6a71139ea77e model:pocket_network object:chat.completion.chunk]"}
{"level":"info","time":"2025-06-24T16:40:31-03:00","message":"📦 Read chunk of length 213"}
{"level":"info","time":"2025-06-24T16:40:31-03:00","message":"📦 Read chunk of length 432"}
{"level":"info","time":"2025-06-24T16:40:31-03:00","message":"✅ Deserialized response body as JSON map: map[choices:[map[delta:map[content:ip] finish_reason:<nil> index:0 logprobs:<nil>]] created:1.75079403e+09 id:chat-2b20014c1d124d1da32d6a71139ea77e model:pocket_network object:chat.completion.chunk]"}
{"level":"info","time":"2025-06-24T16:40:31-03:00","message":"📦 Read chunk of length 213"}
{"level":"info","time":"2025-06-24T16:40:31-03:00","message":"📦 Read chunk of length 432"}
{"level":"info","time":"2025-06-24T16:40:31-03:00","message":"✅ Deserialized response body as JSON map: map[choices:[map[delta:map[content:an] finish_reason:<nil> index:0 logprobs:<nil>]] created:1.75079403e+09 id:chat-2b20014c1d124d1da32d6a71139ea77e model:pocket_network object:chat.completion.chunk]"}
{"level":"info","time":"2025-06-24T16:40:31-03:00","message":"📦 Read chunk of length 213"}
{"level":"info","time":"2025-06-24T16:40:31-03:00","message":"📦 Read chunk of length 433"}
{"level":"info","time":"2025-06-24T16:40:32-03:00","message":"✅ Deserialized response body as JSON map: map[choices:[map[delta:map[content: is] finish_reason:<nil> index:0 logprobs:<nil>]] created:1.75079403e+09 id:chat-2b20014c1d124d1da32d6a71139ea77e model:pocket_network object:chat.completion.chunk]"}
...

Type of change

Select one or more from the following:

  • New feature, functionality or library
  • Bug fix
  • Code health or cleanup
  • Documentation
  • Other (specify)

Sanity Checklist

  • I have updated the GitHub Issue Metadata: assignees, reviewers, labels, project, iteration and milestone
  • For docs: make docusaurus_start
  • For small changes: make go_develop_and_test and make test_e2e
  • For major changes: devnet-test-e2e label to run E2E tests in CI
  • For migration changes: make test_e2e_oneshot
  • 'TODO's, configurations and other docs

@RawthiL RawthiL requested a review from jorgecuesta June 24, 2025 19:43
@jorgecuesta jorgecuesta added relayminer Changes related to the Relayminer proxy Changes related to the Proxy labels Jun 24, 2025
@jorgecuesta jorgecuesta requested review from Olshansk and red-0ne June 24, 2025 20:43
@jorgecuesta
Copy link
Contributor

@RawthiL Please update it with a rebase, but after that is LGTM 🚀

Now it needs to get reviewed by Pocket Team @red-0ne @Olshansk

@Olshansk
Copy link
Collaborator

@jorgecuesta @RawthiL Just to set some expectations (since everyone has a lot going on):

  • Might take our team a few days to get to this PR
  • I don't know (without reviewing) if it'll require changes or be an auto-approval

To expedite things, lmk if you want us to build a similar binary to this dev release so you're not blocked.

@jorgecuesta
Copy link
Contributor

@jorgecuesta @RawthiL Just to set some expectations (since everyone has a lot going on):

  • Might take our team a few days to get to this PR
  • I don't know (without reviewing) if it'll require changes or be an auto-approval

To expedite things, lmk if you want us to build a similar binary to this dev release so you're not blocked.

I think it is smooth, a dev release will be great. But Idk if that will allow me to get the image of it.

@Olshansk
Copy link
Collaborator

Olshansk commented Jun 25, 2025

@RawthiL Could you please reopen this PR as a branch of the main repo and not your fork?

It'll enable me to publish a dev-release (and push review changes when I get around to it).

@RawthiL
Copy link
Contributor Author

RawthiL commented Jun 25, 2025

Closing in favor of internal branch PR:
#1570

@RawthiL RawthiL closed this Jun 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

proxy Changes related to the Proxy relayminer Changes related to the Relayminer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants