今日已更新 100 条资讯 | 累计 24386 条内容
关于我们

标签:#Python

找到 732 篇相关文章

AI 资讯

How to Route Real-Time Gold and Silver Prices from a Unified WebSocket Stream

When I first connected to a precious metals WebSocket API, I expected to get a clean stream of prices. What I actually got was a firehose of mixed ticks—gold, silver, platinum—all arriving through the same callback. If you’ve ever tried to build a trading bot or a custom chart, you know this is a recipe for disaster. In this post, I’ll share how I solved the problem with a few lines of Python and a clear mapping strategy. The scenario: You have one WebSocket URL that pushes quotes for multiple metals. You need to separate them so you can update different UI components, run independent strategies, or store them in distinct database tables. The data pain point: every message uses the same JSON structure, and the only differentiator is a field like symbol . If you don’t act on it immediately, everything gets mixed up. Identify Assets via the Symbol Field Start by checking the API docs for the field that carries the instrument code. Usually it’s symbol , but instrumentId or type are also used. Here’s a typical reference table: Field Description Example symbol Asset code XAUUSD, XAGUSD instrumentId Internal platform ID 1001, 1002 type Asset class gold, silver I turn this into a dictionary mapping each symbol to a human-readable category: asset_map = { " XAUUSD " : " gold " , " XAGUSD " : " silver " , " XPTUSD " : " platinum " } Buffer Messages by Type Because these streams are high-frequency, I avoid processing every tick individually. Instead, the WebSocket callback just updates an in-memory store that is already grouped by asset type: # Keep the hot path extremely light def on_message ( msg ): symbol = msg [ ' symbol ' ] price = msg [ ' price ' ] asset_type = asset_map . get ( symbol , " unknown " ) cache [ asset_type ][ symbol ] = price Then, a background timer fetches the latest prices from cache["gold"] and cache["silver"] separately and does the actual work—like computing indicators or rendering charts. The key benefit is complete isolation: your gold logic never t

2026-05-29 原文 →
AI 资讯

Python Day Three – Lists, Indices, and Packing Your Virtual Backpack 🎒

Welcome back to Day 3, Python dynamic duo! 🚀 If you survived Day 2 , you now know how to create variables and throw strings, integers, floats, and booleans into their own little cardboard boxes. 📦 But what happens when you’re building a game and your character needs an inventory? Or you're making a shopping list app? Creating 50 different variables like item1, item2, item3 will make you want to throw your router out the window. 🪟💻 Today, we are leveling up our storage game. We are moving out of single cardboard boxes and packing a Virtual Backpack: Enter Lists! 🎒🎉 🎒 What is a List? In Python, a List is a data structure used to store a collection of items in one single variable. Think of it like a backpack where you can stuff multiple things inside, keep them in a specific order, and pull them out whenever you need them. Creating a list is simple. You use square brackets [] and separate your items with commas: # Packing our survival backpack 🗺️ backpack = [ " map " , " flashlight " , " water bottle " , " protein bar " ] print ( backpack ) # Prints: ['map', 'flashlight', 'water bottle', 'protein bar'] The coolest part? Python lists don’t care what you put inside. You can mix strings, integers, and booleans all in one single backpack (though usually, it makes the most sense to keep similar things together). 🤯 The First Rule of Coding Club: We Start Counting at Zero! Here is where programming turns your brain upside down. 🧠🙃 If I asked you what the first item in our backpack list is, you’d logically say "map". And you'd be right in human language. But in Python-speak, computer memory starts counting at 0. This is called Indexing. To pull a specific item out of your backpack, you write the name of the list followed by the item's position (index) inside square brackets: backpack = [ " map " , " flashlight " , " water bottle " , " protein bar " ] # Pulling out the items using their index 🔍 print ( backpack [ 0 ]) # Prints: map (The absolute first item!) print ( backpack [

2026-05-29 原文 →
AI 资讯

Building a Resume Download Gate: Email Collection, Signed Tokens, and an S3 Lesson

I wanted a soft gate on my resume download. Not a paywall. Just an email field — enough friction to filter bots, enough signal to know who's interested. What started as a straightforward feature turned into a three-part lesson: stateless token signing, S3 public access, and email delivery mechanics. Here's the full story. The Feature The flow I wanted: Visitor clicks "Download Resume" on the About page or Hero A modal asks for their email Backend validates the email (format + disposable domain check) A signed, time-limited link is emailed to them They click the link, the PDF opens No database tokens. No cron jobs. No permanent S3 URLs floating around. Part 1 — The Model and the Gate The Resume Model Resume follows the singleton pattern I already use for page headers — force pk=1 on every save, restrict add/delete in admin. One row, forever. class Resume ( models . Model ): pdf = models . FileField ( upload_to = " resume/ " , storage = private_resume_storage ) last_updated = models . DateField ( default = date . today ) def save ( self , * args , ** kwargs ): self . pk = 1 super (). save ( * args , ** kwargs ) ResumeDownloadRequest logs every email that requests a link — no tokens, no expiry columns, just a record of who asked and when. class ResumeDownloadRequest ( models . Model ): email = models . EmailField () created_at = models . DateTimeField ( auto_now_add = True ) unsubscribed = models . BooleanField ( default = False ) class Meta : ordering = [ " -created_at " ] The unsubscribed flag is there for a future newsletter broadcast — when a new blog post goes out, skip anyone who opted out. Blocking Disposable Emails Before signing anything, the email is checked against a frozenset of ~70 known throwaway domains: # core/validators.py DISPOSABLE_EMAIL_DOMAINS : frozenset [ str ] = frozenset ({ " mailinator.com " , " guerrillamail.com " , " yopmail.com " , " 10minutemail.com " , " trashmail.com " , # ... ~70 total }) def is_disposable_email ( email : str ) -> bool

2026-05-29 原文 →
AI 资讯

Data Scientist & AI Engineer — Open to Full-Time Opportunities

Hey Dev.to the community, I'm Ashwin Gururaj — a Data Scientist & AI Engineer based in Melbourne, Australia, currently open to full-time, contract, and internship opportunities. I specialise in building production-grade AI systems — not just notebooks and demos, but end-to-end pipelines that actually run in production. What I work with: Python · LangChain · LangGraph · FastAPI · RAG pipelines · pgvector · Multi-agent systems · LLMs · Groq · HuggingFace · Pydantic · Docker · Celery · Redis · PostgreSQL · Data Science · SQL · Pandas · Scikit-learn What I've built recently: Sift — an open-source multi-agent fact-checking pipeline. Takes any text, extracts every factual claim, retrieves grounded evidence via HyDE RAG + live web search, and returns auditable verdicts with cited sources. Built with LangGraph, pgvector, FastAPI, and Docker. → GitHub Open to: Full-time Data Scientist / AI Engineer / ML Engineer roles Remote or Melbourne-based Companies building serious AI products If you're hiring or know someone who is — I'd genuinely appreciate a connection. GitHub: https://github.com/ashg2099 LinkedIn: https://www.linkedin.com/in/ashwin-gururaj-93943816a/ Thanks!

2026-05-29 原文 →
AI 资讯

How to Stop Your AI Agent Before It Does Something You Can't Undo

By Umair Sheikh, founder of Gateplex Autonomous AI agents are shipping fast. LangChain, CrewAI, AutoGen — the frameworks are mature, the tutorials are everywhere, and developers are connecting agents to real systems: databases, payment APIs, email, file storage. And then something goes wrong. Not because the code is buggy. Because the agent did exactly what it was told — and what it was told turned out to be a problem nobody anticipated. I spent nearly a decade in fintech and responsible AI policy watching this pattern repeat. A system behaves perfectly in testing. In production, an edge case triggers behaviour that was technically correct but operationally catastrophic. By the time anyone notices, the action has already executed. The problem is not the agent. The problem is that there is nothing between the agent's decision and the real world. The gap nobody talks about Most agent observability tools log what happened. That is useful for debugging. It does nothing to prevent the next incident. What agents actually need is a governance layer — something that intercepts every action before it executes, checks it against your rules, and either allows it, flags it for review, or blocks it outright. This is what a firewall does for network traffic. Your AI agent deserves the same treatment. What this looks like in practice Here is a simple LangChain agent calling an external tool: from langchain.agents import initialize_agent , Tool from langchain.llms import OpenAI def send_payment ( amount : str ) -> str : # This actually moves money return f " Payment of { amount } sent " tools = [ Tool ( name = " SendPayment " , func = send_payment , description = " Send a payment " )] agent = initialize_agent ( tools , OpenAI (), agent = " zero-shot-react-description " ) agent . run ( " Send $5000 to vendor account " ) This works. It also has no guardrails whatsoever. If the agent misreads the input, hallucinates a vendor, or gets manipulated via prompt injection, the payment goes

2026-05-28 原文 →
开源项目

🔥 OpenMOSS / MOSS-TTS - MOSS‑TTS Family is an open‑source speech and sound generatio

GitHub热门项目 | MOSS‑TTS Family is an open‑source speech and sound generation model family from MOSI.AI and the OpenMOSS team. It is designed for high‑fidelity, high‑expressiveness, and complex real‑world scenarios, covering stable long‑form speech, multi‑speaker dialogue, voice/character design, environmental sound effects, and real‑time streaming TTS. | Stars: 2,051 | 53 stars today | 语言: Python

2026-05-28 原文 →
AI 资讯

I built an MCP server that gives AI persistent memory of your SQL database

A while ago I tried to build a local coding assistant. I downloaded Qwen3, fired it up on my MacBook with 16GB of RAM, and within a day realized the output quality was nowhere close to Claude or GPT-5. The model could fit . It just couldn't compete . So I changed the question. If I can't make the model smarter on my hardware, can I make what I feed it smarter? Where the tokens actually go I started watching where my Claude / Cursor / Copilot sessions actually spent their tokens. The surprise: most of it wasn't reasoning. It was lookup . Every fresh chat about my company's database re-discovered the same things: What does status = 3 mean? (cancelled) How does orders join to users ? ( orders.user_id → users.id ) What's that cryptic JobStatus enum? (a dozen integer codes nobody remembers) The model figured it out, the session ended, and tomorrow it figured it out again . Same tokens, same latency, every single time. The expensive part of working with an AI wasn't the thinking — it was re-teaching it things it had already learned yesterday. There's a lot of attention right now on trimming AI output tokens (talk like a caveman, strip the pleasantries, etc.). But in my workflow the bigger leak was on the input side: paying full token cost every session to re-establish context that never changed. "Memory" isn't a feature, it's an architecture question AI clients are starting to bolt on "memory" features. But they're proprietary, opaque, and locked to one tool. Claude's memory doesn't help Cursor. Cursor's doesn't help Copilot. You can't inspect it, you can't share it with a teammate, and you can't diff it. What I actually wanted was an explicit, inspectable, shareable context layer that any AI client could read deterministically — same answer every time, same file my team could hand off. I picked the highest re-learn cost in my world to start with: SQL databases. Enter amnesic amnesic is an open-source MCP server that gives any AI client persistent semantic memory of your

2026-05-28 原文 →