Skip to content

Instantly share code, notes, and snippets.

View fswair's full-sized avatar
🤠
coding

Mert fswair

🤠
coding
View GitHub Profile
@fswair
fswair / grpo_demo.py
Last active February 2, 2025 23:11
llama code interact
# thoughts
# 1) if you do not use it for more than one time, do not define a variable
# 2) add detailed annotations to understanding code and best editor support
# 3) do not use f-string 4 times, you can apply them all in one f-string expression
# # 3.1) if you did not change sep parameter, then you dont need to send strings one by one
# 4) you can use f-string expression to multiply characters
def correctness_reward_func2(prompts: List[List[Mapping[str, str]]], completions: List[Mapping[str, str]], answer: List[Any], **kwargs) -> list[float]:
responses = [completion[0]['content'] for completion in completions]
@fswair
fswair / waifu.py
Last active April 3, 2024 20:11
WaifuPics API Wrapper
from aiohttp import ClientSession
from enum import Enum, auto
import asyncio
class InvalidResponse(Exception):
"""Error class for invalid responses."""
pass
class InvalidInput(Exception):
"""Error class for invalid inputs."""
@fswair
fswair / main.py
Created November 14, 2023 13:49
cppreference.com impl. python
from requests import get
from bs4 import BeautifulSoup
class CPPReference:
def __init__(self, keyword: str) -> None:
self.keyword = keyword
self.url = f"https://en.cppreference.com/w/cpp/keyword/{keyword}"
def request(self):
self.response = get(self.url, headers={"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:89.0) Gecko/20100101 Firefox/89.0"})
if self.response.status_code != 200:
@fswair
fswair / nowpayments.examples.py
Created August 8, 2023 15:39
telepaidev.NowPaymentsAPI Using Example
from nowpayments import (
currency,
exchanges,
Plugins,
Payments,
NowPaymentsAPI,
GetPaymentContext
)
from nowpayments.dataclasses import IPNCompatibleResponse
@fswair
fswair / api.py
Last active July 30, 2023 19:16
distance calculator api with locations
import geopy, haversine as hs
from fastapi import FastAPI
app = FastAPI()
@app.get("/get/locationDistance")
async def distanceCalc(loc1: str, loc2: str):
locator = geopy.Nominatim(user_agent="MacOS 13.5;")
location: geopy.Location = (locator.geocode(loc1))
location2: geopy.Location = (locator.geocode(loc2))
point1 = (location.latitude, location.longitude)