Skip to content

Instantly share code, notes, and snippets.

View piclez's full-sized avatar

Peter WD piclez

View GitHub Profile
@lotif
lotif / upload_and_deploy_new_model_version.py
Last active August 25, 2024 22:10
Upload and deploy new model version to Vertex AI endpoint
import sys
import logging
from google.cloud import aiplatform
logging.basicConfig(level=logging.DEBUG, format="%(asctime)s - %(name)s - %(levelname)s: %(message)s")
logger = logging.getLogger(__name__)
model_id = sys.argv[1]
artifact_uri = sys.argv[2]
// Chart.tsx example
'use client'
import { AreaChart, Card, Title } from '@tremor/react'
const generateData = () => {
let dataset = []
const dates = [
'Jun 30',
@peterc
peterc / embedding_store.rb
Last active December 28, 2023 06:27
Using SQLite to store OpenAI vector embeddings from Ruby
# Example of using SQLite VSS with OpenAI's text embedding API
# from Ruby.
# Note: Install/bundle the sqlite3, sqlite_vss, and ruby-openai gems first
# OPENAI_API_KEY must also be set in the environment
# Other embeddings can be used, but this is the easiest for a quick demo
# More on the topic at
# https://observablehq.com/@asg017/introducing-sqlite-vss
# https://observablehq.com/@asg017/making-sqlite-extension-gem-installable
@alexrudall
alexrudall / #ChatGPT Streaming.md
Last active November 10, 2024 23:18
ChatGPT streaming with ruby-openai, Rails 7, Hotwire, Turbostream, Sidekiq and Tailwind!

How to add ChatGPT streaming to your Ruby on Rails 7 app!

This guide will walk you through adding a ChatGPT-like messaging stream to your Ruby on Rails 7 app using ruby-openai, Rails 7, Hotwire, Turbostream, Sidekiq and Tailwind. All code included below!

Want more content like this, for free? Check out my free book, RailsAI!

Alt Text

@andreibondarev
andreibondarev / create_schema.rb
Last active October 2, 2023 23:26
Code for "Adding Intelligent Search to a Rails application with Weaviate"
require "weaviate"
client = Weaviate::Client.new(
url: ENV['WEAVIATE_URL'],
api_key: ENV['WEAVIATE_API_KEY'],
# Configure Weaviate to use OpenAI to create vectors and use it for querying
# You can also use Cohere or Hugging Face and pass their API key here instead
model_service: :openai,
model_service_api_key: ENV['OPENAI_API_KEY']
{
"name": "setup-chat",
"description": "the gist to setup Build your own AI-Powered chat app with Next.js and LangChain from blog.experienced.dev",
"version": "0.3.0",
"engines": {
"node": ">=18"
},
"bin": "./setup.js"
}
@mabenson00
mabenson00 / cheatsheet.rb
Last active October 22, 2024 02:15
Rails Postgres ActiveRecord JSON cheatsheet
# Basic key operators to query the JSON objects :
# #> : Get the JSON object at that path (if you need to do something fancy)
# -> : Get the JSON object at that path (if you don't)
# ->> : Get the JSON object at that path as text
# {obj, n} : Get the nth item in that object
# https://www.postgresql.org/docs/9.4/functions-json.html#FUNCTIONS-JSONB-OP-TABLE
# Date
# date before today
@Tiefseetauchner
Tiefseetauchner / Instructions.md
Created December 4, 2022 18:32
ChatGPT RPG adventure

How to?

This is a prompt that will make ChatGPT play a RPG adventure with you. Just paste the prompt into the input. You can also provide information like your name

To pause a game, save the JSON and paste it in the second file and paste that as the prompt. Optionally provide more information for the model like setting

Why?

To play original and very adaptive RPG games without friends. Obviously, I'm a redditor.

@mattiaz9
mattiaz9 / blurhashDataURL.ts
Last active November 16, 2024 13:04
Convert blurhash to a base64 DataURL string (no canvas or node-canvas)
import { decode } from "blurhash"
export function blurHashToDataURL(hash: string | undefined): string | undefined {
if (!hash) return undefined
const pixels = decode(hash, 32, 32)
const dataURL = parsePixels(pixels, 32, 32)
return dataURL
}
@nymous
nymous / README.md
Last active November 15, 2024 19:24
Logging setup for FastAPI, Uvicorn and Structlog (with Datadog integration)

Logging setup for FastAPI

This logging setup configures Structlog to output pretty logs in development, and JSON log lines in production.

Then, you can use Structlog loggers or standard logging loggers, and they both will be processed by the Structlog pipeline (see the hello() endpoint for reference). That way any log generated by your dependencies will also be processed and enriched, even if they know nothing about Structlog!

Requests are assigned a correlation ID with the asgi-correlation-id middleware (either captured from incoming request or generated on the fly). All logs are linked to the correlation ID, and to the Datadog trace/span if instrumented. This data "global to the request" is stored in context vars, and automatically added to all logs produced during the request thanks to Structlog. You can add to these "global local variables" at any point in an endpoint with `structlog.contextvars.bind_contextvars(custom