Skip to content
Closed
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Add ProdopsEx to your mix.exs:
```elixir
def deps do
[
{:prodops_ex, "~> 0.1.0"}
{:prodops_ex, "~> 0.2.0"}
]
end
```
Expand Down
2 changes: 1 addition & 1 deletion lib/prodops/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule ProdopsEx.Config do
@definition [
api_url: [
type: :string,
default: "https://app.prodops.ai"
default: "https://app.revelry.ai/"
],
api_key: [
type: :string,
Expand Down
11 changes: 8 additions & 3 deletions lib/prodops/stream.ex
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,14 @@ defmodule ProdopsEx.Stream do
%HTTPoison.AsyncChunk{chunk: chunk} ->
data =
chunk
|> String.split("\n")
|> Enum.filter(fn line -> String.starts_with?(line, "data: ") end)
|> Enum.map(fn line -> String.trim_leading(line, "data: ") end)
|> String.split("\n\n")
|> Enum.map(fn event ->
event
|> String.split("\n")
|> Enum.filter(fn line -> String.starts_with?(line, "data: ") end)
|> Enum.map_join("\n", fn line -> String.trim_leading(line, "data: ") end)
end)
|> Enum.filter(fn data -> data != "" end)
Comment on lines +66 to +73
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not following how this fixes the problem... not saying it doesn't, I'm just confused. 🫤 Seems like it'd end up being the same in the end since we're splitting on the \n in the Enum.map. is the map_join adding back the newlines that were previously split?

Copy link
Author

@stuartjohnpage stuartjohnpage Apr 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ye, exactly!

In the old code, you'd get a flat list of independent lines, losing the relationship between lines that were part of the same event.

eg:

data: Line 1
data: Line 2

data: Another event

originally would return: ["Line 1", "Line 2", "Another event"]

but now returns: ["Line 1\nLine 2", "Another event"]

The difference is that in the new approach, lines within the same event stay together with their formatting preserved

we have to split on the \n\n (the event delimited). Then we have each event. Then we want to grab the data bits, while preserving the new lines

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah ha! thank you 🙏


HTTPoison.stream_next(res)
{data, res}
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule ProdopsEx.MixProject do
app: :prodops_ex,
description: "An SDK for interacting with the ProdOps API",
license: "MIT",
version: "0.1.0",
version: "0.2.0",
elixir: "~> 1.12",
deps: deps(),
compilers: [:yecc, :leex] ++ Mix.compilers(),
Expand Down
Loading