mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-17 15:35:21 +02:00
openai ratelimit retry
This commit is contained in:
parent
6ebe8efc63
commit
5c47fc5361
3 changed files with 27 additions and 13 deletions
|
|
@ -393,7 +393,10 @@ class GenActionDetails(STAction):
|
|||
act_sector = GenActionSector().run(role, access_tile, act_desp)
|
||||
act_arena = GenActionArena().run(role, act_desp, act_world, act_sector)
|
||||
act_address = f"{act_world}:{act_sector}:{act_arena}"
|
||||
act_game_object = GenActionObject().run(role, act_desp, act_address)
|
||||
if not role.s_mem.get_str_accessible_arena_game_objects(act_address):
|
||||
act_game_object = "<random>"
|
||||
else:
|
||||
act_game_object = GenActionObject().run(role, act_desp, act_address)
|
||||
new_address = f"{act_world}:{act_sector}:{act_arena}:{act_game_object}"
|
||||
act_pron = GenPronunciatio().run(role, act_desp)
|
||||
act_event = GenEventTriple().run(role, act_desp)
|
||||
|
|
|
|||
|
|
@ -73,18 +73,22 @@ class STAction(Action):
|
|||
"""
|
||||
assert model_name in ["gpt-3.5-turbo-instruct", "text-davinci-002", "text-davinci-003"]
|
||||
for idx in range(retry):
|
||||
tmp_model_name = self.llm.model
|
||||
tmp_max_tokens_rsp = CONFIG.max_tokens_rsp
|
||||
CONFIG.max_tokens_rsp = max_tokens
|
||||
self.llm.model = model_name
|
||||
try:
|
||||
tmp_model_name = self.llm.model
|
||||
tmp_max_tokens_rsp = CONFIG.max_tokens_rsp
|
||||
CONFIG.max_tokens_rsp = max_tokens
|
||||
self.llm.model = model_name
|
||||
|
||||
llm_resp = self._ask_nonchat(prompt)
|
||||
llm_resp = self._ask_nonchat(prompt)
|
||||
|
||||
CONFIG.max_tokens_rsp = tmp_max_tokens_rsp
|
||||
self.llm.model = tmp_model_name
|
||||
logger.info(f"Action: {self.cls_name} llm _run_text_davinci raw resp: {llm_resp}")
|
||||
if self._func_validate(llm_resp, prompt):
|
||||
return self._func_cleanup(llm_resp, prompt)
|
||||
CONFIG.max_tokens_rsp = tmp_max_tokens_rsp
|
||||
self.llm.model = tmp_model_name
|
||||
logger.info(f"Action: {self.cls_name} llm _run_text_davinci raw resp: {llm_resp}")
|
||||
if self._func_validate(llm_resp, prompt):
|
||||
return self._func_cleanup(llm_resp, prompt)
|
||||
except Exception as exp:
|
||||
logger.warning(f"Action: {self.cls_name} _run_text_davinci exp: {exp}")
|
||||
time.sleep(5)
|
||||
return self.fail_default_resp
|
||||
|
||||
def _run_gpt35(self,
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import errno
|
|||
import json
|
||||
import os
|
||||
import shutil
|
||||
import time
|
||||
from pathlib import Path
|
||||
from typing import Any, Union
|
||||
|
||||
|
|
@ -66,8 +67,14 @@ def get_embedding(text, model: str = "text-embedding-ada-002"):
|
|||
text = text.replace("\n", " ")
|
||||
if not text:
|
||||
text = "this is blank"
|
||||
return openai.Embedding.create(
|
||||
input=[text], model=model)['data'][0]['embedding']
|
||||
for idx in range(3):
|
||||
try:
|
||||
embedding = openai.Embedding.create(input=[text], model=model)['data'][0]['embedding']
|
||||
except Exception as exp:
|
||||
time.sleep(5)
|
||||
if not embedding:
|
||||
raise ValueError("get_embedding failed")
|
||||
return embedding
|
||||
|
||||
|
||||
def extract_first_json_dict(data_str: str) -> Union[None, dict]:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue