Python and AI

Created: by Pradeep Gowda Updated: Nov 04, 2023 Tagged: sqlite · llm · python

Python

Python 3.12 was announced today, some interesting features:

The itertools.batched function reminded me that I need to internalize itertools and use it more often. The batched function is especially handy.

PES-701 - Changes to f-strings: * quote reuse is a good one. You don’t have to hunt for different types of quotes. You can use double-quote inside the {} without having to use single-quote or escape it. Huge UX improvement. * f-strings can now be multi-line, which makes it easy to read * f-strings are parsed with PEG parser leading to precise error messages.

AI

Andrew Ng: Opportunities in AI - 2023 - Youtube Video.

Updating SQLite table with new values when values exist

Scenario: when two different processes update a SQLite table.

Schema of the table under consideration:

CREATE TABLE sitecache (
url STRING PRIMARY KEY,
title STRING,
generator STRING,
published datetime,
updated datetime,
author string,
description string,
kind string,
keywords TEXT,
html text);

Let’s assume process A updates columns - url, title, html and process B updates the rest.

The first insert looks like:

insert or replace into sitecache(url, title, html) values(?,?,?)

the second insert to update the rest is the interesting part:

WITH new (title, generator, published, updated, author,
  description, kind, keywords, html)
INSERT OR REPLACE INTO sitecache(title, generator, published,
  updated, author, description, kind, keywords, html)
SELECT old.url, new.title, new.generator, new.published,
  new.updated, new.author, new.description, new.kind,
  new.keywords, new.html
FROM new
LEFT JOIN sitecache AS old on new.url = old.url

Inspired by this answer - Source: Stackoverflow.


Next Day