TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: Batch Processing with OpenAI

9 点作者 nantersand将近 2 年前
So I have 10,000 paragraphs I want to individually process with a prompt.<p>Any packages that would handle running things async, doing retries, handling the occasional hung connection, and logging performance?<p>Tried helicone, but I don&#x27;t think it handles the hung connections.<p>Just doing it manually for now, but there must be an existing solution?

7 条评论

bob1029将近 2 年前
You could set up a collection in memory&#x2F;SQL with a Status + UpdatedUtc column and poll the collection for incomplete items each loop until all are in the desired state.<p>Your state machine could be as simple as: New, Processing, Failed, Succeeded. Outer loop will query the collection every ~second for items that are New or Failed and retry them. Items that are stuck Processing for more than X seconds should be forced to Failed each loop through (you&#x27;ll retry them on the next pass). Each state transition is written to a log with timestamps for downstream reporting. Failures are exclusively set by the HTTP processing machinery with timeouts being detected as noted above.<p>Using SQL would make iterations of your various batch processing policies substantially easier. Using a SELECT statement to determine your batch at each iteration would permit adding constraints over aggregates. For example, you could cap the # of simultaneous in-flight requests, or abandon all hope &amp; throw if the statistics are looking poor (aka OpenAI outage).
评论 #37139757 未加载
评论 #37141721 未加载
psimm将近 2 年前
I&#x27;m working on a Python package for this: <a href="https:&#x2F;&#x2F;github.com&#x2F;qagentur&#x2F;texttunnel">https:&#x2F;&#x2F;github.com&#x2F;qagentur&#x2F;texttunnel</a><p>It&#x27;s a wrapper for OpenAI&#x27;s Python sample script plus adjacent functionality like cost estimation and binpacking multiple inputs into one request.
评论 #37139767 未加载
dsalzman将近 2 年前
They have an example python script for batch jobs with retries. <a href="https:&#x2F;&#x2F;github.com&#x2F;openai&#x2F;openai-cookbook&#x2F;blob&#x2F;main&#x2F;examples&#x2F;api_request_parallel_processor.py">https:&#x2F;&#x2F;github.com&#x2F;openai&#x2F;openai-cookbook&#x2F;blob&#x2F;main&#x2F;examples...</a>
tmaly将近 2 年前
What is the average paragraph length?<p>I would consider using one of the 32k context windows.<p>Define a delimiter for the paragraphs and prefix the prompt to process each then write out with a delimiter the result you need.<p>Maybe wrap your call in a simple try catch and do exponential back-off.
kolinko将近 2 年前
Did you try asking chatgpt to write it? :)<p>For async and retries I just asked the bot to write proper code, and it worked fine. Could do it myself, but it would take longer.<p>With hung connections - I didn&#x27;t experience those, but it should also be straightforward.
评论 #37139753 未加载
aiunboxed将近 2 年前
Open AI has a batch api for generating embeddings, rest haven&#x27;t found much libraries built on top of open ai which are production ready
rboyd将近 2 年前
I think a <a href="https:&#x2F;&#x2F;www.windmill.dev&#x2F;">https:&#x2F;&#x2F;www.windmill.dev&#x2F;</a> workflow could handle this