Skip to content

Instantly share code, notes, and snippets.

View raunakdoesdev's full-sized avatar

Raunak Chowdhuri raunakdoesdev

View GitHub Profile
@raunakdoesdev
raunakdoesdev / claude_json_prefill.py
Created November 10, 2024 05:34
Force claude to output JSON by pre-filling the response with ```json
import anthropic
client = anthropic.Anthropic()
message = client.messages.create(
model="claude-3-5-sonnet-20241022",
max_tokens=1000,
temperature=0,
system="Always respond in JSON.",
messages=[
{"usage":{"num_pages":3},"result":{"type":"full","chunks":[{"content":"# Jazz Pharmaceuticals (JAZZ)\n\nRating: OUTPERFORM* Price (9 May 14, US$): 129.45 Target Price (US$): 170.00 52-Week Price Range: 55.28-174.98 Market Cap. (US$ m): 8,196.0 Enterprise Value (US$ m): 9,089.5\n\n*Target Price is for 12 months.\n\nResearch Analysts: Peter Sullivan, Ph.D. Seth Davis, M.D. John Tuld, M.D.\n\nFigure 1 JAZZ Stock Price Performance\n\nACCUMMULATE RECOMMENDATION/COMPANY UPDATE\n\n## Strong Q1 FY14 & Multiple Catalysts Ahead\n\n- Q1 Results: Jazz Pharmaceuticals reported strong Q1 results on Thursday, with revenue of $247 million vs. $196 million in Q1 of FY 13, representing 26% YoY growth. The GAAP Net Loss was $93 million vs. GAAP Net Income of $43 million in Q1 of FY 13, but $127 million of that was due to an upfront license fee and milestone payment for JZP-110. Adjusted Net Income was $101 million vs. $84 million in Q1 of FY 13. These figures were slightly ahead of Goldman Stanley estimates of $240 million in r
{
"usage": {
"num_pages": 63,
"num_fields": 1098
},
"result": [
{
"companyName": "MetLife",
"effectiveDate": null,
"benefitPlans": [
@raunakdoesdev
raunakdoesdev / visualize_bbox.py
Created May 17, 2024 20:39
Code snippet for visualizing bounding boxes
import requests
import os.path
from pdf2image.pdf2image import convert_from_path
from PIL import ImageDraw
pdf_path = os.path.expanduser("~/Downloads/research-highlight.pdf")
upload_form = requests.post("https://v1.api.reducto.ai/upload").json()
requests.put(upload_form["presigned_url"], data=open(pdf_path, "rb"))
response = requests.post(
{
"$ref": "#/definitions/extension",
"definitions": {
"extension": {
"type": "object",
"properties": {
"$schema": {
"type": "string"
},
"name": {
@raunakdoesdev
raunakdoesdev / qa_gpt.py
Last active December 12, 2022 17:34
Get GPT to answer questions with justifications, then extract those answers and justifications in a standardized format.
# Setup OpenAI GPT API
import openai
import textwrap
# Set the GPT-3 API key
openai.api_key = "YOUR_API_KEY"
def get_gpt_response(prompt, max_tokens=2048, temperature=0.7, n=1):
response = openai.Completion.create(
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<OfficeApp xmlns="http://schemas.microsoft.com/office/appforoffice/1.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:bt="http://schemas.microsoft.com/office/officeappbasictypes/1.0"
xsi:type="ContentApp">
<Id>03648872-fa1f-4c2d-b9aa-29ce4d0a2bbc</Id>
<Version>1.0.0.0</Version>
<ProviderName>Contoso</ProviderName>
<DefaultLocale>en-US</DefaultLocale>
<DisplayName DefaultValue="Oloren PPT Visualize"/>
‰PNG

IHDR  Ì Ú¦!m sRGB ®Îé gAMA ± üa úPLTE / L N !P "Q #S #U $V %X &Z &[ '] (_ (a )c *d *f +h ,j -l -m .n .o /o 0o 1o 2n 3n 4n5n6n
7m7m8m9m9m:l;l<l <l"=l$>l&>l'?l)@k+Ak,Ak.Bk/Ck1Dk2Dk3Ek5Fk6Fk7Gk8Hk:Ik;Ik<Jk=Kk>Kk@LkAMkBNkCNkDOkEPkFPkGQkHRkISkJSkKTkLUkMUkNVkOWlPXlQXlRYlSZlTZlU[lV\lW]mX]mY^mZ_m[_m\`m]an^bn_bn_cn`dnaeobeocfodgoegofhpgiphjpikqjlqkmqlmrmnrnorooropspqsqrsrrtsstttuuuuvvvwwvxxvyxwzyw{zw{{x|{x}|x~}x~x€~xx‚€xƒx„x…‚x†ƒx‡„xˆ…x‰…xІx‹‡xŒˆxˆxމxŠx‹x‘Œx’Œx“x”Žx•x–w—w˜‘w™’wš“w›“wœ”w•wž–vŸ—v ˜v¡˜v¢™v£šu¤›u¥œu¦œu§u¨žt©Ÿtª t«¡t¬¡s­¢s®£s¯¤s°¥r±¦r²¦r´§qµ¨q¶©q·ªp¸«p¹«pº¬o»­o¼®n½¯n¾°n¿±mÀ±mÁ²l³lôlŵkƶkÇ·jȸjɸiʹi˺hÌ»hͼgνgоfÑ¿fÒÀeÓÀeÔÁdÕÂcÖÃc×ÄbØÅaÙÆaÛÇ`ÜÈ`ÝÉ_ÞÊ^ßË]àË]áÌ\ãÍ[äÎ[åÏZæÐYçÑXèÒWéÓVëÔVìÕUíÖTî×SïØRðÙQñÚPóÛOôÜNõÝMöÞL÷ßKùàIúàHûáGüâFýãEÿäCÿåBÿæBÿçCÿèDÿéEŸ‘+Û€rU pHYs à ÃÇo¨d HIDATx^íÔåÒ.€A8‚H7Ò!twww
J# ÝÝÝ%Jw(¤”bJwIKfx†ï½þ²{;ð=6â°aÃ~‘2rFɨùaFËèùQÆÈ3fÆÊØ'ãf¼ŒŸ 2a&ÊÄ“dҁÉò“L>0E¦ÌT™:ÓdÚL—é3C~š3SfÎ,™5³eöÌ‘ŸeÎÌ•¹3OæÍ|™? dÁ,”…
import sqlite3
import numpy as np
import datetime
secret_key = 0.10721210370764633
db_path = '/var/jail/home/raunakc/lab08a/server.db'
def request_handler(request):
if request['method'] == 'GET':
{
"Beef": [
357.0,
224.0,
312.0,
281.0,
185.0,
185.0,
540.0,
432.0,