有人有使用 Openai 的 API 创建嵌入的经验吗?当我尝试运行 openai.Embedding.create(input=short_string, model="text-embedding-ada-002 ) 时,我在几行代码的第一步中遇到了一个奇怪的错误(速率限制)。如果有人有任何想法,我们将不胜感激!
(我确信我的 api 密钥有效并且有积分,我在 2 个帐户中尝试了多个,其中一个已付款)
根据速率限制文档,您可能需要等待 48 小时才能解除初始限制。随后的限制更加宽松。
对我有用的是为 TextSplitter 添加一个更合适的分隔符。 就我而言:
text_splitter = CharacterTextSplitter(chunk_size=800, chunk_overlap=50, separator="\n")
我使用这样的东西(我只会发布一个片段)。如果出现错误429(参考OpenAI的Rate Limit),请等待60秒。如果再次出现这种情况,我会将 Batch 分成两部分,并在 60 秒后重试。等等...
...
except HTTPException as http_error:
if http_error.status_code == 429: # back off if rate limit reached
logger.info("HTTP RATE LIMIT REACHED: {0}", str(http_error.detail))
time.sleep(60)
if len(documents_chunk) == 1:
# retry the single document
process_documents_chunk(documents_chunk, retries + 1)
else:
# Recursively divide and process the documents
half = len(documents_chunk) // 2
process_documents_chunk(documents_chunk[:half], retries + 1)
time.sleep(60)
process_documents_chunk(documents_chunk[half:], retries + 1)
else:
logger.exception("HTTP ERROR: {0}", str(http_error.detail))
raise
...