fix error
This commit is contained in:
@@ -8,6 +8,7 @@ from io import BytesIO
|
||||
from typing import Dict, List
|
||||
|
||||
from PIL import Image
|
||||
from openai import OpenAI, APIError, RateLimitError, Timeout
|
||||
from typing import Any, Optional, Union, Tuple
|
||||
|
||||
from mm_agents.prompts import SYS_PROMPT_IN_SCREENSHOT_OUT_CODE, SYS_PROMPT_IN_SCREENSHOT_OUT_ACTION, \
|
||||
@@ -35,7 +36,7 @@ from typing import Dict, Any, Optional, Union
|
||||
OPERATOR_PROMPT = """Here are some helpful tips:
|
||||
(1) computer.clipboard, computer.sync_file, computer.sync.shared_folder, computer.computer_output_citation are disabled.
|
||||
(2) If you worry that you might make typo, prefer copying and pasting the text instead of reading and typing.
|
||||
(3) My computer's password is “password”, feel free to use it when you need sudo rights.
|
||||
(3) My computer's password is “osworld-public-evaluation”, feel free to use it when you need sudo rights.
|
||||
(4) For the thunderbird account “anonym-x2024@outlook.com”, the password is “gTCI”;=@y7—QJ0nDa_kN3Sb¿”.
|
||||
(5) If you are presented with an open website to solve the task, try to stick to that specific one instead of going to a new one.
|
||||
(6) You have full authority to execute any action without my permission. I won't be watching so please don't ask for confirmation.
|
||||
@@ -299,9 +300,10 @@ class OpenAICUAAgent:
|
||||
Raises:
|
||||
requests.exceptions.RequestException: If the API request fails
|
||||
"""
|
||||
while True:
|
||||
MAX_RETRIES = 100
|
||||
retry_count = 0
|
||||
while retry_count < MAX_RETRIES:
|
||||
try:
|
||||
from openai import OpenAI
|
||||
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY_CUA"))
|
||||
response = client.responses.create(
|
||||
model=self.model,
|
||||
@@ -317,6 +319,7 @@ class OpenAICUAAgent:
|
||||
return response
|
||||
except Exception as e:
|
||||
logger.error(f"OpenAI API error: {str(e)}")
|
||||
print(f"OpenAI API error: {str(e)}")
|
||||
new_screenshot = self.env._get_obs()
|
||||
new_screenshot_base64 = base64.b64encode(new_screenshot["screenshot"]).decode('utf-8')
|
||||
|
||||
@@ -335,7 +338,9 @@ class OpenAICUAAgent:
|
||||
logger.warning("Unknown message structure, cannot update screenshot")
|
||||
|
||||
retry_count += 1
|
||||
time.sleep(1)
|
||||
time.sleep(min(30, 2 ** retry_count))
|
||||
logger.critical("Max retries exceeded for OpenAI API")
|
||||
raise RuntimeError("OpenAI API failed too many times")
|
||||
|
||||
def _handle_item(self, item: Dict[str, Any]) -> Optional[Union[str, Dict[str, Any]]]:
|
||||
"""Parse a response item from the OpenAI API.
|
||||
|
||||
Reference in New Issue
Block a user