From 4c61b6f9aadfb207ad36efffb907471426b03e35 Mon Sep 17 00:00:00 2001 From: Stu Page Date: Tue, 8 Apr 2025 13:38:11 -0500 Subject: [PATCH 1/3] first changes --- lib/prodops/stream.ex | 12 ++++++--- test_api.exs | 61 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 test_api.exs diff --git a/lib/prodops/stream.ex b/lib/prodops/stream.ex index ce236cb..75a0cd4 100644 --- a/lib/prodops/stream.ex +++ b/lib/prodops/stream.ex @@ -63,9 +63,15 @@ 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(fn line -> String.trim_leading(line, "data: ") end) + |> Enum.join("\n") + end) + |> Enum.filter(fn data -> data != "" end) HTTPoison.stream_next(res) {data, res} diff --git a/test_api.exs b/test_api.exs new file mode 100644 index 0000000..9491812 --- /dev/null +++ b/test_api.exs @@ -0,0 +1,61 @@ +# Simple script to test the ProdopsEx API +# Run with: mix run test_api.exs + +defmodule ProdopsApiTest do + def run do + config = [ + api_key: System.get_env("PRODOPS_API_KEY"), + api_url: System.get_env("PRODOPS_API_URL", "https://app.prodops.ai") + ] + + stream_test(config) + end + + def stream_test(config) do + # Using hardcoded values + artifact_slug = "test_prompt" + prompt_template_id = 1 + project_id = 1 + + # Create a streaming artifact + params = %{ + prompt_template_id: prompt_template_id, + project_id: project_id, + artifact_slug: artifact_slug + } + + # Process the stream and collect all chunks + stream = ProdopsEx.Artifact.stream_create_artifact(params, config) + + try do + # Collect all chunks into a list + chunks = + stream + |> Elixir.Stream.map(fn chunk -> chunk end) + |> Elixir.Enum.to_list() + + # Show number of chunks received + IO.puts("Received #{length(chunks)} chunks") + + # Display each chunk separately with its index + chunks + |> Enum.with_index() + |> Enum.each(fn {chunk, i} -> + IO.puts("\n--- Chunk #{i + 1} ---") + IO.inspect(chunk) + end) + + # Combine all chunks to see if we can reconstruct the complete content + combined = Enum.join(chunks, "") + IO.puts("\n--- Combined Result ---") + IO.puts(combined) + rescue + e -> + IO.puts("Error processing stream:") + IO.inspect(e) + end + end +end + +# Run the tests +ProdopsApiTest.run() From 3142539cf91a7d9acc7ffbcac9e9f41e8b13ca00 Mon Sep 17 00:00:00 2001 From: Stu Page Date: Tue, 8 Apr 2025 14:03:56 -0500 Subject: [PATCH 2/3] removed testing scripts; formating --- lib/prodops/stream.ex | 3 +-- test_api.exs | 61 ------------------------------------------- 2 files changed, 1 insertion(+), 63 deletions(-) delete mode 100644 test_api.exs diff --git a/lib/prodops/stream.ex b/lib/prodops/stream.ex index 75a0cd4..a6dc89e 100644 --- a/lib/prodops/stream.ex +++ b/lib/prodops/stream.ex @@ -68,8 +68,7 @@ defmodule ProdopsEx.Stream do event |> String.split("\n") |> Enum.filter(fn line -> String.starts_with?(line, "data: ") end) - |> Enum.map(fn line -> String.trim_leading(line, "data: ") end) - |> Enum.join("\n") + |> Enum.map_join("\n", fn line -> String.trim_leading(line, "data: ") end) end) |> Enum.filter(fn data -> data != "" end) diff --git a/test_api.exs b/test_api.exs deleted file mode 100644 index 9491812..0000000 --- a/test_api.exs +++ /dev/null @@ -1,61 +0,0 @@ -# Simple script to test the ProdopsEx API -# Run with: mix run test_api.exs - -defmodule ProdopsApiTest do - def run do - config = [ - api_key: System.get_env("PRODOPS_API_KEY"), - api_url: System.get_env("PRODOPS_API_URL", "https://app.prodops.ai") - ] - - stream_test(config) - end - - def stream_test(config) do - # Using hardcoded values - artifact_slug = "test_prompt" - prompt_template_id = 1 - project_id = 1 - - # Create a streaming artifact - params = %{ - prompt_template_id: prompt_template_id, - project_id: project_id, - artifact_slug: artifact_slug - } - - # Process the stream and collect all chunks - stream = ProdopsEx.Artifact.stream_create_artifact(params, config) - - try do - # Collect all chunks into a list - chunks = - stream - |> Elixir.Stream.map(fn chunk -> chunk end) - |> Elixir.Enum.to_list() - - # Show number of chunks received - IO.puts("Received #{length(chunks)} chunks") - - # Display each chunk separately with its index - chunks - |> Enum.with_index() - |> Enum.each(fn {chunk, i} -> - IO.puts("\n--- Chunk #{i + 1} ---") - IO.inspect(chunk) - end) - - # Combine all chunks to see if we can reconstruct the complete content - combined = Enum.join(chunks, "") - IO.puts("\n--- Combined Result ---") - IO.puts(combined) - rescue - e -> - IO.puts("Error processing stream:") - IO.inspect(e) - end - end -end - -# Run the tests -ProdopsApiTest.run() From 9d4146bfb17c292493c621affc3ca7cf183de9fe Mon Sep 17 00:00:00 2001 From: Stu Page Date: Tue, 8 Apr 2025 14:36:50 -0500 Subject: [PATCH 3/3] added release changes --- README.md | 2 +- lib/prodops/config.ex | 2 +- mix.exs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9e9a81b..fe385aa 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/lib/prodops/config.ex b/lib/prodops/config.ex index 6ca6c7a..3fe6a1f 100644 --- a/lib/prodops/config.ex +++ b/lib/prodops/config.ex @@ -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, diff --git a/mix.exs b/mix.exs index ec4d878..5636278 100644 --- a/mix.exs +++ b/mix.exs @@ -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(),