Module: OllamaChat::ServerSocket
- Included in:
- Chat
- Defined in:
- lib/ollama_chat/server_socket.rb
Instance Attribute Summary collapse
-
#server_socket_message ⇒ Object
Returns the value of attribute server_socket_message.
Class Method Summary collapse
-
.send_to_server_socket(content, type: :socket_input) ⇒ String, NilClass
The response from the server if type is :socket_input_with_response, otherwise nil.
Instance Method Summary collapse
-
#init_server_socket ⇒ nil
Initializes the server socket to receive messages from the Ollama Chat Client.
Instance Attribute Details
#server_socket_message ⇒ Object
Returns the value of attribute server_socket_message.
23 24 25 |
# File 'lib/ollama_chat/server_socket.rb', line 23 def @server_socket_message end |
Class Method Details
.send_to_server_socket(content, type: :socket_input) ⇒ String, NilClass
Returns the response from the server if type is :socket_input_with_response, otherwise nil.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/ollama_chat/server_socket.rb', line 11 def send_to_server_socket(content, type: :socket_input) server = UnixSocks::Server.new(socket_name: 'ollama_chat.sock') = { content:, type: } if type.to_sym == :socket_input_with_response return server.transmit_with_response() else server.transmit() nil end end |
Instance Method Details
#init_server_socket ⇒ nil
Initializes the server socket to receive messages from the Ollama Chat Client.
This method sets up a Unix domain socket server that listens for incoming messages in the background. When a message is received, it updates the instance variable ‘server_socket_message` and sends an interrupt signal to the current process in order to handle the message.
server socket and kills the process when a message is received.
35 36 37 38 39 40 41 |
# File 'lib/ollama_chat/server_socket.rb', line 35 def init_server_socket server = UnixSocks::Server.new(socket_name: 'ollama_chat.sock') server.receive_in_background do || self. = Process.kill :INT, $$ end end |