-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split the query and history dbus implementations
This will allow us to interact separatedly in dbus for the query and history commands. Having their own implementation, context and etc... This will allow for more control over the next iterations
- Loading branch information
Showing
19 changed files
with
558 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from typing import Optional | ||
|
||
from dasbus.signal import Signal | ||
|
||
from command_line_assistant.config import Config | ||
from command_line_assistant.dbus.structures import Message | ||
|
||
|
||
class BaseContext: | ||
def __init__(self, config: Config) -> None: | ||
self._config = config | ||
|
||
@property | ||
def config(self) -> Config: | ||
"""Return the configuration from this context.""" | ||
return self._config | ||
|
||
|
||
class QueryContext(BaseContext): | ||
"""This is the process context that will handle anything query related""" | ||
|
||
def __init__(self, config: Config) -> None: | ||
self._input_query: Optional[Message] = None | ||
self._query_changed = Signal() | ||
super().__init__(config) | ||
|
||
@property | ||
def query(self) -> Optional[Message]: | ||
"""Make it accessible publicly""" | ||
return self._input_query | ||
|
||
@property | ||
def query_changed(self) -> Signal: | ||
return self._query_changed | ||
|
||
def process_query(self, input_query: Message) -> None: | ||
"""Emit the signal that the query has changed""" | ||
self._input_query = input_query | ||
self._query_changed.emit() | ||
|
||
|
||
class HistoryContext(BaseContext): | ||
"""This is the process context that will handle anything query related""" | ||
|
||
def __init__(self, config: Config) -> None: | ||
super().__init__(config) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from dasbus.server.interface import dbus_interface | ||
from dasbus.server.property import emits_properties_changed | ||
from dasbus.server.template import InterfaceTemplate | ||
from dasbus.typing import Structure | ||
|
||
from command_line_assistant.daemon.http.query import submit | ||
from command_line_assistant.dbus.constants import HISTORY_IDENTIFIER, QUERY_IDENTIFIER | ||
from command_line_assistant.dbus.structures import ( | ||
HistoryEntry, | ||
Message, | ||
) | ||
from command_line_assistant.history import handle_history_read, handle_history_write | ||
|
||
|
||
@dbus_interface(QUERY_IDENTIFIER.interface_name) | ||
class QueryInterface(InterfaceTemplate): | ||
"""The DBus interface of a query.""" | ||
|
||
def connect_signals(self) -> None: | ||
"""Connect the signals.""" | ||
# Watch for property changes based on the query_changed method. | ||
self.watch_property("RetrieveAnswer", self.implementation.query_changed) | ||
|
||
@property | ||
def RetrieveAnswer(self) -> Structure: | ||
"""This method is mainly called by the client to retrieve it's answer.""" | ||
output = Message() | ||
llm_response = submit( | ||
self.implementation.query.message, self.implementation.config | ||
) | ||
print("llm_response", llm_response) | ||
output.message = llm_response | ||
return Message.to_structure(output) | ||
|
||
@emits_properties_changed | ||
def ProcessQuery(self, query: Structure) -> None: | ||
"""Process the given query.""" | ||
self.implementation.process_query(Message.from_structure(query)) | ||
|
||
|
||
@dbus_interface(HISTORY_IDENTIFIER.interface_name) | ||
class HistoryInterface(InterfaceTemplate): | ||
@property | ||
def GetHistory(self) -> Structure: | ||
history = HistoryEntry() | ||
history.entries = handle_history_read(self.implementation.config) | ||
return history.to_structure(history) | ||
|
||
def ClearHistory(self) -> None: | ||
handle_history_write(self.implementation.config.history.file, [], "") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from dasbus.structure import DBusData | ||
from dasbus.typing import Str | ||
|
||
|
||
class Message(DBusData): | ||
"""Base class for message input and output""" | ||
|
||
def __init__(self) -> None: | ||
self._message: Str = "" | ||
super().__init__() | ||
|
||
@property | ||
def message(self) -> Str: | ||
return self._message | ||
|
||
@message.setter | ||
def message(self, value: Str) -> None: | ||
self._message = value | ||
|
||
|
||
class HistoryEntry(DBusData): | ||
def __init__(self) -> None: | ||
self._entries: list[str] = [] | ||
super().__init__() | ||
|
||
@property | ||
def entries(self) -> list[str]: | ||
return self._entries | ||
|
||
@entries.setter | ||
def entries(self, value: list[str]) -> None: | ||
self._entries = value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.