AI 资讯
AIchain Pool: Parallel Calls Instead of Sequential
You have 50 documents and you're running them through an LLM in a loop. The first one finishes at the 2-second mark. The fiftieth finishes at the 100-second mark — not because it's harder, but because it waited in line behind the other 49. Pool runs all 50 at the same time. The Problem With Loops Every developer who works with LLMs writes this code eventually: import os from yait_aichain.models import Model from yait_aichain.skills import Skill skill = Skill ( model = Model ( " claude-sonnet-4-6 " , api_key = os . getenv ( " ANTHROPIC_API_KEY " )), input = { " messages " : [{ " role " : " user " , " parts " : [ " Summarise in two sentences: \n\n {text} " ]}]}, ) documents = [{ " text " : f " Document { i } content... " } for i in range ( 50 )] results = [] for doc in documents : result = skill . run ( doc ) results . append ( result ) It works. It's readable. And it's painfully slow. Each LLM call takes roughly 2 seconds. Multiply that by 50 documents and you're staring at your terminal for almost two minutes. The calls are completely independent — document 37 doesn't need the result of document 12. Yet document 37 sits idle, waiting its turn. That's a scheduling problem, not a computation problem. I ran into this directly while building a task that pulled N files or links and produced a consolidated report. The sequential version was logically fine but just hemorrhaged time. I needed to fire everything at once without rewriting the Skill logic — no new prompt templates, no restructured code, just a different execution model. That's what Pool is. Pool: Parallel Map for LLM Calls Pool takes one Skill (or Chain) and a list of inputs , then launches all of them concurrently. Think of it as Array.map() where every element runs in parallel against an LLM. import os from yait_aichain.models import Model from yait_aichain.skills import Skill from yait_aichain.pool import Pool , DONE , FAILED skill = Skill ( model = Model ( " claude-sonnet-4-6 " , api_key = os . getenv ( "
开源项目
🔥 home-assistant / core - 🏡 Open source home automation that puts local control and pr
GitHub热门项目 | 🏡 Open source home automation that puts local control and privacy first. | Stars: 87,712 | 32 stars today | 语言: Python
开源项目
🔥 skypilot-org / skypilot - Run, manage, and scale AI workloads on any AI infrastructure
GitHub热门项目 | Run, manage, and scale AI workloads on any AI infrastructure. Use one system to access & manage all AI compute (Kubernetes, Slurm, 20+ clouds, on-prem). | Stars: 10,141 | 46 stars today | 语言: Python
开源项目
🔥 openinterpreter / openinterpreter - A lightweight coding agent for open models like Deepseek, Ki
GitHub热门项目 | A lightweight coding agent for open models like Deepseek, Kimi, and Qwen | Stars: 63,947 | 45 stars today | 语言: Python
开源项目
🔥 pytest-dev / pytest - The pytest framework makes it easy to write small tests, yet
GitHub热门项目 | The pytest framework makes it easy to write small tests, yet scales to support complex functional testing | Stars: 13,942 | 8 stars today | 语言: Python
AI 资讯
Weekly Challenge: Existence
Weekly Challenge 377 Each week Mohammad S. Anwar sends out The Weekly Challenge , a chance for all of us to come up with solutions to two weekly tasks. My solutions are written in Python first, and then converted to Perl. Unless otherwise stated, Copilot (and other AI tools) have NOT been used to generate the solution. It's a great way for us all to practice some coding. Challenge , My solutions Task 1: Reverse Existence Task You are given a string. Write a script to find whether any substring of length 2 is also present in the reverse of the given string. My solution This is relatively straight forward. I create a variable reversed_string which is the string reversed. I then have a loop called start_pos that goes from 0 to 2 less than the length of the string. At each position, I check if the two letters at that position are in the original string. def reverse_existence ( input_string : str ) -> bool : reversed_string = input_string [:: - 1 ] for start_pos in range ( len ( input_string ) - 1 ): if reversed_string [ start_pos : start_pos + 2 ] in input_string : return True return False The Perl solution follows the same logic. sub main ($input_string) { my $reversed_string = reverse ( $input_string ); foreach my $start_pos ( 0 .. length ( $input_string ) - 2 ) { if ( index ( $input_string , substr ( $reversed_string , $start_pos , 2 ) ) != - 1 ) { say " true "; return ; } } say " false "; } Examples $ ./ch-1.py abcba true $ ./ch-1.py racecar true $ ./ch-1.py abcd false $ ./ch-1.py banana true $ ./ch-1.py hello true Task 2: Prefix Suffix Task You are given an array of strings. Write a script to find if the two strings ( str1 , str2 ) in the given array such that str1 is prefix and suffix of str2. Return the total count of such pairs. My solution In Python, this is a one line solution. I use the combinations function from the itertools module to produce all combinations of pairs of str1 and str2 . For each pair, I use the startwith and endswith function on the strings
AI 资讯
I built a free Python AI platform for Indian developers. Here's everything inside.
6 months ago I was a final year CS student with no real projects and no clear path into tech. So I built one. Not just a project. A full platform. Here's everything inside Rohith Builds — completely free, forever. What's Inside 1. 100 Structured Lessons (Python → AI) Not random tutorials. A structured path: Day 1-20: Python basics Day 21-40: Backend & APIs Day 41-60: SQL & Databases Day 61-80: AI & LLMs Day 81-100: AI Agents & Launch Every lesson uses Indian examples. Zomato orders. Cricket scores. IRCTC bookings. Aadhaar validation. Because most tutorials use pizza and baseball. We use what we actually know. 2. Rohi — AI Tutor Stuck on a concept? Ask Rohi. he's powered by Groq LLM, understands Indian context, and is available 24/7. No waiting for a mentor to reply. No expensive bootcamp. Just ask and learn. 3. Jobs Board — Updated Daily This took the longest to build. An autonomous scraper that: → Queries LinkedIn Guest API → Searches Naukri via AOL gateway → Finds Indeed listings → Sends each to Groq AI for analysis → Filters only junior/fresher roles → Checks freshness (last 4 days only) → Removes duplicates automatically → Inserts into PostgreSQL Result: 53+ curated jobs. Updated daily. Filter by: Python, Backend, AI, Frontend Filter by: 2025, 2026, 2027 graduates No more scrolling through senior roles pretending to be junior. 4. 220+ Prompt Vault Every prompt I've used to: Debug faster Write better code Prepare for interviews Build projects Copy. Use. Customize. 5. Improve Any Prompt (Free Tool) Paste any AI prompt. Get an optimized version instantly. No signup needed. The Tech Stack Built with: Python + Flask PostgreSQL (Neon) Groq API (Llama-3.3-70b) Render deployment SQLAlchemy + psycopg2 No React. No Next.js. No hype stack. Just Python and PostgreSQL doing real work. Why I Made It Free Because every resource that helped me was either: Paywalled after lesson 3 In English accent I had to rewind Using examples I couldn't relate to Assuming I had a MacBook and
AI 资讯
I Built a Consistent Hashing Ring in Pure Python and Finally Understood How Cassandra Distributes Data
I Built a Consistent Hashing Ring in Pure Python and Finally Understood How Cassandra Distributes Data I've been using Cassandra and Redis Cluster for years. I knew consistent hashing was "how they work." But I never truly got it until I built one myself from scratch, in pure Python, with zero dependencies. This post is about what I learned doing that. The Problem Consistent Hashing Solves Imagine you have 3 servers and 1 million keys. The naive approach: server = hash(key) % 3 . It works great until you add or remove a server. Change 3 to 4, and almost every key remaps to a different server. In a caching layer, that means near 100% cache miss. In a database, it means massive data movement. That's the problem consistent hashing solves. When you add or remove a node, only a fraction of keys move. Specifically, 1/n of the keys, where n is the number of nodes. Building the Ring The core idea: place both nodes and keys on a circular number line from 0 to 2^32 (or any large integer). To find which node owns a key, walk clockwise until you hit a node. Here's the minimal version: import hashlib import bisect class ConsistentHashRing : def __init__ ( self , replicas = 150 ): self . replicas = replicas self . ring = {} # hash -> node name self . sorted_keys = [] # sorted hash positions def _hash ( self , key : str ) -> int : return int ( hashlib . md5 ( key . encode ()). hexdigest (), 16 ) def add_node ( self , node : str ): for i in range ( self . replicas ): virtual_key = f " { node } :vnode: { i } " h = self . _hash ( virtual_key ) self . ring [ h ] = node bisect . insort ( self . sorted_keys , h ) def remove_node ( self , node : str ): for i in range ( self . replicas ): virtual_key = f " { node } :vnode: { i } " h = self . _hash ( virtual_key ) del self . ring [ h ] idx = bisect . bisect_left ( self . sorted_keys , h ) self . sorted_keys . pop ( idx ) def get_node ( self , key : str ) -> str : if not self . ring : raise ValueError ( " Ring is empty " ) h = self . _hash
AI 资讯
Python for Machine Learning: The Complete Roadmap Nobody Told You About
When I first started exploring Machine Learning, I made the same mistake most beginners do — I jumped straight into neural networks and model training without really understanding the Python underneath. I'd copy code from tutorials, get it running, and have zero idea why it worked. Then I started going through a structured Python-for-ML curriculum — and everything changed. This post is a distillation of that journey. If you're a CS student or early-career developer who wants to work seriously in ML/AI, here's the complete Python foundation you need — with the why , not just the what . Why Python Specifically? (It's Not Just Hype) Python isn't the fastest language. C++ blows it out of the water on speed — and I've personally used C++ for packet-capture modules in one of my ML projects. But Python dominates ML for one reason: the ecosystem . NumPy, Pandas, PyTorch, TensorFlow, Scikit-learn, Hugging Face — all Python-first. You don't choose Python for ML. The field chose it for you. Stage 1: Python Basics — The Foundation You Can't Skip Before you touch any ML library, you need these locked in. Variables and Data Types Python is dynamically typed, which feels nice at first but will bite you during data preprocessing if you're not careful. # These are all valid — Python infers the type name = " Parth " score = 8.97 is_enrolled = True year = 2025 For ML, the types that matter most are int , float , bool , and str — and knowing when Python silently converts between them (type coercion) can save you hours of debugging. Loops and Conditions — Your Data Iteration Backbone grades = [ 8.5 , 7.9 , 9.1 , 6.8 , 8.97 ] for g in grades : if g >= 8.5 : print ( f " Distinction: { g } " ) elif g >= 7.0 : print ( f " First Class: { g } " ) else : print ( f " Pass: { g } " ) Simple? Yes. But this exact pattern — iterate over a collection, branch on conditions — is the mental model for 80% of data cleaning code you'll write later. Functions and Lambda Expressions Functions are how you st
AI 资讯
Agent Series (20): Harness in Production — From Single File to Reusable Package
From Demo Code to a Reusable Package Article 19 used a 900-line harness_full_demo.py to demonstrate eight defense layers. That file is good for explaining concepts, but not for reuse — all layers are coupled together, nothing can be tested in isolation, and nothing can be imported by another project. A production-grade Agent project needs something you can actually import : harness/ ├── __init__.py Public API exports ├── registry.py Layer 2: ActionRegistry + PermissionLevel ├── budget.py Layer 3: PermissionBudget (with refund()) ├── sandbox.py Layer 4: sanitise_input + sandboxed_eval ├── audit.py Layer 6: ImmutableAuditLog (hash-chained) ├── rollback.py Layer 7: RollbackCoordinator └── harness.py Unified entry point: AgentHarness This article starts with package design, covers three key API decisions, and finishes with two integration styles: standalone Python and LangGraph graph embedding. Module Design registry.py — Layer 2 class PermissionLevel ( Enum ): READ = 1 WRITE = 2 ADMIN = 3 IRREVERSIBLE = 4 @dataclass class RegisteredAction : name : str level : PermissionLevel budget_cost : int description : " str " handler : Any # Callable or BaseTool class ActionRegistry : def register ( self , action : RegisteredAction ) -> None : ... def get ( self , name : str ) -> RegisteredAction : ... # not found → PermissionError def is_allowed ( self , name : str ) -> bool : ... def names ( self ) -> list [ str ]: ... get() rather than __getitem__ : raises a consistent PermissionError , without leaking the internal KeyError detail. budget.py — Layer 3 class PermissionBudget : def spend ( self , action_name : str , cost : int ) -> None : if self . remaining < cost : raise BudgetExhaustedError (...) self . remaining -= cost def refund ( self , action_name : str , cost : int ) -> None : self . remaining = min ( self . total , self . remaining + cost ) The new refund() method fixes a design flaw from Article 19: budget was deducted before approval, and never returned on rejection.
AI 资讯
I Cut Our Image Captioning Costs 60% — Here's the Backend Story
Check this out: i Cut Our Image Captioning Costs 60% — Here's the Backend Story Look, I'll be honest. Six months ago I didn't think twice about image captioning. We were a small team, traffic was low, and we just threw everything at GPT-4o because it was the path of least resistance. Then our infra bill came in, my manager did that thing where he just stares at the dashboard, and suddenly I was a "cost optimization" guy. fwiw, that was not in my job description. This is the story of how I went from "we just use GPT-4o for everything" to a multi-model setup that cut our spend by more than half, with quality that — imho — is actually better than what we had before. No, this is not a sponsored post. Yes, I am going to mention Global API at the end because they made my life easier. More on that in a bit. Why Image Captioning Was Even on My Radar Our product has a lot of user-uploaded images. Think: product photos, profile pictures, the usual suspects. For each one we need a short, accessible caption that we use for SEO, alt text, and a downstream tagging pipeline. The downstream pipeline, btw, is the part that actually makes us money. Garbage captions in, garbage tags out. We were calling gpt-4o for everything. Every image. No caching. No batching. No thought. Each call cost us $2.50 per million input tokens and $10.00 per million output tokens. You don't have to be a math PhD to know that scales badly. I was not a math PhD. I am still not a math PhD. But I can do division. When I started pulling the numbers, the situation was grim. We were processing roughly 8 million images a month, and each one was generating more tokens than it needed to. I found one image in the logs that had produced a 4,000-token caption. The image was a screenshot of an error message. The caption was longer than the error. The Wake-Up Call: Actually Reading the Catalog One Saturday morning, coffee in hand, I decided to actually look at what was on offer. I'd been ignoring the multi-model world b
AI 资讯
Sliding-Window Spend Guard: the $47K Loop Per-Call Caps Miss
Sliding-Window Spend Guard for AI Agents: Catch the $47K Loop Per-Call Caps Miss A sliding-window spend guard sums what your agent has spent over the last N minutes and refuses the next call before it dispatches — which is the thing a per-call cap can't do. A per-call cap asks "is this one call too expensive?" The runaway loops that empty a budget are built from calls that each pass that check. The damage lives in the sum, not in any single call. In short: a sliding-window spend guard tracks a trailing window of calls and blocks the next one when cumulative spend or a repeated near-identical call breaches a per-window rule. In my run it stopped an Analyzer-Verifier ping-pong at call 12, $45.80 in, after a naive per-call $5 cap let all 12 through. Stdlib, keyless, runs in seconds. AI disclosure: I wrote window_guard.py with AI assistance and ran it myself before publishing. Every number in the output blocks below is pasted from a real run of that script on a fixture I'll show you. The $47K incident is someone else's, and I link the postmortem next to it. I label which is which. A $47K agent loop where every single call was fine In November 2025 a team woke up to a $47,000 bill from a single agent deployment. Four LangChain agents, talking to each other over A2A, and two of them — an Analyzer and a Verifier — got into a ping-pong. Analyzer hands work to Verifier, Verifier kicks it back, repeat. For 264 hours. The cost didn't spike. It escalated , week over week: $127, then $891, then $6,240, then $18,400. The author of the postmortem, Gabriel Anhaia, describes the root cause in a way I keep coming back to: the dashboard was green for eleven days, and there was no step cap, no per-conversation USD budget, no orchestrator deciding when the work was done ( dev.to/gabrielanhaia, Nov 2025 ). The dashboard showed the number. It just showed it after each call, never before the next one. A follow-up teardown by the Waxell team sharpened the line into the title of their piece:
开发者
AtCoder Beginner Contest 462 参加記録と解答例 (A E問題)
本記事は、AtCoder Beginner Contest 462 (ABC462) に参加した際の、A〜E問題の復習と解答の備忘録です。コンテスト中に考えた解法の方針や、提出したPythonのコードについて整理しています。 A - Secret Numbers / 実行時間制限: 2 sec / メモリ制限: 1024 MiB / Difficulty: None 配点 : 100 点 問題文 英小文字と数字のみからなる文字列 $S$ が与えられます。 $S$ から数字である文字だけを取り出し、元の順序のまま並べた文字列を求めてください。 制約 $S$ は英小文字と数字のみからなる長さ 1 以上 50 以下の文字列 自分の解答の方針 一文字づつ数字かどうかを判定し、数字のみを配列に入れて出力する。 提出の時には数字かどうかの判定は0-9のどれかに含まれているかを調べたが、解説ではPythonは isdigit() で数値かどうかを調べられるらしい。 提出したコード S = list ( input ()) T = [] for i in range ( len ( S )): if S [ i ] in [ " 1 " , " 2 " , " 3 " , " 4 " , " 5 " , " 6 " , " 7 " , " 8 " , " 9 " , " 0 " ]: T . append ( S [ i ]) print ( "" . join ( T )) B - Gift / 実行時間制限: 2 sec / メモリ制限: 1024 MiB / Difficulty: None 配点 : 200 点 問題文 人 1 から人 $N$ の $N$ 人がギフトを送り合いました。 人 $i$ は人 $A_{i,1}, A_{i,2}, \dots, A_{i,K_i}$ の $K_i$ 人にギフトを送りました。 $i=1,2,\dots,N$ に対し、人 $i$ にギフトを送った人を全て求めてください。 制約 $2 \le N \le 100$ $1 \le K_i \le N-1$ $1 \le A_{i,1} < A_{i,2} < \dots < A_{i,K_i} \le N$ $A_{i,j} \neq i$ 入力される値は全て整数 自分の解答の方針 辞書に人 $i$ と、その人にギフトを送った人の番号をリストとして持つことを考える。 入力で受け取った、ギフトを送った人と送られた人すべてに対して辞書に登録し、結果を出力する。 提出したコード N = int ( input ()) dct = dict () for i in range ( N ): dct [ i + 1 ] = [] for i in range ( N ): A = list ( map ( int , input (). split ())) for j in range ( 1 , A [ 0 ] + 1 ): dct [ A [ j ]]. append ( i + 1 ) for i in range ( N ): print ( " " . join ([ str ( len ( dct [ i + 1 ]))] + list ( map ( str , dct [ i + 1 ])))) C - Not Covered Points / 実行時間制限: 2 sec / メモリ制限: 1024 MiB / Difficulty: None 配点 : 300 点 問題文 2 次元平面上に点 1 から点 $N$ の $N$ 個の点があります。点 $i$ $(1 \le i \le N)$ の座標は $(X_i, Y_i)$ です。ここで、 $X, Y$ はそれぞれ $(1,2,\dots,N)$ の順列であることが保証されます。 左下の頂点を $(0,0)$ 、右上の頂点を $(X_i, Y_i)$ とする $x$ 軸に平行な辺と $y$ 軸に平行な辺のみからなる長方形の内部(辺上を含まない)に点 1 から点 $N$ までの $N$ 個の点をどれも含まないような $i$ の個数を求めてください。 制約 $1 \le N \le 3 \times 10^5$ $1 \le X_i, Y_i \le N$ $X, Y$ はそれぞれ $(1,2,\dots,N)$ の順列 入力される値は全て整数 自分の解答の方針 端から考えたいので、初めに $X$ についてソートする。 $X$ が小さい順に見ていったとき、現在の点が作る長方形の内部にほかの点が含まれるかどうかは、、これまでに走査した($X$座標が自身より小さい)点の中に、自身より $Y$ 座標
AI 资讯
Beyond the Happy Path: Lessons in Resilience and Distributed State
Reflecting on two major technical challenges from my backend engineering internship, focusing on fault tolerance, infrastructure, and distributed architectures. Introduction As I wrap up my HNG internship, I’ve been reflecting on the gap between code that "works on my machine" and code that survives in production. Here is a look at two tasks from Stage 9—one solo, one team-based—that completely changed how I approach backend engineering and infrastructure. The Individual Task: Background Job Scheduler What it was For my individual Stage 9 task, I built a distributed background job scheduler backed by PostgreSQL and a FastAPI backend, featuring a vanilla HTML/CSS/JS frontend. It manages async tasks (like a mock email sending queue) using a MinHeap priority queue, Directed Acyclic Graph (DAG) dependency resolution, a Dead-Letter Queue (DLQ), and a real-time Server-Sent Events (SSE) dashboard. The problem it was solving Heavy asynchronous tasks—like email generation or batch processing—cannot block the main API thread. The system needed to successfully queue, prioritize, retry on failure, and track every job entirely independently from the standard request-response cycle. How I approached it I built the core logic from the ground up: a MinHeap and an alternative Timing Wheel algorithm for scheduling, a worker engine featuring a 3-attempt backoff sequence (1s, 5s, 25s with jitter), a DAG dependency checker, and a starvation daemon to prevent tasks from hanging. Once the CRUD API and SSE streaming were hooked up, I containerized the entire application with Docker and wrote my deploy scripts. I thought I was done. What actually broke and how I fixed it The application code took hours. The deployment took a full day of non-stop debugging across multiple cloud providers. Oracle Cloud was out of capacity on every free tier shape, and GCP demanded upfront payment. I finally got a t3.micro running on AWS, but that’s when the real DevOps nightmare began: The SSL Chicken-and-Egg
开源项目
🔥 shareAI-lab / learn-claude-code - Bash is all you need - A nano claude code–like 「agent harnes
GitHub热门项目 | Bash is all you need - A nano claude code–like 「agent harness」, built from 0 to 1 | Stars: 66,365 | 133 stars today | 语言: Python
开源项目
🔥 NVIDIA / physicsnemo - Open-source deep-learning framework for building, training,
GitHub热门项目 | Open-source deep-learning framework for building, training, and fine-tuning deep learning models using state-of-the-art Physics-ML methods | Stars: 2,927 | 6 stars today | 语言: Python
开源项目
🔥 tirth8205 / code-review-graph - Local-first code intelligence graph for MCP and CLI. Builds
GitHub热门项目 | Local-first code intelligence graph for MCP and CLI. Builds a persistent map of your codebase so AI coding tools read only what matters, with benchmarked context reductions on reviews and large-repo workflows. | Stars: 18,455 | 36 stars today | 语言: Python
开源项目
🔥 scikit-learn / scikit-learn - scikit-learn: machine learning in Python
GitHub热门项目 | scikit-learn: machine learning in Python | Stars: 66,316 | 19 stars today | 语言: Python
开源项目
🔥 reflex-dev / reflex - 🕸️ Web apps in pure Python 🐍
GitHub热门项目 | 🕸️ Web apps in pure Python 🐍 | Stars: 28,485 | 9 stars today | 语言: Python
开源项目
🔥 andrewyng / aisuite - Simple, unified interface to multiple Generative AI provider
GitHub热门项目 | Simple, unified interface to multiple Generative AI providers | Stars: 13,988 | 132 stars today | 语言: Python