Skip to content

Instantly share code, notes, and snippets.

import json
import logging
from datetime import datetime
from typing import Any
from sqlalchemy import create_engine, text
logger = logging.getLogger("llm_logger")
DEFAULT_DATABASE_URL = (
EXTRACTION_PROMPT = """\
<system_prompt>
You are an intelligent and disciplined AI assistant specializing in identifying and classifying Red-Line Statements (RLS) from the public statements of world leaders. Your job is to read a text in Russian and determine if it contains a Red-Line Statement (RLS), and if it does, break down that statement in a specific JSON format.
- **CRITICAL:** Your response MUST ALWAYS be in valid JSON format. Any deviation from the format will make your output completely unusable.
- **CRITICAL**: **Accuracy in JSON formatting is vital.** This includes proper use of double quotes ("") for strings, no quotes around numbers, and correct placement of brackets [], commas ,, and colons :.
- **CRITICAL**: **Do not include any additional explanations or comments outside the JSON structure.**
### What is a Red-Line Statement (RLS)?
@hp0404
hp0404 / sqlite3
Created July 9, 2022 12:28
imports csv file into sqlite3 and later exports a subset of the table to a separate csv
# import
sqlite3 -csv phrases.db ".import np-example.csv phrases_table"
# export
sqlite3 -header -csv phrases.db "select * from phrases_table limit 5;" > tracks.csv
@hp0404
hp0404 / cache_decorator.py
Created April 27, 2022 08:11
Короткий приклад декоратора з параметрами
import functools
def pop_item(di, *, first=True):
if first:
it = iter(di)
else:
it = iter(reversed(di))
key = next(it)
return key, di.pop(key)
@hp0404
hp0404 / kmplus.py
Created May 28, 2021 07:55
kmplus-api
# -*- coding: utf-8 -*-
import os
import logging
import requests
import pandas as pd
from time import sleep
KEY = os.environ.get("kmplus", "")
KMP = "https://kmplus.ukravtodor.gov.ua/api/v1/kmp"
ROUTE = "https://kmplus.ukravtodor.gov.ua/api/v1/route/id"
@hp0404
hp0404 / asyncio_aiohttp_requests.py
Last active September 16, 2020 10:52
aiohttp, asyncio: An example of how to make concurrent requests with a random timeouts, process JSON response and store it in a tabular format.
import json
import random
import asyncio
import aiohttp
import pandas as pd
SLEEP_RANGE = 0.4, 0.8
CONCURRENT_CONNECTIONS = 5