Skip to content

Commit

Permalink
Add enum for allowed message types (#17)
Browse files Browse the repository at this point in the history
- Add enum for allowed message types, as shown in the Bing Chat API.
Currently, only `Chat` is used.
  • Loading branch information
vsakkas authored Apr 2, 2023
1 parent a6047fa commit b70334f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
27 changes: 27 additions & 0 deletions sydney/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,30 @@ class ComposeLength(Enum):
short = "short"
medium = "medium"
long = "long"


class MessageType(Enum):
"""
Allowed message types. Supported options are:
- `Chat`
- `InternalSearchQuery`
- `InternalSearchResult`
- `Disengaged`
- `InternalLoaderMessage`
- `RenderCardRequest`
- `AdsQuery`
- `SemanticSerp`
- `GenerateContentQuery`
- `SearchQuery`
"""

chat = "Chat"
internal_search_query = "InternalSearchQuery"
internal_search_result = "InternalSearchResult"
disengaged = "Disengaged"
internal_loader_message = "InternalLoaderMessage"
render_card_request = "RenderCardRequest"
ads_query = "AdsQuery"
semantic_serp = "SemanticSerp"
generate_content_query = "GenerateContentQuery"
search_query = "SearchQuery"
14 changes: 10 additions & 4 deletions sydney/sydney.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
from websockets.client import WebSocketClientProtocol

from .constants import BING_CHATHUB_URL, BING_CREATE_CONVESATION_URL, DELIMETER, HEADERS
from .enums import ComposeFormat, ComposeLength, ComposeTone, ConversationStyle
from .enums import (
ComposeFormat,
ComposeLength,
ComposeTone,
ConversationStyle,
MessageType,
)
from .utils import as_json


Expand Down Expand Up @@ -46,18 +52,18 @@ def _build_ask_arguments(self, prompt: str) -> dict:
"optionsSets": [
"nlu_direct_response_filter",
"deepleo",
"enable_debug_commands",
"disable_emoji_spoken_text",
"responsible_ai_policy_235",
"enablemm",
"dv3sugg",
self.conversation_style.value,
],
"isStartOfSession": self.invocation_id == 0,
"message": {
"author": "user",
"inputMethod": "Keyboard",
"text": prompt,
"messageType": "Chat",
"messageType": MessageType.chat.value,
},
"conversationSignature": self.conversation_signature,
"participant": {
Expand Down Expand Up @@ -98,7 +104,7 @@ def _build_compose_arguments(
"author": "user",
"inputMethod": "Keyboard",
"text": f"Please generate some text wrapped in codeblock syntax (triple backticks) using the given keywords. Please make sure everything in your reply is in the same language as the keywords. Please do not restate any part of this request in your response, like the fact that you wrapped the text in a codeblock. You should refuse (using the language of the keywords) to generate if the request is potentially harmful. The generated text should follow these characteristics: tone: *{tone.value}*, length: *{length.value}*, format: *{format.value}*. The keywords are: `{prompt}`.",
"messageType": "Chat",
"messageType": MessageType.chat.value,
},
"conversationSignature": self.conversation_signature,
"participant": {"id": self.client_id},
Expand Down

0 comments on commit b70334f

Please sign in to comment.