|
104 | 104 | Now share the results! |
105 | 105 | """ |
106 | 106 |
|
| 107 | + |
| 108 | +class ModelNotRecognizedException(Exception): |
| 109 | + """Exception raised for unrecognized models.""" |
| 110 | + |
| 111 | + def __init__(self, model, message="Model not recognized"): |
| 112 | + self.model = model |
| 113 | + self.message = message |
| 114 | + super().__init__(self.message) |
| 115 | + |
| 116 | + def __str__(self): |
| 117 | + return f"{self.model} -> {self.message}" |
| 118 | + |
| 119 | + |
107 | 120 | # Define style |
108 | 121 | style = PromptStyle.from_dict( |
109 | 122 | { |
|
125 | 138 | # Standard yellow text |
126 | 139 | ANSI_YELLOW = "\033[33m" |
127 | 140 |
|
| 141 | +ANSI_RED = "\033[31m" |
| 142 | + |
128 | 143 | # Bright magenta text |
129 | 144 | ANSI_BRIGHT_MAGENTA = "\033[95m" |
130 | 145 |
|
131 | 146 |
|
132 | | -def main(model="gpt-4-vision-preview"): |
| 147 | +def main(model): |
133 | 148 | """ |
134 | 149 | Main function for the Self-Operating Computer |
135 | 150 | """ |
| 151 | + |
136 | 152 | message_dialog( |
137 | 153 | title="Self-Operating Computer", |
138 | 154 | text="Ask a computer to do anything.", |
@@ -161,7 +177,21 @@ def main(model="gpt-4-vision-preview"): |
161 | 177 | while looping: |
162 | 178 | if DEBUG: |
163 | 179 | print("[loop] messages before next action:\n\n\n", messages[1:]) |
164 | | - response = get_next_action(messages, objective) |
| 180 | + try: |
| 181 | + response = get_next_action(model, messages, objective) |
| 182 | + |
| 183 | + except ModelNotRecognizedException as e: |
| 184 | + print( |
| 185 | + f"{ANSI_GREEN}[Self-Operating Computer]{ANSI_RED} error: {e} {ANSI_RESET}" |
| 186 | + ) |
| 187 | + looping = False |
| 188 | + break |
| 189 | + except Exception as e: |
| 190 | + print( |
| 191 | + f"{ANSI_GREEN}[Self-Operating Computer]{ANSI_RED} error: {e} {ANSI_RESET}" |
| 192 | + ) |
| 193 | + looping = False |
| 194 | + break |
165 | 195 |
|
166 | 196 | action = parse_oai_response(response) |
167 | 197 | action_type = action.get("type") |
@@ -227,7 +257,17 @@ def format_vision_prompt(objective): |
227 | 257 | return prompt |
228 | 258 |
|
229 | 259 |
|
230 | | -def get_next_action(messages, objective): |
| 260 | +def get_next_action(model, messages, objective): |
| 261 | + if model == "gpt-4-vision-preview": |
| 262 | + content = get_next_action_from_oai(messages, objective) |
| 263 | + return content |
| 264 | + elif model == "agent-1": |
| 265 | + return "coming soon" |
| 266 | + |
| 267 | + raise ModelNotRecognizedException(model) |
| 268 | + |
| 269 | + |
| 270 | +def get_next_action_from_oai(messages, objective): |
231 | 271 | """ |
232 | 272 | Get the next action for Self-Operating Computer |
233 | 273 | """ |
@@ -515,16 +555,16 @@ def convert_percent_to_decimal(percent_str): |
515 | 555 |
|
516 | 556 |
|
517 | 557 | if __name__ == "__main__": |
518 | | - # parser = argparse.ArgumentParser( |
519 | | - # description="Run the self-operating-computer with a specified model." |
520 | | - # ) |
521 | | - # parser.add_argument( |
522 | | - # "-m", |
523 | | - # "--model", |
524 | | - # help="Specify the model to use", |
525 | | - # required=False, |
526 | | - # default="default-model", |
527 | | - # ) |
528 | | - |
529 | | - # args = parser.parse_args() |
530 | | - main() |
| 558 | + parser = argparse.ArgumentParser( |
| 559 | + description="Run the self-operating-computer with a specified model." |
| 560 | + ) |
| 561 | + parser.add_argument( |
| 562 | + "-m", |
| 563 | + "--model", |
| 564 | + help="Specify the model to use", |
| 565 | + required=False, |
| 566 | + default="gpt-4-vision-preview", |
| 567 | + ) |
| 568 | + |
| 569 | + args = parser.parse_args() |
| 570 | + main(args.model) |
0 commit comments