Utility Modules
Annotation Utils
src.worksheets.annotation_utils
Utility functions for handling Genie worksheet annotations and context management.
This module provides utilities for managing and formatting Genie worksheet annotations, handling different types of answers, and preparing context for semantic parsing and dialogue interactions.
Functions
handle_genie_type
handle_genie_type(key, value, context, response_generator)
Processes a Genie type value and generates its schema representation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str
|
The key/name of the Genie type value. |
required |
value
|
Union[GenieType, Answer, GenieWorksheet]
|
The value to process. |
required |
context
|
The context object containing variable information. |
required | |
response_generator
|
bool
|
Flag indicating whether to include response generation info. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
The schema representation of the Genie type value, or None if not applicable. |
Source code in src/worksheets/annotation_utils.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
|
get_context_schema
get_context_schema(context, response_generator=False)
Generates a schema representation of the given context.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
context
|
The context object containing variables and their values. |
required | |
response_generator
|
bool
|
Flag to include response generation info. Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
str |
A string representation of the context schema with escaped backslashes removed. |
Source code in src/worksheets/annotation_utils.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
|
get_agent_action_schemas
get_agent_action_schemas(agent_acts, *args, **kwargs)
Converts agent actions into their schema representations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent_acts
|
List of agent actions to convert. |
required | |
*args
|
Variable length argument list. |
()
|
|
**kwargs
|
Arbitrary keyword arguments. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
list |
List of string representations of agent actions. |
Source code in src/worksheets/annotation_utils.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
|
prepare_context_input
prepare_context_input(bot, dlg_history, current_dlg_turn)
Prepares context input for dialogue processing.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bot
|
The bot instance containing context and configuration. |
required | |
dlg_history
|
List of previous dialogue turns. |
required | |
current_dlg_turn
|
The current dialogue turn being processed. |
required |
Returns:
Name | Type | Description |
---|---|---|
tuple |
A tuple containing (state_schema, agent_acts, agent_utterance). |
Source code in src/worksheets/annotation_utils.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
|
prepare_semantic_parser_input
prepare_semantic_parser_input(bot, dlg_history, current_dlg_turn)
Prepares input for semantic parsing by gathering necessary context and schemas.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bot
|
The bot instance containing worksheets and database models. |
required | |
dlg_history
|
List of previous dialogue turns. |
required | |
current_dlg_turn
|
The current dialogue turn being processed. |
required |
Returns:
Name | Type | Description |
---|---|---|
tuple |
A tuple containing (state_schema, agent_acts, agent_utterance, available_worksheets_text, available_dbs_text). |
Source code in src/worksheets/annotation_utils.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
|
Utils
src.worksheets.utils
Functions
callable_name
callable_name(any_callable)
Source code in src/worksheets/utils.py
7 8 9 10 11 12 13 14 |
|
deep_compare_lists
deep_compare_lists(list1, list2)
Source code in src/worksheets/utils.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
|
generate_var_name
generate_var_name(name)
Source code in src/worksheets/utils.py
38 39 40 41 42 |
|
camel_to_snake
camel_to_snake(name)
Source code in src/worksheets/utils.py
45 46 47 |
|
extract_code_block_from_output
extract_code_block_from_output(output: str, lang='python')
Source code in src/worksheets/utils.py
50 51 52 53 54 55 56 57 58 |
|
num_tokens_from_string
num_tokens_from_string(string: str, model: str = 'gpt-3.5-turbo') -> int
Returns the number of tokens in a text string.
Source code in src/worksheets/utils.py
61 62 63 64 65 |
|
Interface Utils
src.worksheets.interface_utils
Classes
bcolors
Source code in src/worksheets/interface_utils.py
33 34 35 36 37 38 39 40 41 42 |
|
Attributes
HEADER
class-attribute
instance-attribute
HEADER = '\x1b[95m'
OKBLUE
class-attribute
instance-attribute
OKBLUE = '\x1b[94m'
OKCYAN
class-attribute
instance-attribute
OKCYAN = '\x1b[96m'
OKGREEN
class-attribute
instance-attribute
OKGREEN = '\x1b[92m'
WARNING
class-attribute
instance-attribute
WARNING = '\x1b[93m'
FAIL
class-attribute
instance-attribute
FAIL = '\x1b[91m'
ENDC
class-attribute
instance-attribute
ENDC = '\x1b[0m'
BOLD
class-attribute
instance-attribute
BOLD = '\x1b[1m'
UNDERLINE
class-attribute
instance-attribute
UNDERLINE = '\x1b[4m'
Functions
convert_to_json
convert_to_json(dialogue: list[CurrentDialogueTurn])
Convert the dialogue history to a JSON-compatible format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dialogue
|
list[CurrentDialogueTurn]
|
The dialogue history. |
required |
Returns:
Type | Description |
---|---|
list[dict]: The dialogue history in JSON format. |
Source code in src/worksheets/interface_utils.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
|
input_user
input_user() -> str
Prompt the user for input and return the input string.
Source code in src/worksheets/interface_utils.py
45 46 47 48 49 50 51 52 53 54 |
|
print_chatbot
print_chatbot(s: str)
Print the chatbot's response in a formatted way.
Source code in src/worksheets/interface_utils.py
57 58 59 |
|
print_user
print_user(s: str)
Print the user's utterance in a formatted way.
Source code in src/worksheets/interface_utils.py
62 63 64 |
|
print_complete_history
print_complete_history(dialogue_history)
Print the complete dialogue history.
Source code in src/worksheets/interface_utils.py
67 68 69 70 71 |
|
conversation_loop
async
conversation_loop(bot, output_state_path, quit_commands=None)
Run the conversation loop with the chatbot. Dumps the dialogue history to a JSON file upon exit.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bot
|
The chatbot instance. |
required | |
output_state_path
|
str
|
The path to save the dialogue history. |
required |
quit_commands
|
list[str]
|
List of commands to quit the conversation. Defaults to None. |
None
|
Source code in src/worksheets/interface_utils.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
|
GSheet Utils
src.worksheets.gsheet_utils
Attributes
CURR_DIR
module-attribute
CURR_DIR = dirname(realpath(__file__))
SCOPES
module-attribute
SCOPES = ['https://www.googleapis.com/auth/spreadsheets.readonly']
Functions
retrieve_gsheet
retrieve_gsheet(id, range)
Retrieve values from a Google Sheet.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id
|
str
|
The ID of the Google Sheet. |
required |
range
|
str
|
The range of cells to retrieve. |
required |
Returns:
Name | Type | Description |
---|---|---|
List |
A list of values from the specified range in the Google Sheet. |
Source code in src/worksheets/gsheet_utils.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
|
fill_all_empty
fill_all_empty(rows, desired_columns)
Source code in src/worksheets/gsheet_utils.py
43 44 45 46 47 |
|
using_service_account
using_service_account()
Source code in src/worksheets/gsheet_utils.py
50 51 52 53 54 55 56 57 58 59 60 61 62 |
|
Chat
src.worksheets.chat
Functions
generate_next_turn
async
generate_next_turn(user_utterance: str, bot)
Generate the next turn in the dialogue based on the user's utterance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user_utterance
|
str
|
The user's input. |
required |
bot
|
Agent
|
The bot instance handling the dialogue. |
required |
Source code in src/worksheets/chat.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
|