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
- .create_socket_server(config:) ⇒ Object
-
.send_to_server_socket(content, config:, 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.
31 32 33 |
# File 'lib/ollama_chat/server_socket.rb', line 31 def end |
Class Method Details
.create_socket_server(config:) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/ollama_chat/server_socket.rb', line 22 def create_socket_server(config:) if runtime_dir = config.server_socket_runtime_dir UnixSocks::Server.new(socket_name: 'ollama_chat.sock', runtime_dir:) else UnixSocks::Server.new(socket_name: 'ollama_chat.sock') end end |
.send_to_server_socket(content, config:, type: :socket_input) ⇒ String, NilClass
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, config:, type: :socket_input) server = create_socket_server(config:) = { 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.
43 44 45 46 47 48 49 |
# File 'lib/ollama_chat/server_socket.rb', line 43 def init_server_socket server = OllamaChat::ServerSocket.create_socket_server(config:) server.receive_in_background do || self. = Process.kill :INT, $$ end end |