Недавно делал быстрый прототип асинхронного приложения в котором требовалось вызывать много синхронного кода. Да, я знаю, что это не лучший дизайн, но нужно было быстрое решение на один процесс и без очередей. Поэтому я выполнял код в потоках.
Выглядело это примерно так:
from fastapi.concurrency import run_in_threadpool
async def execute(data: DataRequest) -> DataResponse:
try:
result = await run_in_threadpool(sync_function, data)
return DataResponse(data=result)
except Exception as e:
return DataResponse(
error=str(e),
success=False,
)
В общем работает нормально. Для всех вызовов под капотом используется общий тредпул, всё работает предсказуемо.
Но потребовалось изменить количество запускаемых в пуле потоков (по умолчанию создается 40 воркеров).
Так как дело происходит с FastAPI, делается это через lifespan используя настройки anyio:
import anyio
@asynccontextmanager
async def lifespan(app: FastAPI):
limiter = anyio.to_thread.current_default_thread_limiter()
limiter.total_tokens = 100
yield
# если вдруг нужно вернуть обратно
limiter.total_tokens = 40
Зачем менять количество воркеров?
- уменьшить, если оперативки мало (один тред занимает ~8мб)
- увеличить чтобы выдержать нагрузку
Если есть предложения получше при тех же вводных - предлагайте😉
#async
green flag: IRAS bot will never get annoyed at you for asking the same questions every tax season 😅 Got a tax question? Use the IRAS bot to get help any time you need. 😉
https://www.iras.gov.sg/digital-services/others/iras-bot
#chatbot#irassg
Air Canada Ordered to Honor Chatbot's Impromptu Refund Policy
Hello everybody! In a landmark decision, Air Canada has been directed by Canada's Civil Resolution Tribunal to uphold a refund policy cited by its customer service chatbot. The ruling sets a potential precedent for similar cases involving automated customer service platforms.
The saga began when Jake Moffatt sought bereavement fares following his grandmother's passing in November 2022. Engaging with Air Canada's chatbot, he was informed of a retroactive refund option for reduced bereavement rates. Despite Air Canada's insistence that the chatbot's actions were independent, the tribunal ruled in Moffatt's favor, deeming the airline accountable for the chatbot's representations.
This decision not only obligates Air Canada to refund Moffatt's fare but also underscores the significance of accuracy and accountability in automated customer interactions. As chatbots become increasingly prevalent in customer service, the ruling highlights the need for companies to ensure consistency and reliability in their AI-driven communications.
#AirCanada#Chatbot
🧠 Google Gemini endi eski suhbatlaringizni eslab qoladi! 💾
Endi Gemini istalgan suhbatni eslab qoladi va kerak bo‘lsa, eski suhbatlaringizga o‘zi murojaat qiladi!😱
🔹RAG tizimi ishlaydi – oldingi chatlaringizdan ma’lumotni topish va ulardan foydalanish imkoniyati!
🔹Mavzuga mos bo‘lsa, AI o‘zi eslab qoladi va sizga kerakli faktlarni taqdim etadi.
🔹Siz istalgan suhbatga murojaat qilishingiz mumkin, hatto u uzoq vaqt oldin bo‘lsa ham!
📌Bitta muhim narsa:
🛑Cheksiz xotirani faollashtirish uchunGemini Advanced obunasi kerak.
🛑Hozircha faqat Flash modeli bilan ishlaydi.
🔮OpenAI ham shunday funksiyani ishlab chiqayotganini aytgandi… Ko‘ramiz, kim birinchi bo‘ladi!🚀
#Gemini#AI#Google#Chatbot
Shhh! Close the curtain quickly!
We don't want the neighbors to see anything! 🤫👀💥
Chat and see more selfies:
📲(iOS)
📲(Android)
#stepsis#aigirlfriend#chatbot
All of your image creations, all in one place.
Introducing the new library for your ChatGPT image creations—rolling out now to all Free, Plus, and Pro users.
➖➖➖➖🔻
💎@Chatgpt_OfficialNews – Stay Updated! ⚡️
🧠 BOT: @Chatgpt_OfficialBOT
#️⃣#OpenAI#AI#GPT#ChatGPT#Chatbot
➖➖➖➖🔺