-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from roseflow-ai/omnes
Adds event bus, support for streaming events and API usage.
- Loading branch information
Showing
19 changed files
with
472 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
module Roseflow | ||
module Action | ||
# This module is used to define the CLI interface for an interaction | ||
module WithEvents | ||
def self.extended(base_class) | ||
base_class.extend ClassMethods | ||
end | ||
|
||
module ClassMethods | ||
def bus=(bus) | ||
@bus = bus | ||
end | ||
|
||
def bus | ||
@bus ||= Registry.get(:events) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
module Roseflow | ||
module AI | ||
module Models | ||
class Configuration < Anyway::Config | ||
config_name :ai_model | ||
|
||
attr_config :name | ||
attr_config instrumentation: false | ||
attr_config temperature: 1.0 | ||
attr_config top_p: 1.0 | ||
attr_config n: 1 | ||
attr_config stream: false | ||
attr_config stream_events: false | ||
attr_config stop: nil | ||
attr_config max_tokens: 2048 | ||
attr_config presence_penalty: 0.0 | ||
attr_config frequency_penalty: 0.0 | ||
attr_config user: nil | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
require "omnes" | ||
|
||
module Roseflow | ||
class EventBus | ||
include Omnes | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
module Roseflow | ||
module Events | ||
end | ||
end | ||
|
||
require "roseflow/events/model/streaming_event" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
require "omnes" | ||
|
||
module Roseflow | ||
module Events | ||
module Model | ||
class StreamingEvent | ||
include Omnes::Event | ||
|
||
attr_reader :body, :stream_id | ||
|
||
def initialize(body:, stream_id:) | ||
@body = body | ||
@stream_id = stream_id | ||
end | ||
|
||
def omnes_event_name | ||
:model_streaming_event | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
require "omnes" | ||
|
||
module Roseflow | ||
module Events | ||
class ModelEvent | ||
include Omnes::Event | ||
|
||
def initialize(model:, provider:, data:) | ||
@model = model.name | ||
@provider = provider.name | ||
@data = data | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
require "roseflow/event_bus" | ||
|
||
module Roseflow | ||
RSpec.describe EventBus do | ||
subject { described_class.new } | ||
|
||
it "does not share buses between instances" do | ||
klass = described_class.new | ||
|
||
expect(klass.omnes_bus).not_to be(subject.omnes_bus) | ||
end | ||
|
||
describe "events" do | ||
describe "from actions" do | ||
before do | ||
Registry.get(:events).register(:action_event) | ||
end | ||
|
||
let(:action) { TestDoubles::EventedAction.execute } | ||
let(:subscriber) { TestDoubles::ActionEventSubscriber.new } | ||
|
||
it "receives events from actions" do | ||
expect(subscriber).to receive(:handler) | ||
subscriber.subscribe_to(Registry.get(:events)) | ||
expect(action).to be_success | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.