Class: Tep::Llm::OpenAI::ChatCompletionsStreamer
- Defined in:
- lib/tep/openai_server.rb
Overview
Runs one streaming chat completion. Subclass of Tep::Streamer. Drives backend.chat_completion_stream through ChatStreamSink, writes the terminating data:, then emits the toy/v1 serving event (kind:eval, phase:serve, name:request) with sink.completion_count (mirrors CompletionsStreamer’s #128 shape).
Instance Attribute Summary collapse
-
#model ⇒ Object
Returns the value of attribute model.
-
#principal_id ⇒ Object
Returns the value of attribute principal_id.
-
#prompt_tokens ⇒ Object
Returns the value of attribute prompt_tokens.
-
#req_ref ⇒ Object
Returns the value of attribute req_ref.
-
#request_id ⇒ Object
Returns the value of attribute request_id.
-
#t0 ⇒ Object
Returns the value of attribute t0.
Instance Method Summary collapse
-
#initialize ⇒ ChatCompletionsStreamer
constructor
A new instance of ChatCompletionsStreamer.
- #pump(out) ⇒ Object
Constructor Details
#initialize ⇒ ChatCompletionsStreamer
Returns a new instance of ChatCompletionsStreamer.
443 444 445 446 447 448 449 450 |
# File 'lib/tep/openai_server.rb', line 443 def initialize @req_ref = Tep::Request.new @model = "" @prompt_tokens = 0 @t0 = 0 @request_id = "" @principal_id = "" end |
Instance Attribute Details
#model ⇒ Object
Returns the value of attribute model.
440 441 442 |
# File 'lib/tep/openai_server.rb', line 440 def model @model end |
#principal_id ⇒ Object
Returns the value of attribute principal_id.
441 442 443 |
# File 'lib/tep/openai_server.rb', line 441 def principal_id @principal_id end |
#prompt_tokens ⇒ Object
Returns the value of attribute prompt_tokens.
440 441 442 |
# File 'lib/tep/openai_server.rb', line 440 def prompt_tokens @prompt_tokens end |
#req_ref ⇒ Object
Returns the value of attribute req_ref.
440 441 442 |
# File 'lib/tep/openai_server.rb', line 440 def req_ref @req_ref end |
#request_id ⇒ Object
Returns the value of attribute request_id.
441 442 443 |
# File 'lib/tep/openai_server.rb', line 441 def request_id @request_id end |
#t0 ⇒ Object
Returns the value of attribute t0.
441 442 443 |
# File 'lib/tep/openai_server.rb', line 441 def t0 @t0 end |
Instance Method Details
#pump(out) ⇒ Object
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 |
# File 'lib/tep/openai_server.rb', line 452 def pump(out) sink = Tep::Llm::OpenAI::ChatStreamSink.new sink.out = out sink.model = @model sink.emit_role_prelude("assistant") Tep::APP.openai_backend.chat_completion_stream(@req_ref, sink) sink.emit_finish("stop") out.write("data: [DONE]\n\n") wall_us = (Time.now.to_i - @t0) * 1_000_000 extra = "{" + Tep::Json.encode_pair_str("request_id", @request_id) + "," + Tep::Json.encode_pair_str("principal_id", @principal_id) + "}" Tep::APP.openai_events.inference( @model, @prompt_tokens, sink.completion_count, wall_us, extra) 0 end |