Skip to content
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

Prompt request refactor #31

Merged
merged 4 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/constants/websockets_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class MessageTypeEnum(str, Enum):
PROMPT_REQUEST = "prompt_request"
OPTIONS_REQUEST = "options_request"
MESSAGE_REQUEST = "message_request"
FILE_UPLOAD_REQUEST = "file_upload_request"
PROMPT_RESPONSE = "prompt_response"
TEST_UPDATE = "test_update"
TIME_OUT_NOTIFICATION = "time_out_notification"
Expand Down
30 changes: 16 additions & 14 deletions app/user_prompt_support/prompt_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,45 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
from enum import Enum
from typing import Dict, Optional

from pydantic import BaseModel

default_timeout_s = 60 # Seconds

from app.constants.websockets_constants import MessageTypeEnum

class PromptRequestType(str, Enum):
BASE = "base"
OPTIONS = "options"
TEXT = "text"
FILE = "file"
default_timeout_s = 60 # Seconds


class PromptRequest(BaseModel):
prompt: Optional[str]
timeout: int = default_timeout_s
__type: PromptRequestType = PromptRequestType.BASE

@property
def type(self) -> PromptRequestType:
return self.__type
def messageType(self) -> MessageTypeEnum:
return MessageTypeEnum.INVALID_MESSAGE


class OptionsSelectPromptRequest(PromptRequest):
__type = PromptRequestType.OPTIONS
options: Dict[str, int]

@property
def messageType(self) -> MessageTypeEnum:
return MessageTypeEnum.OPTIONS_REQUEST


class TextInputPromptRequest(PromptRequest):
__type = PromptRequestType.TEXT
placeholder_text: Optional[str]
default_value: Optional[str]
regex_pattern: Optional[str]

@property
def messageType(self) -> MessageTypeEnum:
return MessageTypeEnum.PROMPT_REQUEST


class UploadFilePromptRequest(PromptRequest):
__type = PromptRequestType.FILE
path: str = "api/v1/test_run_execution/file_upload/"

@property
def messageType(self) -> MessageTypeEnum:
return MessageTypeEnum.FILE_UPLOAD_REQUEST
13 changes: 3 additions & 10 deletions app/user_prompt_support/user_prompt_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,9 @@ def __init__(self, prompt: PromptRequest, message_id: int) -> None:
def as_dictionary(self) -> Dict[MessageKeysEnum, Any]:
prompt_dict = self.prompt.dict()
prompt_dict[MESSAGE_ID_KEY] = self.message_id
message_type = MessageTypeEnum.PROMPT_REQUEST

# Check if options exist
if "options" in prompt_dict:
if prompt_dict["options"]:
message_type = MessageTypeEnum.OPTIONS_REQUEST
else:
message_type = MessageTypeEnum.MESSAGE_REQUEST

message_dict = {
MessageKeysEnum.TYPE: message_type,
MessageKeysEnum.TYPE: self.prompt.messageType,
MessageKeysEnum.PAYLOAD: prompt_dict,
}
return message_dict
Expand Down Expand Up @@ -227,4 +220,4 @@ def __prompt_exchange_for_message(
)


user_prompt_manager = UserPromptManager()
user_prompt_manager: UserPromptManager = UserPromptManager()
Loading