Current section
Files
Jump to
Current section
Files
lib/snakebridge_generated/dspy/streaming/streamify/__init__.ex
# Generated by SnakeBridge v0.12.0 - DO NOT EDIT MANUALLY
# Regenerate with: mix compile
# Library: dspy 3.1.2
# Python module: dspy.streaming.streamify
defmodule Dspy.Streaming.Streamify do
@moduledoc """
Submodule bindings for `dspy.streaming.streamify`.
"""
def __snakebridge_python_name__, do: "dspy.streaming.streamify"
def __snakebridge_library__, do: "dspy"
@doc """
Convert the async streaming generator to a sync generator.
Parameters:
- `async_generator` (term())
Returns:
- `term()`
"""
@spec apply_sync_streaming(term(), keyword()) :: {:ok, term()} | {:error, Snakepit.Error.t()}
def apply_sync_streaming(async_generator, opts \\ []) do
SnakeBridge.Runtime.call(__MODULE__, :apply_sync_streaming, [async_generator], opts)
end
@doc """
Wrap a DSPy program so that it streams its outputs incrementally, rather than returning them
all at once. It also provides status messages to the user to indicate the progress of the program, and users
can implement their own status message provider to customize the status messages and what module to generate
status messages for.
## Parameters
- `program` - The DSPy program to wrap with streaming functionality.
- `status_message_provider` - A custom status message generator to use instead of the default one. Users can implement their own status message generator to customize the status messages and what module to generate status messages for.
- `stream_listeners` - A list of stream listeners to capture the streaming output of specific fields of sub predicts in the program. When provided, only the target fields in the target predict will be streamed to the user.
- `include_final_prediction_in_output_stream` - Whether to include the final prediction in the output stream, only useful when `stream_listeners` is provided. If `False`, the final prediction will not be included in the output stream. When the program hit cache, or no listeners captured anything, the final prediction will still be included in the output stream even if this is `False`.
- `is_async_program` - Whether the program is async. If `False`, the program will be wrapped with `asyncify`, otherwise the program will be called with `acall`.
- `async_streaming` - Whether to return an async generator or a sync generator. If `False`, the streaming will be converted to a sync generator.
Parameters:
- `program` (term())
- `status_message_provider` (term() default: None)
- `stream_listeners` (term() default: None)
- `include_final_prediction_in_output_stream` (boolean() default: True)
- `is_async_program` (boolean() default: False)
- `async_streaming` (boolean() default: True)
Returns:
- `term()`
"""
@spec streamify(term()) :: {:ok, term()} | {:error, Snakepit.Error.t()}
@spec streamify(term(), keyword()) :: {:ok, term()} | {:error, Snakepit.Error.t()}
@spec streamify(term(), term()) :: {:ok, term()} | {:error, Snakepit.Error.t()}
@spec streamify(term(), term(), keyword()) :: {:ok, term()} | {:error, Snakepit.Error.t()}
@spec streamify(term(), term(), term()) :: {:ok, term()} | {:error, Snakepit.Error.t()}
@spec streamify(term(), term(), term(), keyword()) ::
{:ok, term()} | {:error, Snakepit.Error.t()}
@spec streamify(term(), term(), term(), boolean()) ::
{:ok, term()} | {:error, Snakepit.Error.t()}
@spec streamify(term(), term(), term(), boolean(), keyword()) ::
{:ok, term()} | {:error, Snakepit.Error.t()}
@spec streamify(term(), term(), term(), boolean(), boolean()) ::
{:ok, term()} | {:error, Snakepit.Error.t()}
@spec streamify(term(), term(), term(), boolean(), boolean(), keyword()) ::
{:ok, term()} | {:error, Snakepit.Error.t()}
@spec streamify(term(), term(), term(), boolean(), boolean(), boolean()) ::
{:ok, term()} | {:error, Snakepit.Error.t()}
@spec streamify(term(), term(), term(), boolean(), boolean(), boolean(), keyword()) ::
{:ok, term()} | {:error, Snakepit.Error.t()}
def streamify(program) do
SnakeBridge.Runtime.call(__MODULE__, :streamify, [program], [])
end
def streamify(program, opts)
when is_list(opts) and
(opts == [] or
(is_tuple(hd(opts)) and tuple_size(hd(opts)) == 2 and is_atom(elem(hd(opts), 0)))) do
SnakeBridge.Runtime.call(__MODULE__, :streamify, [program], opts)
end
def streamify(program, status_message_provider) do
SnakeBridge.Runtime.call(__MODULE__, :streamify, [program, status_message_provider], [])
end
def streamify(program, status_message_provider, opts)
when is_list(opts) and
(opts == [] or
(is_tuple(hd(opts)) and tuple_size(hd(opts)) == 2 and is_atom(elem(hd(opts), 0)))) do
SnakeBridge.Runtime.call(__MODULE__, :streamify, [program, status_message_provider], opts)
end
def streamify(program, status_message_provider, stream_listeners) do
SnakeBridge.Runtime.call(
__MODULE__,
:streamify,
[program, status_message_provider, stream_listeners],
[]
)
end
def streamify(program, status_message_provider, stream_listeners, opts)
when is_list(opts) and
(opts == [] or
(is_tuple(hd(opts)) and tuple_size(hd(opts)) == 2 and is_atom(elem(hd(opts), 0)))) do
SnakeBridge.Runtime.call(
__MODULE__,
:streamify,
[program, status_message_provider, stream_listeners],
opts
)
end
def streamify(
program,
status_message_provider,
stream_listeners,
include_final_prediction_in_output_stream
) do
SnakeBridge.Runtime.call(
__MODULE__,
:streamify,
[
program,
status_message_provider,
stream_listeners,
include_final_prediction_in_output_stream
],
[]
)
end
def streamify(
program,
status_message_provider,
stream_listeners,
include_final_prediction_in_output_stream,
opts
)
when is_list(opts) and
(opts == [] or
(is_tuple(hd(opts)) and tuple_size(hd(opts)) == 2 and is_atom(elem(hd(opts), 0)))) do
SnakeBridge.Runtime.call(
__MODULE__,
:streamify,
[
program,
status_message_provider,
stream_listeners,
include_final_prediction_in_output_stream
],
opts
)
end
def streamify(
program,
status_message_provider,
stream_listeners,
include_final_prediction_in_output_stream,
is_async_program
) do
SnakeBridge.Runtime.call(
__MODULE__,
:streamify,
[
program,
status_message_provider,
stream_listeners,
include_final_prediction_in_output_stream,
is_async_program
],
[]
)
end
def streamify(
program,
status_message_provider,
stream_listeners,
include_final_prediction_in_output_stream,
is_async_program,
opts
)
when is_list(opts) and
(opts == [] or
(is_tuple(hd(opts)) and tuple_size(hd(opts)) == 2 and is_atom(elem(hd(opts), 0)))) do
SnakeBridge.Runtime.call(
__MODULE__,
:streamify,
[
program,
status_message_provider,
stream_listeners,
include_final_prediction_in_output_stream,
is_async_program
],
opts
)
end
def streamify(
program,
status_message_provider,
stream_listeners,
include_final_prediction_in_output_stream,
is_async_program,
async_streaming
) do
SnakeBridge.Runtime.call(
__MODULE__,
:streamify,
[
program,
status_message_provider,
stream_listeners,
include_final_prediction_in_output_stream,
is_async_program,
async_streaming
],
[]
)
end
def streamify(
program,
status_message_provider,
stream_listeners,
include_final_prediction_in_output_stream,
is_async_program,
async_streaming,
opts
)
when is_list(opts) and
(opts == [] or
(is_tuple(hd(opts)) and tuple_size(hd(opts)) == 2 and is_atom(elem(hd(opts), 0)))) do
SnakeBridge.Runtime.call(
__MODULE__,
:streamify,
[
program,
status_message_provider,
stream_listeners,
include_final_prediction_in_output_stream,
is_async_program,
async_streaming
],
opts
)
end
@doc """
Convert a DSPy program output stream to an OpenAI-compatible output stream that can be
used by a service as an API response to a streaming request.
## Parameters
- `streamer` - An async generator that yields values from a DSPy program output stream.
Parameters:
- `streamer` (term())
Returns:
- `term()`
"""
@spec streaming_response(term(), keyword()) :: {:ok, term()} | {:error, Snakepit.Error.t()}
def streaming_response(streamer, opts \\ []) do
SnakeBridge.Runtime.call(__MODULE__, :streaming_response, [streamer], opts)
end
end