-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Implement streaming completions #32
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a couple of comments
lib/llm/response/chunk.rb
Outdated
# frozen_string_literal: true | ||
|
||
module LLM | ||
class Response::Chunk < Response |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we inherit from Response::Completion
? It is still a Completion response, right ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It certainly is, I was thinking about it, but got a little hesitant.
@@ -30,8 +30,18 @@ def complete(message, **params) | |||
params = DEFAULT_PARAMS.merge(params) | |||
body = {messages: messages.map(&:to_h)}.merge!(params) | |||
req = preflight(req, body) | |||
res = request(@http, req) | |||
Response::Completion.new(res.body, self).extend(response_parser) | |||
if params[:stream] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could offload the complexity to another method
stream!(req, body) if params[:stream]
stream_completion!(req, body) if params[:stream]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@0x1eef I'm still not sure about we go about this
lib/llm/response/chunk.rb
Outdated
# frozen_string_literal: true | ||
|
||
module LLM | ||
require_relative "completion" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move this to lib/llm/response.rb
instead ? The require_relative
statements found in that file are properly ordered. For example, it could be like this and the dependencies should be properly met:
require "json"
require_relative "response/completion"
require_relative "response/chunk"
require_relative "response/embedding"
Changes
Chunk
response to represent a streamed completion chunkExamples