You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#!/usr/bin/python3importsysimporttracebackimportopenaifromopenlimitimportChatRateLimiterWithRedisopenai.api_key="<token>"request_timeout=3rate_limiter=ChatRateLimiterWithRedis(
request_limit=3500,
token_limit=90000,
redis_url="redis://localhost:6379/0"
)
@rate_limiter.is_limited()defcall_openai(**chat_params):
returnopenai.ChatCompletion.create(**chat_params)
defextract_sentiment(text):
iftext=="":
return"NEUTRAL"messages= [{"role": "system",
"content": "You are an AI language model trained to analyze and detect the sentiment of hackernews forum comments."},
{"role": "user",
"content": f"Analyze the following hackernews comment and determine if the sentiment is: positive, negative or neutral. "f"Return only a single word, either POSITIVE, NEGATIVE or NEUTRAL: {text}"}]
try:
params= {
"model": "gpt-3.5-turbo",
"messages": messages,
"max_tokens": 30,
"temperature": 0,
"request_timeout": request_timeout
}
response=call_openai(**params)
sentiment=response.choices[0].message.content.strip()
return"NEUTRAL"ifsentiment==""elsesentimentexceptExceptionase:
traceback.print_exc()
returnf"ERROR - {e}"forsizeinsys.stdin:
# collect a batch for performanceforrowinrange(0, int(size)):
print(extract_sentiment(sys.stdin.readline().strip()))
sys.stdout.flush()
throws an exception
AttributeError: 'NoneType' object has no attribute 'wait_for_capacity_sync'
ERROR - 'NoneType' object has no attribute 'wait_for_capacity_sync'
Traceback (most recent call last):
File "/opt/udfs/sentiment_distributed.py", line 39, in extract_sentiment
response = call_openai(**params)
File "/opt/udfs/.venv/lib/python3.9/site-packages/openlimit/utilities/context_decorators.py", line 22, in wrapper
with self.rate_limiter.limit(**kwargs):
File "/opt/udfs/.venv/lib/python3.9/site-packages/openlimit/utilities/context_decorators.py", line 44, in __enter__
self.rate_limiter._request_bucket.wait_for_capacity_sync(1)
AttributeError: 'NoneType' object has no attribute 'wait_for_capacity_sync'
printf '6\n\nThis page seems to cover most of the prerequisites, and some other advice: <a href="https://github.com/yandex/ClickHouse/blob/master/doc/build.md" rel="nofollow">https://github.com/yandex/ClickHouse/blob/master/doc/build.m...</a><p>And it does say this: <i>"With appropriate changes, build should work on any other Linux distribution...Only x86_64 with SSE 4.2 is supported"</i>\nThanks so much for that. It definitely looks like the documentation might be out of sync as there are also some references to ODBC support in the code:<p><a href="https://github.com/yandex/ClickHouse/blob/32057cf2afa965033cf850a081e7a9dfa306594d/dbms/src/ODBC/info.cpp" rel="nofollow">https://github.com/yandex/ClickHouse/blob/32057cf2afa965033c...</a><p>Going to look into building a Spark data source for this so we can see how it well it compares to databases like Cassandra.\nWithout supporting other operating systems it is hard to consider it as an alternative to anything. We have several clusters using another operating system than the one supported by ClickHouse. Unfortunately few customers are going to invest into a different platform to try out something new like this. The lower the entering bar for new tech is the better.\nThis is huge. It seems to me that it's similar to BigQuery but has many other features that I didn't see in other databases.<p>AggregatingMergeTree is especially one of them and allows incremental aggregation which is a huge gain for analytics services.<p>Also it provides many table engines for different use-cases. You don't even need a commit-log such as Apache Kafka in front of ClickHouse, you can just push the data to TinyLog table and and move data in micro-batches to a more efficient column-oriented table that uses different table engine.\n\n' | python3 sentiment.py
The text was updated successfully, but these errors were encountered:
You can try doing something like this =>
@rate_limiter.is_limited()
async def call_openai(**kwargs):
print("Calling OpenAI API...")
result = openai.ChatCompletion.create(**kwargs)
print("OpenAI API call completed.")
return result
on inspecting the source code, the sync part of the Redis one isn't properly implemented, but the async one works, as in the aenter dunder that wait_for_capacity() function is properly called unlike the enter dunder.
Following (v0.3.0)
throws an exception
The text was updated successfully, but these errors were encountered: