Q: How do I install nginx? Q: Where is nginx configured? Q: Where is nginx hosted on homebrew?
Chunking text
These are basic chunking utilities for quickly getting large text blocks into smaller chunks. Starts with Character based, then Word base, then Sentence based chunking.
My VSCode Vim settings
User Settings > Key Bindings Step: Find”Preferences: Open User Settings (JSON) Explanation: Code command Do this in the command palette by typing “shell command” Key Repeat on Mac Different installations use different commands (github)
async openai calls with python
In the previous post we explored asyncio (link), here we build on that to create async openai calls The uses the standard python “asyncio” library and the function asyncio.gather to concurrently call openai 3 times (you can add as many calls as you like).
Async python with asyncio
You have two options for concurrent python Traditionally, we used threads with python for concurrency, but the release of the asyncio library (version 3.4) and the release of async/await syntax (version 3.5) created support for native coroutines that are familiar to users of the many languages that support it. (history of asyncio) asyncio (docs) The…
local inference with llama-cpp-python
Step: install the package Step: download a model “TheBloke” on huggingface (link) has a ton of models in “GGUF” format (format introduced by llama.cpp) Click on any of these different quantized (reduced precision) models and find the “download” link Put them in your project somewhere like a “models” directory Step: create your python (.py) or…
rsync with python without extra files
Your goal is to send your python project to your server from your local machine. Your python project includes a ton of files you wouldn’t want to send to a server so a simple rsync is not enough. Option 1: rsync with a bunch of exclude flags Option 2: Shell Function Option 3: Shell script
tiktoken: get number of tokens from string + openai pricing
Get the number of tokens The encoding cl100k_base is used by gpt-4, gpt-3.5-turbo, text-embedding-ada-002.This is how you encode a string into the tokens. You can abstract this into a separate function. Source: openai-cookbook (github) OpenAI Pricing As of November 22, 2023 Splitting chunks for to manage Context Window Limits gpt-3.5-turbo-1106 has a limit of 16,385…
Creating a form with HTMX, Django
Step 1: Activate htmx (link) for django: Render a csrf token somewhere Step 2: Create the form with hx-post Case: Targeting a container div Case: Loading states extension (docs) Setup: import script, set style to avoid flash, add header Disable submit, add a loading indicator
Django and pgvector for semantic search
Goal: Semantic Search Setup pgvector You have a model with a field you want to make semantically searchable. Installation comes from: https://github.com/pgvector/pgvector-python Step: install pgvector on your machine Step: create a migration to activate Step: add a VectorField to your model Step: make migrations and migrate Setup sentence transformers for embeddings We will use the…