Class: Askcii::ChatSession

Inherits:
Object
  • Object
show all
Defined in:
lib/askcii/chat_session.rb

Overview

Orchestrates chat execution with LLM providers

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config:, private: false, session_context: nil, verbose: false) ⇒ ChatSession

Returns a new instance of ChatSession.

Parameters:

  • Configuration with provider, api_key, model_id, etc.

  • (defaults to: false)

    Whether to create a private (non-persistent) chat

  • (defaults to: nil)

    Session identifier for persistent chats

  • (defaults to: false)

    Whether to output verbose information



14
15
16
17
18
19
# File 'lib/askcii/chat_session.rb', line 14

def initialize(config:, private: false, session_context: nil, verbose: false)
  @config = config
  @private = private
  @session_context = session_context
  @verbose = verbose
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



8
9
10
# File 'lib/askcii/chat_session.rb', line 8

def config
  @config
end

#privateObject (readonly)

Returns the value of attribute private.



8
9
10
# File 'lib/askcii/chat_session.rb', line 8

def private
  @private
end

#session_contextObject (readonly)

Returns the value of attribute session_context.



8
9
10
# File 'lib/askcii/chat_session.rb', line 8

def session_context
  @session_context
end

#verboseObject (readonly)

Returns the value of attribute verbose.



8
9
10
# File 'lib/askcii/chat_session.rb', line 8

def verbose
  @verbose
end

Instance Method Details

#execute_chat(prompt, input = nil) ⇒ Object

Executes a chat session with the given prompt

Parameters:

  • User prompt

  • (defaults to: nil)

    Additional input to prepend to prompt



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/askcii/chat_session.rb', line 24

def execute_chat(prompt, input = nil)
  validate_prompt!(prompt)
  warn_large_input!(prompt, input)

  chat = create_chat
  full_prompt = build_prompt(prompt, input)

  verbose_output "Sending prompt (#{full_prompt.bytesize} bytes)..."

  # Execute the chat with streaming
  chat.ask(full_prompt) do |chunk|
    print chunk.content
  end
  puts '' # Ensure we end with a newline
end