Skip to content

Instantly share code, notes, and snippets.

View jfjensen's full-sized avatar

Jes Fink-Jensen jfjensen

View GitHub Profile
@jfjensen
jfjensen / langchain_chatopenai.py
Created September 15, 2023 11:25
Using Langchain to access an LLM on a vLLM server
from langchain import PromptTemplate
from langchain.prompts.chat import ChatPromptTemplate, HumanMessagePromptTemplate
from langchain.chains import LLMChain
from langchain.chat_models import ChatOpenAI
import requests
base_url = "http://localhost:9999/v1"
x = requests.get(base_url + "/models")
model = str(x.json()["data"][0]["id"])
@jfjensen
jfjensen / langchain_openai.py
Created September 15, 2023 11:16
Using Langchain to access an LLM on a vLLM server
from langchain import PromptTemplate
from langchain.chains import LLMChain
from langchain.llms import OpenAI
import requests
base_url = "http://localhost:9999/v1"
x = requests.get(base_url + "/models")
model = str(x.json()["data"][0]["id"])
print(f"model: {model}")
@jfjensen
jfjensen / vllm_guidance.py
Last active May 15, 2025 16:45
Using the Guidance AI to access an LLM on a vLLM server
import guidance
import requests
base_url = "http://localhost:9999/v1"
x = requests.get(base_url + "/models")
model = str(x.json()["data"][0]["id"])
guidance.llm = guidance.llms.OpenAI(
model=model,
endpoint=base_url,
@jfjensen
jfjensen / vllm_openai_chat_api.py
Created September 14, 2023 20:03
Using the OpenAI Chat API to access an LLM on a vLLM server
import openai
base_url = "http://localhost:9999/v1"
openai.api_key = "***"
openai.api_base = base_url
models = openai.Model.list()
model = models["data"][0]["id"]
print(f"model: {model}")
@jfjensen
jfjensen / vllm_openai_api.py
Created September 14, 2023 20:01
Using the OpenAI API to access an LLM on a vLLM server
import openai
base_url = "http://localhost:9999/v1"
openai.api_key = "***"
openai.api_base = base_url
models = openai.Model.list()
model = models["data"][0]["id"]
print(f"model: {model}")
@jfjensen
jfjensen / reviews.py
Last active July 25, 2023 18:33
A Python script for scraping reviews from Amazon given one or more product ASIN codes.
from playwright.sync_api import sync_playwright
from selectolax.parser import HTMLParser
from dataclasses import dataclass
import time
import csv
from loguru import logger
@dataclass
class Item:
asin: str
@jfjensen
jfjensen / gtav_yolopv2.py
Last active October 16, 2022 13:06
This code allows you to perform road and vehicle detection in GTA V using YOLOPv2.
import mss
from win32gui import FindWindow, GetWindowRect, SetForegroundWindow
import torch
import cv2 as cv
import numpy as np
from time import time, sleep
from utils.utils import letterbox, driving_area_mask, lane_line_mask,\
split_for_trace_model, non_max_suppression, plot_one_box, scale_coords, clip_coords
@jfjensen
jfjensen / ready_data.yaml
Created October 1, 2022 17:08
YAML file describing the training data
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
# Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
path: ../PROJECT/ready_data/train_data # dataset root dir
train: images/train # train images (relative to 'path')
val: images/val # val images (relative to 'path')
test: ../PROJECT/ready_data/test_data # test images (optional)
# Classes
names:
@jfjensen
jfjensen / albion_test.py
Created October 1, 2022 17:05
This code is used for real-time inference on a stream of screenshots from Albion Online
import mss
from win32gui import FindWindow, GetWindowRect, SetForegroundWindow
import torch
import cv2 as cv
import numpy as np
from time import time, sleep
window_handle = FindWindow(None, "Albion Online Client")
window_rect = GetWindowRect(window_handle)
SetForegroundWindow(window_handle)
@jfjensen
jfjensen / labels.txt
Created October 1, 2022 16:03
This is a textfile with the labels that we'll use for annotating the objects in the images for the dataset
Iron Ore
Hemp
Flax
Travertine
Sandstone
Rough Logs
Cotton
Limestone
Copper Ore
Tin Ore