{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "7961ec4aa6944ceb9cf9347d067f9908", "version_major": 2, "version_minor": 0 }, "text/plain": [ "VBox(children=(HTML(value='
---------------------------------------+----------------------+------------\u001b[4h-\u001b[4l========|Tue Oct 24 13:12:52 2023\u001b[1;75H5\u001b[3;19H5\u001b[20;10H4\u001b[20;47H2023\u001b[20;71H 46\u001b[24;80H\u001b[1;75H7\u001b[3;19H7\u001b[20;10H5\u001b[20;31H233\u001b[20;48H101\u001b[20;71H100\u001b[24;80H\u001b[1;75H9\u001b[3;19H9\u001b[20;10H4\u001b[20;33H0\u001b[20;49H83\u001b[20;71H 41\u001b[24;80H\u001b[1;72H3:01\u001b[3;16H3:01\u001b[20;10H3\u001b[20;32H21\u001b[20;48H255\u001b[20;72H 0\u001b[24;80H\u001b[1;75H3\u001b[3;19H3\u001b[20;31H 80\u001b[20;48H307\u001b[24;80H\u001b[1;75H5\u001b[3;19H6\u001b[20;49H93\u001b[24;80H\u001b[1;75H8\u001b[3;19H8\u001b[20;10H2\u001b[20;32H67\u001b[24;80H\u001b[1;74H10\u001b[3;18H10\u001b[20;10H1\u001b[24;80H\u001b[24;1H\u001b[2J\u001b[?47l\u001b8" ] } ], "source": [ "!watch nvidia-smi" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import json" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "with open('/projectnb/ds549/students/aakash07/DrVai/data/Review_of_ophthalmology.json') as f:\n", " json_file = json.load(f)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "chapter_names = list(json_file.keys())" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['Diseases of Lens',\n", " 'Glaucoma',\n", " 'Cornea',\n", " 'Conjunctiva',\n", " 'Sclera and Episclera',\n", " 'Uveitis',\n", " 'Orbit',\n", " 'Ocular Adenexae',\n", " 'Lacrimal Drainage',\n", " 'Neurophthalmology',\n", " 'Fundus',\n", " 'Vitreous',\n", " 'Squint and Optics',\n", " 'Community',\n", " 'Embryology',\n", " 'Recent Advances']" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "chapter_names" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'C H A P T E R': {'start_index': 758656, 'page_number': 381}}" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "json_file['Recent Advances']" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'C H A P T E R\\nDiseases of Lens\\nANATOMY \\uf077 It is secreted at embryonic stage as a\\nbasement membrane of lens epithelium\\n\\uf077 Lens is biconvex in shape. (Thickest basement membrane in\\n\\uf077 Diameter: 9–10 mm. the body).\\n\\uf077 Refractive index: 1.39. \\uf077 It is thicker anteriorly than posteriorly\\nand at the equator than the poles.\\n\\uf077 Total refractive power: 16 D–17 D.\\nCapsule is thinnest at the\\nStructure of Lens posterior pole.\\n2. Anterior epithelium: It constitutes single\\nEquatorial layer of epithelium cells. They are cuboidal\\nIris Epithelium lens bow\\nat the centre and become columnar at the\\nperiphery.\\n3. Lens fibres: They are of two types:\\na. Nucleus (old lens fibres). It is further\\nCiliary divided into: Embryonic (1–3 months\\nbody gestation), Foetal, Infantile, Adult.\\nHexagonal\\nZonules Cortex Capsulelens fibers b. Cortex (youngest lens fibres). Embr-\\nEmbryonic yonic nucleus is the oldest fibres.\\nnucleus\\n4. Zonules of zinn: They are the suspensory\\nFig. 1.1: Structure of lens ligaments which support the nucleus.\\nLens constitutes of:\\nPHYSIOLOGY\\n1. Lens capsule:\\n\\uf077 80% of glucose is metabolized anaerobically.\\n\\uf077 Lens capsule is a thin, transparent,\\nThis leads to formation of lactic acid in the\\nhyaline collagenous membrane which\\nlens which diffuses into the aqueous\\nsurrounds the lens completely.\\nhumour. Hence, absence of lens will lead to\\n\\uf077 Lens capsule is highly elastic but does decreased lactic acid in the aqueous\\nnot have any elastic tissue. humour.\\n12 Review of Ophthalmology\\n\\uf077 Lens derives its nutrition from aqueous Classification\\nhumour.\\na. Etiologically: (1) Senile (2) Metabolic\\n\\uf077 Antioxidative system of the lens constitutes (3) Complicated (4) Traumatic (5) Radia-\\nof Vitamin C, i.e., ascorbic acid, Vitamin tional (6) Toxic (7) Electric (8) Skin diseases\\nE and glutathione. The detoxifying (9) Osseus diseases (10) Syndromes.\\nenzymes which are responsible to\\nb. According to maturity: (1) Immature\\ncounteract the oxidative damage in the lens\\n(2) Mature (3) Hypermature.\\nare catalase and superoxide dismutase.\\nCataract occurs due to the oxidative c. Anatomically: (1) Capsular cataract–\\ndamage to the lens. Anterior and Posterior (2) Subcapsular\\ncataract–Anterior and Posterior (3) Cortical\\n\\uf077 Glutathione plays a central role in\\ncataract (4) Supranuclear cataract (5)\\nprotecting the lens from oxidative damage.\\nNuclear cataract (6) Polar cataract–\\nIt is a tripeptide synthesized in the lens.\\nAnterior and Posterior.\\nIts levels are reduced in patients of\\ncataract. Most common cause of acquired\\ncataract is senile cataract.\\n\\uf077 Myoinositol is actively transported into the\\nlens by sodium dependent carrier mediated\\nCONGENITAL AND DEVELOPMENTAL\\nmechanism. Its levels are markedly\\nCATARACT\\nreduced in cataract. It is a precursor of\\nmembrane phosphoinositides which are\\nEtiology\\ninvolved in Na/Ka ATPase function. It also\\nparticipates in ascorbic acid transport in\\na. Heredity: Usually dominant.\\nthe lens.\\nb. Maternal factors:\\nLens 1. Malnutrition.\\nWater 99% 66% 2. TORCHS infections, i.e., Toxoplas-\\nNa+ 144 20 mosis, rubella, cytomegalovirus, Herpes\\nand syphilis.\\nNa + K + AT Pase\\nK+ 4.5 125 3. Drug: Thalidomide, Corticosteroid.\\nGlucose 6 1 4. Radiation.\\nLactic acid 7.4 14\\nc. Foetal or Infantile factor:\\nProteins 0.04% (S) 33%\\n1. Anoxia.\\nActive Transport\\nDiffusion 2. Metabolic:\\n(S) Synthesis\\na. Galactosemia–Galactokinase defi-\\nFig. 1.2 ciency.\\nDevelopment of lens: Lens develops from b. Neonatal hypoglycemia.\\nlens vesicle which is derived from surface 3. Congenital anomaly: Lowe’s syndrome,\\nectoderm. Myotonia dystrophica.\\nCataract 4. Birth trauma.\\n5. Malnutrition.\\nDefinition: Any interference in the optical\\nhomogeneity of the lens is called cataract. d. Idiopathic.Diseases of Lens 3\\nTypes\\nCONGENITAL RUBELLA SYNDROME\\na. Cataracta centralis pulverulenta:\\nIt is characterized by the classical triad of–\\n1. Embryonic nuclear cataract.\\nCataract, Headache and Deafness.\\n2. Opacity has powdery appearance.\\n3. Does not affect vision.\\nb. Zonular/lamellar: MNEMONIC\\nMost common type of congenital cataract\\nCHD (Cataract, Headache and Deafness)\\ncausing decreased vision.\\n1. Involves the foetal nucleus. Ocular Features\\n2. Etiology may be: 1. Microphthalmos.\\n2. Cataract: Pearly nuclear or lamellar.\\nA. Genetic: Dominant inheritance.\\n3. Retinopathy: Salt-pepper retinopathy at\\nB. Environmental: (1) Vitamin D defi-\\nposterior pole. It is non progressive.\\nciency, (2) Rubella infection in 7th–\\n4. Glaucoma.\\n8th week of gestation.\\n5. Optic nerve abnormalities.\\n3. Usually bilateral.\\n6. Other complications:\\n4. Causes severe visual defect.\\nA. Pendular nystagmus and strabismus.\\n5. Small linear opacities towards\\nB. Keratitis.\\nequator called Riders are charac-\\nteristic of lamellar cataract. C. Iritis and iris atrophy.\\nD. Extreme refractive error.\\nc. Sutural cataract: Along anterior and\\nposterior sutures. The most common type of cataract in\\nrubella is–Nuclear Pearly.\\nd. Anterior polar cataract.\\nACQUIRED CATARACT\\ne. Posterior polar cataract.\\nf. Coronary cataract: Occurs in adolescence, 1.Senile Cataract\\nclub shaped opacities peripheral in\\nEtiology:\\ndistribution.\\n\\uf077 Heredity.\\ng. Punctate cataract: Also called Blue-dot\\n\\uf077 Dehydrational crisis in diarrhea and\\ncataract or Cataracta-punctate-cerulea–\\ncholera.\\nBluish dots in peripheral part of adolescent\\n\\uf077 UV-Rays.\\nnucleus and deeper cortex are seen. It is the\\nmost common type of congenital cataract. \\uf077 Dietary deficiency of vitamin E,C,B and\\nproteins.\\nh. Total congenital cataract.\\nIt is broadly divided into:\\ni. Congenital membranous cataract: It is due\\n\\uf077 Nuclear.\\nto total or partial absorption of congenital\\ncataract. \\uf077 Cortical.4 Review of Ophthalmology\\nNuclear Cataract: lies right in the pathway of the axial\\nrays, at the nodal point of the eye\\nIt occurs due to following factors:\\n(Nodal point of eye is just behind the\\nw Increased age-related nuclear sclerosis. lens) and thus causes an early loss of\\nw Increase in insoluble proteins. visual acuity.\\nw Deposition of pigments like urochrome\\nMaturation of Cortical Cataract:\\nand melanin.\\n1. Stage of Lamellar Separation.\\nSclerosis makes the lens hard and inelastic\\nleading to shrunken lens with wrinkled 2. Stage of Incipient Cataract.\\ncapsule due to leakage of water. This 3. Immature Senile Cataract (Intumescent\\ncauses inability to accommodate and Cataract—It causes frequent change of\\nprogressive index myopia. It manifests as presbyopic glasses).\\n“Second sight of old age”.\\n4. Mature Senile Cataract (Ripe Cataract).\\nMaturation of Nuclear Cataract: 5. Hypermature Morgagnian Cataract.\\nA. Immature cataract. Causes of frequent change of\\npresbyopic glasses are:\\nB. Mature cataract.\\n1. Early cataract (Intumescent cataract).\\nC. Hypermature nuclear sclerotic cataract.\\n2. Late stage of primary open angle\\nNuclear Cataract may be Tinted:\\nglaucoma.\\nA. Amber. 3. Diabetes mellitus (Hyperglycemia\\nB. Brown—Cataracta Brunescens. causes myopic shift and hypoglycemia\\ncauses hypermetropic shift).\\nC. Black—Cataracta Nigra.\\nD. Red—Cataracta Rubra. Note:\\nNuclear cataract causes Hamarlopia (Day w Intumescent cataract is a cause of\\nBlindness). Phacomorphic glaucoma.\\nCauses of Hamarlopia: w Morgagnian cataract is the most\\ncommon form of senile cataract\\n1. Central corneal opacities.\\ncausing glaucoma.\\n2. Central lenticular opacities. w Most common complication of\\n3. Congenital absence of cones. Morgagnian cataract is Phacolytic\\nCortical Cataract: Decreased levels of Glaucoma. Other complication\\npossible is Phacoanaphylactic\\ntotal protein, amino acids and potassium\\nuveitis.\\nalongwith increased concentration of Na+,\\nleads to hydration and coagulation of w Most common complication of\\nproteins causing cataract. It is of two types: hypermature nuclear sclerotic\\ncataract is subluxation of lens.\\n1. Cuneiform: It generally starts as wedge\\nshaped radial spokes from periphery to 2.Metabolic Cataract\\ncenter. Hence visual disturbances are\\ncomparatively at the late stage. a. Diabetes Mellitus:\\n2. Cupulliform: These are posterior sub- w Causes senile cataract at early age (i.e.,\\ncapsular opacities. This type of cataract presenile cataract).Diseases of Lens 5\\nw Typical morphology is Snow-Flake descements membrane is due to\\nOr Snow-Storm Cataract. copper deposition and is patho-\\nw Increased glucose leads to sorbitol gnomic of Wilson’s disease.\\npathway (Due to saturation of other Note: Fleischer’s ring is iron\\nmetabolic pathways like glycolysis and deposition at the base of the cone in\\nkrebs cycle. When enzyme hexokinase patients of keratoconus.\\nis saturated or inhibited, sorbitol path- e. Lowe’s Syndrome (Oculocere-\\nway is the only pathway remaining for brorenal syndrome): It is an\\nglucose metabolism.\\ninborn error of aminoacid metabolism.\\nw This sorbitol accumulation in the lens Ocular Features:\\n(Due to Aldose Reductase pathway)\\n1. Congenital cataract.\\nleads to overhydration of lens causing\\ncataract. 2. Microphakia.\\n3. Posterior lentiglobus/Posterior Lenti-\\nb. Galactosaemia:\\nconus.\\nw Deficiency of GPUT (Galactose-\\n4. Glaucoma.\\nphosphouridyl transferase) causes Oil\\nDroplet Cataract. f. Mannosidosis: Deficiency of alpha-\\nw Deficiency of Galactokinase causes mannosidase leads to mannose rich\\noligosaccharides in tissues causing\\nlamellar cataract.\\nspoke like posterior capsular cataract.\\nc. Hypocalcaemia: Due to decreased\\nparathyroid activity, i.e., Hypoparathy- g. Fabry’s Disease:\\nroidism.\\nw It is due to deficiency of alpha-\\nd. Wilson’s Disease: Wilson’s disease\\nGalactosidase.\\n(Hepatolenticular degeneration) is a\\nOcular Features:\\nrare condition caused by deficiency of\\nalpha —globulin, ceruplasmin. It is 1. Spoke like cataract—No impairment\\n2\\ncharacterized by widespread deposition of vision.\\nof copper in the tissues and becomes\\n2. Vortex Keratopathy.\\nmanifest in 3 ways:\\n1. Liver disease. 3.Complicated Cataract\\n2. Neurological involvement of the\\nClinical Features:\\nbasal ganglion.\\n3. Psychiatric features. w It is posterior cortical or more\\ncommonly posterior subcapsular due to\\nOcular Features are:\\nposterior segment disease.\\n1. Sunflower Cataract: This type of\\nw It is anterior cortical due to anterior\\ncataract also occurs in blunt trauma\\nsegment disease.\\nwhere it is also known as Rossete\\nCataract. w Most commonly it is Posterior sub-\\ncapsular.\\n2. K.F. Ring (Kayser-Fleischer Ring):\\nGolden brown discoloration of w Spreads axially.6 Review of Ophthalmology\\nw Has Bread Crumb appearance. 5. Busulphan: It is given for treatment of\\nw Polychromatic luster is the patho- CML. It causes PSC, i.e., posterior sub-\\ncapsular cataract.\\ngnomic feature of complicated\\ncataract. 6. Amiodarone: Anterior subcapsular\\ncataract. Also causes vortex keratopathy.\\nCauses:\\n7. Cu, Fe, Au: Gold is used for the\\n1. Inflammatory–Iridocyclitis, Pars- treatment of rheumatoid arthritis and\\nplanitis, Choroiditis, Endophthalmitis, causes ASC.\\nCorneal ulcer. w Most common ocular compli-\\n2. Degenerative–Retinitis pigmentosa, cation of steroid is–Glaucoma.\\nBest disease (It is dystrophy of RPE Occurrence of glaucoma is\\ncells), Myopia. genetically monitored. Less common\\nin short term steroid therapy or\\n3. Tumours.\\nalternate day therapy.\\n4. Glaucoma–Primary and Secondary.\\nw Oral steroids more commonly\\n5. Retinal detachment. lead to cataract and topical\\nHypermetropia is not a degenerative steroids more commonly lead to\\ndisease hence complicated cataract glaucoma.\\ndoes not occur in hypermetropia but w Both phenothiazines (chlorpromazine)\\noccurs in myopia. and chloroquine can cause cataract\\nbut phenothiazines are most\\n4.Toxic Cataract\\ncommonly mentioned in relation to\\ncataract formation.\\nCauses:\\n5.Traumatic Cataract\\n1. Corticosteroids: Typically discoid,\\nposterior sub-capsular cataract which\\nFeatures of Blunt Trauma/\\nat a later stage involves anterior\\nsubcapsular region. Steroids both Concussion Injury:\\nsystemic and topical are cataracto-\\n1. Rossette-shaped cataract: It is also\\ngenic.\\ncalled sunflower cataract. It mainly\\n2. Phenothiazines: Deposition of fine yellow involves posterior cortex first.\\nbrown granules under the anterior 2. Vossius ring: It is the imprint of iris\\ncapsule in pupillary zone which develop pigment on the anterior capsule of the\\ninto large stellate opacities and finally lens, due to blunt trauma.\\nanterior polar cataract.\\n3. Berlins edema: It is also called\\n3. Chloroquine: (Not hydroxychloroquine) Commotio Retinae. It is macular edema\\ncauses white, flaky posterior sub- after blunt trauma and is morpho-\\ncapsular cataract. logically described as “cherry-red spot”.\\n4. Anticholinesterases: Commonly causes 4. Angle-recession glaucoma: Angle\\nanterior subcapsular cataract. Mainly recession occurs due to tear in ciliary\\ndue to long acting miotics like DFP, body after blunt trauma. Glaucoma is\\nEcothiophate, Demecarium bromide. due to damage in trabecular network.Diseases of Lens 7\\n6.Radiational Cataract 2. Ptosis—Usually bilateral.\\nw It occurs due to damage to lens by all 3. Pigmentary retinopathy, i.e., salt\\ntypes of radiations namely UV rays, and pepper fundus.\\nInfrared rays, X-rays/Y-rays or neutrons. 4. Pupillary changes—Light-near\\nw Infrared rays causes “Glass Blower’s” or dissociation.\\nGlass worker’s cataract. 5. Low intraocular—pressure.\\nw MRI has no radiation exposure as it is Hence, we remember its ocular\\ndone by ultrasonic energy and not features as 5 Ps.\\nradiations.\\n2. Atopic dermatitis: Stellate opacities\\nw Most common type of radiational\\nmostly posterior.\\ncataract is Posterior subcapsular\\n3. Diabetes mellitus: It causes snowstorm\\ncataract. They are punctate subcapsular\\nor snowflake opacities.\\nopacities which mature rapidly.\\n7.Syndermatotic Cataract SYNDROMES ASSOCIATED WITH\\nCATARACT\\nThese are cataracts which occur due to skin\\ndiseases.\\nA.Down’s Syndrome\\nCauses:\\nOcular Features:\\nw Atopic dermatitis is the most common 1. Shortened and slanted palpebral fissure.\\ncause.\\n2. Neonatal ectropion.\\nw Poikiloderma.\\n3. Lateral trichiasis and entropion.\\nw Scleroderma.\\n4. Keratoconus.\\n8.Pre-Senile Cataract 5. Cataract.\\nThese are cataracts which occur in young 6. Brushfield spots are light coloured\\nage. spots on iris.\\nB.Others\\nCauses:\\nw Werner’s syndrome.\\n1. Myotonic dystrophy: Myotonic dys-\\ntrophy or Dystrophia myotonica is a w Rothmund’s syndrome.\\ngeneralized dominantly inherited\\nmyopathy characterized by myotonia of CLINICAL FEATURES OF CATARACT\\nperipheral muscles and muscle wasting.\\n1. Misty vision with distortion of vision.\\nOcular Features:\\n2. Loss of vision.\\n1. Pre-senile cataract\\n3. Coloured halos.\\nw “Christmas-tree cataract”—\\nOther causes of coloured halos are:\\nposterior subcapsular, stellate\\nplaque. w Mucopurulent conjunctivitis.\\nw Small iridescent, polychromatic w Acute congestive angle closure\\ncrystals. glaucoma.8 Review of Ophthalmology\\nFinchams Test: It helps to know the 4. Phacoemulsification: Cataract removal\\ncause of halos whether it is due to cataract using phacoemulsification is achieved by\\nor glaucoma. A stenopic slit is passed in ultrasonic fragmentation and aspiration of\\nfront of the eye which is seeing the halos, the lens material. The tip of the phaco-\\nif the halos break then it is due to cataract emulsification hand piece is composed of a\\nand if not then it is due to glaucoma. hollow (approximately 1 mm) titanium\\n4. Black spots in front of eyes. needle that transmits vibrations at a high\\nspeed (30,000 to 60,000 cycles/sec) to\\n5. Glare.\\nemulsify the cataract. These vibrations are\\n6. Uniocular diplopia or polyopia seen in stage\\ntransferred from piezoelectric or magneto-\\nof intumescent cataract.\\nstrictive crystals.\\n5. Lensectomy with anterior vitrectomy:\\nCOMPLICATIONS OF LONG\\nLens in toto with anterior vitreous is\\nSTANDING CATARACT\\nremoved. This procedure is specially opted\\n1. Uveitis. in children when ICCE is indicated. This\\nis because in children there is strong\\n2. Subluxation or dislocation of lens (In\\nadhesion between posterior surface of lens\\nnuclear sclerotic cataract).\\nand anterior hyaloid face of vitreous and\\n3. Glaucoma: Phacoanaphylactic/Phaco-\\nhence any pulling can cause retinal\\nmorphic/Phacolytic.\\ndetachment.\\nMANAGEMENT OF CATARACT 6. Mydriatics/optical iridectomy: This\\nprocedure can be opted for congenital\\nThe first line of treatment in cataract is stationary cataracts but now it is more of\\nsurgery. a theoretical purpose and not opted for.\\nModalities of Treatment of Cataract 7. ECCE with PC IOL with primary posterior\\n1. ICCE (Intracapsular cataract extraction): It capsulotomy: Primary posterior capsulo-\\nconstitutes removal of lens alongwith the tomy is done in children as they are very\\ncapsule. The methods of ICCE are: 1. prone to develop posterior capsular\\nCryoextraction 2. Forceps method (Arrugas opacification after few days of surgery due\\nforceps are used) 3. Irisophake 4. Wire to intense postoperative inflammations.\\nVectis 5. Indiansmith method (Also called\\nDiscission and Needling done in\\ntumbling method). The best method is\\ncongenital cataract are now obsolete\\ncryoextraction. Today the only\\nprocedures.\\nindication of ICCE is subluxation of\\nPreoperative evaluation of cataract\\nlens.\\nsurgery includes:\\n2. ECCE with PC IOL (Extracapsular cataract\\nextraction): It constitutes removal of lens I. General Examination for:\\nleaving behind the posterior capsule on\\n\\uf077 Diabetes mellitus.\\nwhich artificial lens is implanted.\\n\\uf077 Hypertension.\\n3. Manual small incision cataract surgery:\\n\\uf077 Cardiac problems.\\nThis is sutureless small incision cataract\\nsurgery without using the phacoprobe. \\uf077 Obstructive lung disorders.Diseases of Lens 9\\nw Any potential source of infection in the w State of endothelial cells.\\nbody like—septic gums, urinary tract\\nE. Intraocular pressure measurement.\\ninfection.\\nF. Gonioscopy is not done routinely. It is\\nII. Ocular Examination:\\nonly when the IOP is found raised, we\\nA. Retinal function test: can do to assess the state of the angle.\\n1. Perception of light.\\nSURGICAL TECHNIQUES\\n2. Projection of rays—Easy test to\\nassess the function of peripheral\\nECCE\\nretina.\\n(a)Limbal partial thickness incision is made\\n3. Test for Marcus Gunn pupillary\\nfrom 10 o’ clock to 2 o’ clock.\\nresponse.\\n(b)Anterior chamber is formed by viscoelastic\\n4. Two light discrimination.}\\nthrough a small full thickness incision.\\nMacular\\n5. Maddox rod test.\\nfunction (c) Anterior capsulotomy is done (Can opener\\n6. Laser interferometry. test\\ntechnique or Envelope technique).\\n7. Stereoacuity.\\n(d)Partial thickness limbal incision is made\\n8. Color perception—It indicates that full-thickness by corneal scissors.\\noptic nerve is relatively normal.\\n(e) Hydrodissection and hydrodelineation is\\n9. Entoptic visualization is also used to done.\\nindicate retinal function but it is a\\n(f) Nucleus is prolapsed.\\nsubjective test where the patient\\n(g)Cortical matter is aspirated.\\nperceives his own vasculature.\\n10. Indirect ophthalmoscopy. (h)IOL is implanted.\\nB. Objective tests are indicated if some (i) Incision is sutured by radial sutures.\\nretinal pathology suspected. BSS (i.e., Basal salt solution) with glutathione\\ni. ERG—Electroretinogram. is the ideal irrigating fluid in cataract\\nsurgery as it resembles the aqueous humour\\nii. EOG—Electrooculogram.\\nmost.\\niii. VER—Visually-Evoked-Response.\\nAfter cataract surgery, stitches are removed\\nC. Search for local source of infection: at 6 weeks post-operative, and refraction\\nw Conjunctivitis. should be done after 2 weeks of the suture\\nremoval so that any change in corneal\\nw Blepharitis.\\ncurvature due to the sutures (tight or loose)\\nw Meibomitis. is stabilized. (But if in the question, 8 weeks\\nw Lacrimal sac infection—lacrimal is not an alternative, we will mark 6 weeks\\nas the correct answer). This schedule is for\\nsyringing is done.\\nconventional cataract surgery (with sutures).\\nD. Slit lamp examination of anterior\\nIn case of sutureless cataract surgery\\nsegment of eye:\\nwith phaco, refraction can be done after\\nw Presence of uveitis. 1–2 weeks.10 Review of Ophthalmology\\nSmall Incision Cataract Surgery Advantages:\\n(SICS)\\n1. Normal life activity regained faster.\\nECCE can also be done through self-sealing 2. Minimum post-operative astigmatism.\\nsmall incision, which does not need any\\nNote:\\nsutures. This sutureless surgery can be either\\n\\uf077 Vitreous haemorrhage and RD occurs\\nby phaco machine, which is called Phaco-\\nmore commonly in ICCE due to vitreous\\nemulsification or manually called Non-phaco\\ntraction. In ECCE since the posterior\\nsutureless cataract surgery.\\ncapsule (PC) is intact this complication\\n1. Manual small incision cataract\\nis less common.\\nsurgery:\\n\\uf077 Cystoid macular edema (CME) after\\nProcedure:\\ncataract surgery (called Irvine-Gass\\n(a) Triplanar scleral tunnel is made. syndrome) is attributed to both vitreous\\ntraction and prostaglandins released\\n(b) Anterior chamber is formed by\\nduring inflammation. As there is an\\nviscoelastic.\\nintact PC in ECCE hence again this\\n(c) Anterior capsulotomy is done (Preferably\\ncomplication is less common in ECCE.\\nCCC, i.e., continues curvilinear capsu-\\n\\uf077 IOL implantation in diabetic patient\\nlorrhexis or can opener).\\nshould be done after PRP (pan-retinal\\n(d) Hydrodissection and hydrodelineation is\\nphotocoagulation). But if the patient has\\ndone.\\ndeveloped diabetic cataract then IOL\\n(e) Nucleus is first prolapsed in the anterior implantation becomes a prerequisite for\\nchamber and then prolapsed out by proper visualization of fundus and PRP.\\nviscoelastic called viscoexpression.\\n\\uf077 An uncontrolled glaucoma is a contra-\\n(f) Cortical matter is aspirated and IOL indication for IOL implantation surgery.\\nimplanted. If we have to implant a First the glaucoma has to be controlled\\nnonfoldable lens then we need to extend as increased intraocular tension can\\nour scleral incision. lead to per-operative complications.\\n(g) No sutures are required as it is a self- \\uf077 Phacoemulsification is less preferred in\\nsealing incision. black cataract, i.e., grade 4 or grade 5\\nnuclear cataract.\\n2. Phacoemulsification:\\nMANAGEMENT OF PEDIATRIC\\nProcedure:\\nCATARACT\\n(a) Scleral tunnel with an external\\nincision of 3 mm to 3.5 mm is made/ In both bilateral and unilateral cases,\\nCorneal incision can also be made. primary implantation is indicated as soon as\\nthe patient is fit for anesthesia, ideally\\n(b) Circular curvilinear capsulorrhexis\\nbetween 2 and 3 months of age. The earlier\\ndone.\\nthe surgery is done, the better is the chance\\n(c) Hydrodissection and Hydrodelineation\\nthat deep amblyopia can be overcome as the\\ndone and lens material emulsified and\\nvisual reflexes develop by 5–6 months of age.\\naspirated along with the cortical\\nUnilateral cases are particularly at a risk of\\nmatters.\\ndeveloping deep amblyopia and hence dealt\\n(d) Foldable IOL implanted. with more seriously.Diseases of Lens 11\\nManagement can be divided according to two \\uf077 PC-IOL–It is of two types J-loop or\\nage groups: C-loop. C-loop is preferred. Best option for\\n1. Patients younger than 2 years. IOL implantation is posterior capsule as it\\nis most physiological.\\n2. Patients between 2–8 years.\\nBiometry:\\nGuidelines for the Choice of\\nIntraocular Lens The process of calculating the power of\\nintraocular IOL is known as biometry.\\n1. < 2 years old:\\nIt is done by SRK formula:\\n\\uf077 Do biometry and undercorrect by 20%.\\nSRK–I\\nOR\\n\\uf077 Use axial length measurements only. P = A – 2.5 L – 0.9 K\\nA is a constant depending on the surgeon and\\nAxial length IOL diopteric power\\nthe type of IOL.\\n17 mm 28 D\\nL is the axial length and is measured by\\n18 mm 27 D USG-A scan.\\n19 mm 26 D K is the keratometry reading (Average of K1\\n20 mm 24 D and K2) and is measured by Keratometer.\\n21 mm 22 D SRK-II: It is the corrected form of SRK-I,\\ntaking into account any unusual axial length\\n2. Between 2 years to 8 years: Do biometry\\nof the eye (i.e., too long or too short).\\nand undercorrect by 10%.\\nHence preferred choice is SRK-II.\\nThe undercorrection of the IOL power is done\\nto take into account the myopic shift of power COMPLICATIONS OF CATARACT\\nas the child grows.\\nSURGERY\\nThe total diameter of IOL in children should\\nOperative:\\nnot exceed 12 mm.\\n1. SR muscle laceration.\\nIOLS\\n2. Excessive bleeding during conjunctival flap\\npreparation.\\nMaterials:\\n3. Irregular incision.\\n\\uf077 Commonly used material of IOL (Non-\\n4. Injury to cornea, DM-detachment.\\nfoldable) is PMMA (Polymethylmetha-\\ncrylate). 5. Iris injury and iridodialysis.\\n\\uf077 Materials for foldable IOLs are: Hydrogel, 6. Accidental rupture of lens capsule.\\nSilicon and Acrylic.\\n7. Vitreous loss.\\nTypes of Non-Foldable IOLs: 8. Expulsive haemorrhage.\\n\\uf077 AC-IOL-Kelman multiplex. Early Post-Operative:\\n\\uf077 Iris-supported lens–Worst’s or Singh’s iris 1. Hyphema.\\nclaw lenses. 2. Iritis and iris prolapse.12 Review of Ophthalmology\\n3. Striate keratopathy. Types:\\n4. Flat anterior chamber. a. Sunset syndrome: Inferior subluxation\\nof IOL.\\n5. Bacterial endophthalmitis: Painful.\\nb. Sunrise syndrome: Superior subluxa-\\n6. Glaucoma due to retained viscoelastic.\\ntion of IOL.\\nLate Post-Operative:\\nc. Lost lens syndrome: Complete dislo-\\n(All are painless conditions) cation of IOL in the vitreous cavity.\\n1. CME. d. Windshield wiper syndrome: It denotes\\n2. RD. the movement of the superior haptic\\nwith the movement of the head. This\\n3. Epithelial in-growth.\\noccurs due to implantation of a very\\n4. Fibrous down growth. small lens in the ciliary sulcus.\\n5. After cataract. 8. Toxic lens syndrome: It indicates the uveal\\nRD occurs more commonly in aphakes inflammation which occurs due to lens\\ncompared to pseudophakes. The patient will material or the ethylene gas used to sterilise\\npresent as floaters and sudden loss of vision. the lens.\\n\\uf077 Most dreaded complication of\\nIOL-Related\\ncataract surgery is–Endophthal-\\n1. Corneal endothelial damage. mitis. It may be early onset or late\\nonset.\\n2. Uveitis: Mainly with AC-IOLs and iris-claw\\nlenses. Early Onset:\\n3. Secondary glaucoma. 1. Staphylococcal epidermidis is the\\nmost common organism isolated\\n4. Anisocoria (difference in size of pupil):\\nfrom post-surgical endophthalmitis.\\nCommonly when iris claw lenses are\\nimplanted. It can also occur in PC-IOL 2. Other organisms are: Staph aureus,\\nimplantation when there is iris hook by the Pseudomonas and Proteus.\\nhaptic. Late Onset:\\n5. Cystoid macular edema: Its incidence is 1. Propionobacterium acne.\\nspecially more in iris-claw lenses or AC-\\n2. Fungal infection.\\nIOLs when, there is no posterior capsule.\\n\\uf077 Most common late complication of\\nCME after cataract surgery is known as\\ncataract surgery is–After cataract\\n“Irvine–Gass Syndrome”.\\nor PCO.\\n6. UGH syndrome:\\nAfter Cataract\\n\\uf077 Uveitis/glaucoma/hyphema syndrome.\\n\\uf077 Occurs with rigid AC-IOLs. \\uf077 It denotes opacification of posterior capsule\\nafter cataract surgery.\\n7. Malposition of IOLs:\\n\\uf077 It is also known as secondary cataract.\\nIt causes:\\n\\uf077 It may present with various morphological\\na. Astigmatism, if IOL is tilted.\\nforms namely–Elschnig’s pearls,\\nb. Decentration of IOL leads to glare, Soemmering’s rings or just a diffuse\\nhalos, rings of light, uniocular diplopia. opacification.Diseases of Lens 13\\nw Treatment: Homocystinuria: It is an inborn error of\\nmetabolism caused by deficiency of enzyme –\\n(a) Surgical capsulotomy by zeiglers knife.\\nCystathione synthetase leading to increased\\n(b) Laser capsulotomy by Nd-Yag laser\\nlevel of homocysteine in plasma and urine. It\\nwhich is a photodisruptive or cutting\\nis characterized by skeletal deformities\\nlaser.\\nsimilar to Marfan’s syndrome and mental\\nhandicap.\\nDISPLACEMENT OF THE LENS\\nOcular Features:\\nSubluxation is partial dislocation of lens.\\n1. Ectopia lentis in inferonasal direction.\\nCauses:\\n2. Angle anomaly leading to glaucoma or pupil\\n1. Congenital—(a) Simple ectopia lentis block glaucoma due to incarceration of lens\\n(Symmetrical and upwards) (b) Ectopia in the pupil.\\nlentis et pupillae (slit shaped pupil displaced\\n3. Loss of accommodation due to disintegration\\nin opposite direction) (c) Ectopia lentis with\\nof zonules.\\nsystemic anomalies (Marfan’s syndrome,\\nHomocystinuria, Weil-Marchesani syndrome Ehlers-Danlos Syndrome\\nand Ehlers-Danlos syndrome).\\n1. Blue sclera.\\n2. Traumatic—Blunt trauma.\\n2. Ectopia lentis.\\n3. Consecutive or Spontaneous—Hyper-\\nmature cataract, Buphthalmos, High Congenital Anomalies of Lens\\nmyopia and Uveitis.\\nA. Colobomas:\\nMarfan’s Syndrome 1. Mostly occurs inferiorly.\\n2. May be associated with defect in iris\\n1. Megalocornea and Cornea plana.\\nand choroid.\\n2. Angle anomaly leading to glaucoma. {M}\\nB. Congenital Ectopia Lentis.\\n3. Upward/temporal ectopia lentis.\\nC. Lenticonus: It is the conical protrusion of\\n4. Difficulty in pupil dilatation. the lens.\\n5. Lattice degeneration and rhegmatogenous\\nAnterior Lenticonus:\\nretinal detachment.\\nAnterior lenticonus occurs in Alport’s\\nThe most PROMINENT manifestation of\\nSyndrome.\\nMarfan’s syndrome is Megalocornea.\\nAlport’s Syndrome (Familial haemorrhagic\\nThe most COMMON manifestation of\\nnephritis)\\nMarfan’s syndrome is Ectopia lentis.\\nSystemic Features:\\nWeil-Marchesani Syndrome 1. Renal failure.\\n1. Microspherophakia. 2. Hearing loss.\\n2. Pupillary block glaucoma. Ocular Features:\\n3. Ectopia lentis in inferior and forward 1. Posterior polymorphous corneal\\ndirection. dystrophy.14 Review of Ophthalmology\\n2. Juvenile arcus. E. Lentiglobus: It is a generalised hemis-\\npherical deformity of the lens. Posterior\\n3. Pigment dispersion.\\nlentiglobus is seen in Lowe’s syndrome.\\n4. Anterior lenticonus.\\nF. Microphakia: Lens is small in size. It is\\n5. Retinal pigmentary changes.\\nseen in Lowe’s syndrome.\\nPosterior Lenticonus: G. Microspherophakia: Small and spherical lens.\\nIt occurs in Lowe’s Syndrome–i.e., Oculo- Occurs in:\\ncerebrorenal syndrome. 1. Weil-Marchesani syndrome.\\nD. Congenital cataract. 2. Hyperlysinaemia.\\nNEET DRILL\\n1. The equatorial diameter of the lens is 15. Lens nucleus is divided as–embryonic\\n9–10 mm. nucleus–1-3 months of gestation/fetal\\nnucleus–3 months–birth/infantile nucleus-\\n2. The equatorial diameter of the lens at birth\\nbirth–puberty/adult nucleus–in adult life.\\nis 6.5 mm.\\n16. Lens is 66% water and 33% protein.\\n3. Thickness of the lens, i.e., the AP\\ndiameter is 3.5 mm–5 mm. 17. Antioxidative system of lens constitutes–\\nvitamin C, i.e., ascorbic acid, glutathione,\\n4. Radius of curvature of the anterior surface\\nmyoinositol that helps in ascorbic acid\\nis 10 mm.\\ncarrier system and detoxifying enzymes\\n5. Radius of curvature of the posterior\\nlike catalase and superoxide dismutase.\\nsurface is 6 mm.\\n18. Respiratory coefficient of the lens is: 1.\\n6. Refractive index of the lens is 1.39.\\n19. Microwave radiations can also cause\\n7. Refractive power is 16 D–17 D.\\ncataract, proved in animals and claimed\\n8. Accommodative power of the lens at birth: that there is maximum probability for\\n14–16 D at birth, 7–8 D at 25 years and humans also. It occurs in due to rise in\\n1–2 D at 50 years of age. temperature.\\n9. The pigments responsible for the color 20. Length of incision in phacoemulsification\\nchange in the process of development of is 2.75–3.2 mm.\\ncataract are urochrome and melanin. 21. Frequency of the phacoprobe is 40 khz.\\n10. Snowflake or snowstorm cataract is more 22. Most commonly used foldable IOL is\\ncommon in type 1 diabetes. acrylic.\\n11. Cataract in diabetes is due to sorbital 23. MICS, i.e., minimal incision cataract\\naccumulation in the lens and sorbital is surgery: incision is between 1.8 and 2.4 mm.\\nvery hyperosmotic.\\n24. Phaconit: Incision length is 0.9 mm.\\n12. Lens capsule is thinnest at posterior pole\\n25. Father of phaco: Charles D Kelman.\\nwith the thickness of 4 microns.\\n26. Causes of ectopia lentis: Marfan’s syndrome,\\n13. Lens capsule is thickest at equatorial\\nhomocystinuria, Weil-Marchesani, Ehlers-\\nregion and is 23 microns in thickness.\\nDanlos, sulphite oxidase deficiency,\\n14. Suspensory ligament or zonules have a hyperlysenemia, Refsum’s disease and\\ndiameter of 0.35–1 microns. Sturge-Weber syndrome.Diseases of Lens 15\\n27. Anterior lenticonus: Alport’s syndrome, 33. The genes responsible for congenital\\nWaardenburg syndrome. cataract: CRY, i.e., crystallines, Cx, i.e.,\\n28. Posterior lenticonus: Lowe’s syndrome. connexins and MIP, i.e., Major Intrinsic\\n29. Expulsive haemorrhage after cataract Protein.\\nsurgery occurs due to bleeding from the\\n34. The most recent in cataract surgery is\\nposterior ciliary arteries.\\nFemtolaser cataract surgery called LACS,\\n30. The size of opening of posterior capsulo- i.e., laser assisted cataract surgery.\\ntomy done by NdYAG laser ranges from\\n35. Femtolaser is an ultrafast laser, with pulse\\n2–3 mm to 5–6 mm.\\nduration in femtosecond, i.e., 10–15.\\n31. The insoluble proteins raised in a\\ncataractous lens are: HM3, HM4. 36. Minimum chance of after cataract is seen\\n32. In nuclear cataract, it is HM4. with Acrylic Hydrophobic IOLSs.\\n'" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "json_file[chapter_names[0]]['C H A P T E R']['content']" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Error in Recent Advances. Error is 'content'\n" ] } ], "source": [ "for chapter in chapter_names:\n", " try:\n", " text = json_file[chapter]['C H A P T E R']['content']\n", " except Exception as e:\n", " print(f\"Error in {chapter}. Error is {e}\")\n", " # print(type(text))\n", " with open(f\"data/book/{chapter}\", \"w+\") as f:\n", " f.write(text.replace(\"\\n\", \" \"))" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from demo_rag_gpt_4 import api_call" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "question = \"Transport of ascorbic acid to lens is done by:\\nA. Myoinositol\\nB. Choline\\nC. Taurine\\nD. Na/K ATPase\"" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "ename": "TypeError", "evalue": "api_call() got an unexpected keyword argument 'service'", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", "\u001b[1;32m/Users/aakashbhatnagar/Documents/masters/ophthal_llm/temp.ipynb Cell 23\u001b[0m line \u001b[0;36m1\n\u001b[0;32m----> 1\u001b[0m answer \u001b[39m=\u001b[39m api_call(\n\u001b[1;32m 2\u001b[0m input_data\u001b[39m=\u001b[39;49mquestion,\n\u001b[1;32m 3\u001b[0m service \u001b[39m=\u001b[39;49m \u001b[39m\"\u001b[39;49m\u001b[39mopenai\u001b[39;49m\u001b[39m\"\u001b[39;49m,\n\u001b[1;32m 4\u001b[0m top_k\u001b[39m=\u001b[39;49m\u001b[39m20\u001b[39;49m,\n\u001b[1;32m 5\u001b[0m prompt_file\u001b[39m=\u001b[39;49m\u001b[39m\"\u001b[39;49m\u001b[39m/projectnb/ds549/students/aakash07/DrVai/prompts/version_1.txt\u001b[39;49m\u001b[39m\"\u001b[39;49m,\n\u001b[1;32m 6\u001b[0m )\n", "\u001b[0;31mTypeError\u001b[0m: api_call() got an unexpected keyword argument 'service'" ] } ], "source": [ "answer = api_call(\n", " input_data=question,\n", " service = \"openai\",\n", " top_k=20,\n", " prompt_file=\"/projectnb/ds549/students/aakash07/DrVai/prompts/version_1.txt\",\n", ")" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Answer for the question is A.\n", "\n", "Explanation: According to the documents, myoinositol participates in ascorbic acid transport in the lens.\n", "\n", "Documents used for reference are\n", "\n", "Document: 1.\n", ". Its levels are markedly CATARACT reduced in cataract. It is a precursor of membrane phosphoinositides which are Etiology involved in Na/Ka ATPase function. It also participates in ascorbic acid transport in a. Heredity: Usually dominant. the lens. b. Maternal factors: Lens 1. Malnutrition\n", "\n", "Document: 2.\n", ". 3. Thickness of the lens, i.e., the AP diameter is 3.5 mm–5 mm. 17. Antioxidative system of lens constitutes– vitamin C, i.e., ascorbic acid, glutathione, 4. Radius of curvature of the anterior surface myoinositol that helps in ascorbic acid is 10 mm. carrier system and detoxifying enzymes 5\n" ] } ], "source": [ "print(answer)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "import json" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "ans = json.loads(answer)" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [], "source": [ "l = ans[\"Doc_no\"].replace(\" \",\"\").split(\",\")" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [], "source": [ "l = [int(i) for i in l]" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "question = \"Transport of ascorbic acid to lens is done by:\\nA. Myoinositol\\nB. Choline\\nC. Taurine\\nD. Na/K ATPase\"" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Transport of ascorbic acid to lens is done by:\n", "A. Myoinositol\n", "B. Choline\n", "C. Taurine\n", "D. Na/K ATPase\n" ] } ], "source": [ "print(question)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "ename": "AuthenticationError", "evalue": "Incorrect API key provided: sk-PzTV1***************************************uuhw. You can find your API key at https://platform.openai.com/account/api-keys.", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mAuthenticationError\u001b[0m Traceback (most recent call last)", "\u001b[1;32m/Users/aakashbhatnagar/Documents/masters/ophthal_llm/temp.ipynb Cell 31\u001b[0m line \u001b[0;36m1\n\u001b[0;32m----> 1\u001b[0m answer \u001b[39m=\u001b[39m api_call(\n\u001b[1;32m 2\u001b[0m input_data\u001b[39m=\u001b[39;49mquestion,history\u001b[39m=\u001b[39;49m{})\n", "File \u001b[0;32m~/Documents/masters/ophthal_llm/demo_rag_gpt_4.py:69\u001b[0m, in \u001b[0;36mapi_call\u001b[0;34m(input_data, history)\u001b[0m\n\u001b[1;32m 66\u001b[0m llm \u001b[39m=\u001b[39m ChatOpenAI(openai_api_key\u001b[39m=\u001b[39mos\u001b[39m.\u001b[39mgetenv(\u001b[39m\"\u001b[39m\u001b[39mOPENAI_API_KEY\u001b[39m\u001b[39m\"\u001b[39m), model\u001b[39m=\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mgpt-4\u001b[39m\u001b[39m\"\u001b[39m, temperature\u001b[39m=\u001b[39m\u001b[39m0.9\u001b[39m)\n\u001b[1;32m 68\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[0;32m---> 69\u001b[0m output \u001b[39m=\u001b[39m llm(complete_prompt)\u001b[39m.\u001b[39mcontent\n\u001b[1;32m 70\u001b[0m \u001b[39mexcept\u001b[39;00m ApiException \u001b[39mas\u001b[39;00m e:\n\u001b[1;32m 71\u001b[0m \u001b[39mprint\u001b[39m(\u001b[39mf\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mAPI Error: \u001b[39m\u001b[39m{\u001b[39;00me\u001b[39m}\u001b[39;00m\u001b[39m\"\u001b[39m)\n", "File \u001b[0;32m~/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/langchain/chat_models/base.py:600\u001b[0m, in \u001b[0;36mBaseChatModel.__call__\u001b[0;34m(self, messages, stop, callbacks, **kwargs)\u001b[0m\n\u001b[1;32m 593\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m__call__\u001b[39m(\n\u001b[1;32m 594\u001b[0m \u001b[39mself\u001b[39m,\n\u001b[1;32m 595\u001b[0m messages: List[BaseMessage],\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 598\u001b[0m \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs: Any,\n\u001b[1;32m 599\u001b[0m ) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m BaseMessage:\n\u001b[0;32m--> 600\u001b[0m generation \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mgenerate(\n\u001b[1;32m 601\u001b[0m [messages], stop\u001b[39m=\u001b[39;49mstop, callbacks\u001b[39m=\u001b[39;49mcallbacks, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs\n\u001b[1;32m 602\u001b[0m )\u001b[39m.\u001b[39mgenerations[\u001b[39m0\u001b[39m][\u001b[39m0\u001b[39m]\n\u001b[1;32m 603\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39misinstance\u001b[39m(generation, ChatGeneration):\n\u001b[1;32m 604\u001b[0m \u001b[39mreturn\u001b[39;00m generation\u001b[39m.\u001b[39mmessage\n", "File \u001b[0;32m~/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/langchain/chat_models/base.py:349\u001b[0m, in \u001b[0;36mBaseChatModel.generate\u001b[0;34m(self, messages, stop, callbacks, tags, metadata, run_name, **kwargs)\u001b[0m\n\u001b[1;32m 347\u001b[0m \u001b[39mif\u001b[39;00m run_managers:\n\u001b[1;32m 348\u001b[0m run_managers[i]\u001b[39m.\u001b[39mon_llm_error(e)\n\u001b[0;32m--> 349\u001b[0m \u001b[39mraise\u001b[39;00m e\n\u001b[1;32m 350\u001b[0m flattened_outputs \u001b[39m=\u001b[39m [\n\u001b[1;32m 351\u001b[0m LLMResult(generations\u001b[39m=\u001b[39m[res\u001b[39m.\u001b[39mgenerations], llm_output\u001b[39m=\u001b[39mres\u001b[39m.\u001b[39mllm_output)\n\u001b[1;32m 352\u001b[0m \u001b[39mfor\u001b[39;00m res \u001b[39min\u001b[39;00m results\n\u001b[1;32m 353\u001b[0m ]\n\u001b[1;32m 354\u001b[0m llm_output \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_combine_llm_outputs([res\u001b[39m.\u001b[39mllm_output \u001b[39mfor\u001b[39;00m res \u001b[39min\u001b[39;00m results])\n", "File \u001b[0;32m~/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/langchain/chat_models/base.py:339\u001b[0m, in \u001b[0;36mBaseChatModel.generate\u001b[0;34m(self, messages, stop, callbacks, tags, metadata, run_name, **kwargs)\u001b[0m\n\u001b[1;32m 336\u001b[0m \u001b[39mfor\u001b[39;00m i, m \u001b[39min\u001b[39;00m \u001b[39menumerate\u001b[39m(messages):\n\u001b[1;32m 337\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[1;32m 338\u001b[0m results\u001b[39m.\u001b[39mappend(\n\u001b[0;32m--> 339\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_generate_with_cache(\n\u001b[1;32m 340\u001b[0m m,\n\u001b[1;32m 341\u001b[0m stop\u001b[39m=\u001b[39;49mstop,\n\u001b[1;32m 342\u001b[0m run_manager\u001b[39m=\u001b[39;49mrun_managers[i] \u001b[39mif\u001b[39;49;00m run_managers \u001b[39melse\u001b[39;49;00m \u001b[39mNone\u001b[39;49;00m,\n\u001b[1;32m 343\u001b[0m \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs,\n\u001b[1;32m 344\u001b[0m )\n\u001b[1;32m 345\u001b[0m )\n\u001b[1;32m 346\u001b[0m \u001b[39mexcept\u001b[39;00m \u001b[39mBaseException\u001b[39;00m \u001b[39mas\u001b[39;00m e:\n\u001b[1;32m 347\u001b[0m \u001b[39mif\u001b[39;00m run_managers:\n", "File \u001b[0;32m~/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/langchain/chat_models/base.py:492\u001b[0m, in \u001b[0;36mBaseChatModel._generate_with_cache\u001b[0;34m(self, messages, stop, run_manager, **kwargs)\u001b[0m\n\u001b[1;32m 488\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mValueError\u001b[39;00m(\n\u001b[1;32m 489\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mAsked to cache, but no cache found at `langchain.cache`.\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[1;32m 490\u001b[0m )\n\u001b[1;32m 491\u001b[0m \u001b[39mif\u001b[39;00m new_arg_supported:\n\u001b[0;32m--> 492\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_generate(\n\u001b[1;32m 493\u001b[0m messages, stop\u001b[39m=\u001b[39;49mstop, run_manager\u001b[39m=\u001b[39;49mrun_manager, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs\n\u001b[1;32m 494\u001b[0m )\n\u001b[1;32m 495\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[1;32m 496\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_generate(messages, stop\u001b[39m=\u001b[39mstop, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs)\n", "File \u001b[0;32m~/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/langchain/chat_models/openai.py:360\u001b[0m, in \u001b[0;36mChatOpenAI._generate\u001b[0;34m(self, messages, stop, run_manager, stream, **kwargs)\u001b[0m\n\u001b[1;32m 358\u001b[0m message_dicts, params \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_create_message_dicts(messages, stop)\n\u001b[1;32m 359\u001b[0m params \u001b[39m=\u001b[39m {\u001b[39m*\u001b[39m\u001b[39m*\u001b[39mparams, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs}\n\u001b[0;32m--> 360\u001b[0m response \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mcompletion_with_retry(\n\u001b[1;32m 361\u001b[0m messages\u001b[39m=\u001b[39;49mmessage_dicts, run_manager\u001b[39m=\u001b[39;49mrun_manager, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mparams\n\u001b[1;32m 362\u001b[0m )\n\u001b[1;32m 363\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_create_chat_result(response)\n", "File \u001b[0;32m~/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/langchain/chat_models/openai.py:299\u001b[0m, in \u001b[0;36mChatOpenAI.completion_with_retry\u001b[0;34m(self, run_manager, **kwargs)\u001b[0m\n\u001b[1;32m 295\u001b[0m \u001b[39m@retry_decorator\u001b[39m\n\u001b[1;32m 296\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m_completion_with_retry\u001b[39m(\u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs: Any) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m Any:\n\u001b[1;32m 297\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mclient\u001b[39m.\u001b[39mcreate(\u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs)\n\u001b[0;32m--> 299\u001b[0m \u001b[39mreturn\u001b[39;00m _completion_with_retry(\u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n", "File \u001b[0;32m~/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/tenacity/__init__.py:289\u001b[0m, in \u001b[0;36mBaseRetrying.wraps..wrapped_f\u001b[0;34m(*args, **kw)\u001b[0m\n\u001b[1;32m 287\u001b[0m \u001b[39m@functools\u001b[39m\u001b[39m.\u001b[39mwraps(f)\n\u001b[1;32m 288\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mwrapped_f\u001b[39m(\u001b[39m*\u001b[39margs: t\u001b[39m.\u001b[39mAny, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkw: t\u001b[39m.\u001b[39mAny) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m t\u001b[39m.\u001b[39mAny:\n\u001b[0;32m--> 289\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m(f, \u001b[39m*\u001b[39;49margs, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkw)\n", "File \u001b[0;32m~/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/tenacity/__init__.py:379\u001b[0m, in \u001b[0;36mRetrying.__call__\u001b[0;34m(self, fn, *args, **kwargs)\u001b[0m\n\u001b[1;32m 377\u001b[0m retry_state \u001b[39m=\u001b[39m RetryCallState(retry_object\u001b[39m=\u001b[39m\u001b[39mself\u001b[39m, fn\u001b[39m=\u001b[39mfn, args\u001b[39m=\u001b[39margs, kwargs\u001b[39m=\u001b[39mkwargs)\n\u001b[1;32m 378\u001b[0m \u001b[39mwhile\u001b[39;00m \u001b[39mTrue\u001b[39;00m:\n\u001b[0;32m--> 379\u001b[0m do \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49miter(retry_state\u001b[39m=\u001b[39;49mretry_state)\n\u001b[1;32m 380\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39misinstance\u001b[39m(do, DoAttempt):\n\u001b[1;32m 381\u001b[0m \u001b[39mtry\u001b[39;00m:\n", "File \u001b[0;32m~/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/tenacity/__init__.py:314\u001b[0m, in \u001b[0;36mBaseRetrying.iter\u001b[0;34m(self, retry_state)\u001b[0m\n\u001b[1;32m 312\u001b[0m is_explicit_retry \u001b[39m=\u001b[39m fut\u001b[39m.\u001b[39mfailed \u001b[39mand\u001b[39;00m \u001b[39misinstance\u001b[39m(fut\u001b[39m.\u001b[39mexception(), TryAgain)\n\u001b[1;32m 313\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mnot\u001b[39;00m (is_explicit_retry \u001b[39mor\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mretry(retry_state)):\n\u001b[0;32m--> 314\u001b[0m \u001b[39mreturn\u001b[39;00m fut\u001b[39m.\u001b[39;49mresult()\n\u001b[1;32m 316\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mafter \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n\u001b[1;32m 317\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mafter(retry_state)\n", "File \u001b[0;32m~/miniconda3/lib/python3.10/concurrent/futures/_base.py:451\u001b[0m, in \u001b[0;36mFuture.result\u001b[0;34m(self, timeout)\u001b[0m\n\u001b[1;32m 449\u001b[0m \u001b[39mraise\u001b[39;00m CancelledError()\n\u001b[1;32m 450\u001b[0m \u001b[39melif\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_state \u001b[39m==\u001b[39m FINISHED:\n\u001b[0;32m--> 451\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m__get_result()\n\u001b[1;32m 453\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_condition\u001b[39m.\u001b[39mwait(timeout)\n\u001b[1;32m 455\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_state \u001b[39min\u001b[39;00m [CANCELLED, CANCELLED_AND_NOTIFIED]:\n", "File \u001b[0;32m~/miniconda3/lib/python3.10/concurrent/futures/_base.py:403\u001b[0m, in \u001b[0;36mFuture.__get_result\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 401\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_exception:\n\u001b[1;32m 402\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[0;32m--> 403\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_exception\n\u001b[1;32m 404\u001b[0m \u001b[39mfinally\u001b[39;00m:\n\u001b[1;32m 405\u001b[0m \u001b[39m# Break a reference cycle with the exception in self._exception\u001b[39;00m\n\u001b[1;32m 406\u001b[0m \u001b[39mself\u001b[39m \u001b[39m=\u001b[39m \u001b[39mNone\u001b[39;00m\n", "File \u001b[0;32m~/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/tenacity/__init__.py:382\u001b[0m, in \u001b[0;36mRetrying.__call__\u001b[0;34m(self, fn, *args, **kwargs)\u001b[0m\n\u001b[1;32m 380\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39misinstance\u001b[39m(do, DoAttempt):\n\u001b[1;32m 381\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[0;32m--> 382\u001b[0m result \u001b[39m=\u001b[39m fn(\u001b[39m*\u001b[39;49margs, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n\u001b[1;32m 383\u001b[0m \u001b[39mexcept\u001b[39;00m \u001b[39mBaseException\u001b[39;00m: \u001b[39m# noqa: B902\u001b[39;00m\n\u001b[1;32m 384\u001b[0m retry_state\u001b[39m.\u001b[39mset_exception(sys\u001b[39m.\u001b[39mexc_info()) \u001b[39m# type: ignore[arg-type]\u001b[39;00m\n", "File \u001b[0;32m~/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/langchain/chat_models/openai.py:297\u001b[0m, in \u001b[0;36mChatOpenAI.completion_with_retry.._completion_with_retry\u001b[0;34m(**kwargs)\u001b[0m\n\u001b[1;32m 295\u001b[0m \u001b[39m@retry_decorator\u001b[39m\n\u001b[1;32m 296\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m_completion_with_retry\u001b[39m(\u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs: Any) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m Any:\n\u001b[0;32m--> 297\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mclient\u001b[39m.\u001b[39;49mcreate(\u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n", "File \u001b[0;32m~/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/openai/api_resources/chat_completion.py:25\u001b[0m, in \u001b[0;36mChatCompletion.create\u001b[0;34m(cls, *args, **kwargs)\u001b[0m\n\u001b[1;32m 23\u001b[0m \u001b[39mwhile\u001b[39;00m \u001b[39mTrue\u001b[39;00m:\n\u001b[1;32m 24\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[0;32m---> 25\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39msuper\u001b[39;49m()\u001b[39m.\u001b[39;49mcreate(\u001b[39m*\u001b[39;49margs, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n\u001b[1;32m 26\u001b[0m \u001b[39mexcept\u001b[39;00m TryAgain \u001b[39mas\u001b[39;00m e:\n\u001b[1;32m 27\u001b[0m \u001b[39mif\u001b[39;00m timeout \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m \u001b[39mand\u001b[39;00m time\u001b[39m.\u001b[39mtime() \u001b[39m>\u001b[39m start \u001b[39m+\u001b[39m timeout:\n", "File \u001b[0;32m~/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/openai/api_resources/abstract/engine_api_resource.py:155\u001b[0m, in \u001b[0;36mEngineAPIResource.create\u001b[0;34m(cls, api_key, api_base, api_type, request_id, api_version, organization, **params)\u001b[0m\n\u001b[1;32m 129\u001b[0m \u001b[39m@classmethod\u001b[39m\n\u001b[1;32m 130\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mcreate\u001b[39m(\n\u001b[1;32m 131\u001b[0m \u001b[39mcls\u001b[39m,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 138\u001b[0m \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mparams,\n\u001b[1;32m 139\u001b[0m ):\n\u001b[1;32m 140\u001b[0m (\n\u001b[1;32m 141\u001b[0m deployment_id,\n\u001b[1;32m 142\u001b[0m engine,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 152\u001b[0m api_key, api_base, api_type, api_version, organization, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mparams\n\u001b[1;32m 153\u001b[0m )\n\u001b[0;32m--> 155\u001b[0m response, _, api_key \u001b[39m=\u001b[39m requestor\u001b[39m.\u001b[39;49mrequest(\n\u001b[1;32m 156\u001b[0m \u001b[39m\"\u001b[39;49m\u001b[39mpost\u001b[39;49m\u001b[39m\"\u001b[39;49m,\n\u001b[1;32m 157\u001b[0m url,\n\u001b[1;32m 158\u001b[0m params\u001b[39m=\u001b[39;49mparams,\n\u001b[1;32m 159\u001b[0m headers\u001b[39m=\u001b[39;49mheaders,\n\u001b[1;32m 160\u001b[0m stream\u001b[39m=\u001b[39;49mstream,\n\u001b[1;32m 161\u001b[0m request_id\u001b[39m=\u001b[39;49mrequest_id,\n\u001b[1;32m 162\u001b[0m request_timeout\u001b[39m=\u001b[39;49mrequest_timeout,\n\u001b[1;32m 163\u001b[0m )\n\u001b[1;32m 165\u001b[0m \u001b[39mif\u001b[39;00m stream:\n\u001b[1;32m 166\u001b[0m \u001b[39m# must be an iterator\u001b[39;00m\n\u001b[1;32m 167\u001b[0m \u001b[39massert\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39misinstance\u001b[39m(response, OpenAIResponse)\n", "File \u001b[0;32m~/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/openai/api_requestor.py:299\u001b[0m, in \u001b[0;36mAPIRequestor.request\u001b[0;34m(self, method, url, params, headers, files, stream, request_id, request_timeout)\u001b[0m\n\u001b[1;32m 278\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mrequest\u001b[39m(\n\u001b[1;32m 279\u001b[0m \u001b[39mself\u001b[39m,\n\u001b[1;32m 280\u001b[0m method,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 287\u001b[0m request_timeout: Optional[Union[\u001b[39mfloat\u001b[39m, Tuple[\u001b[39mfloat\u001b[39m, \u001b[39mfloat\u001b[39m]]] \u001b[39m=\u001b[39m \u001b[39mNone\u001b[39;00m,\n\u001b[1;32m 288\u001b[0m ) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m Tuple[Union[OpenAIResponse, Iterator[OpenAIResponse]], \u001b[39mbool\u001b[39m, \u001b[39mstr\u001b[39m]:\n\u001b[1;32m 289\u001b[0m result \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mrequest_raw(\n\u001b[1;32m 290\u001b[0m method\u001b[39m.\u001b[39mlower(),\n\u001b[1;32m 291\u001b[0m url,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 297\u001b[0m request_timeout\u001b[39m=\u001b[39mrequest_timeout,\n\u001b[1;32m 298\u001b[0m )\n\u001b[0;32m--> 299\u001b[0m resp, got_stream \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_interpret_response(result, stream)\n\u001b[1;32m 300\u001b[0m \u001b[39mreturn\u001b[39;00m resp, got_stream, \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mapi_key\n", "File \u001b[0;32m~/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/openai/api_requestor.py:710\u001b[0m, in \u001b[0;36mAPIRequestor._interpret_response\u001b[0;34m(self, result, stream)\u001b[0m\n\u001b[1;32m 702\u001b[0m \u001b[39mreturn\u001b[39;00m (\n\u001b[1;32m 703\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_interpret_response_line(\n\u001b[1;32m 704\u001b[0m line, result\u001b[39m.\u001b[39mstatus_code, result\u001b[39m.\u001b[39mheaders, stream\u001b[39m=\u001b[39m\u001b[39mTrue\u001b[39;00m\n\u001b[1;32m 705\u001b[0m )\n\u001b[1;32m 706\u001b[0m \u001b[39mfor\u001b[39;00m line \u001b[39min\u001b[39;00m parse_stream(result\u001b[39m.\u001b[39miter_lines())\n\u001b[1;32m 707\u001b[0m ), \u001b[39mTrue\u001b[39;00m\n\u001b[1;32m 708\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[1;32m 709\u001b[0m \u001b[39mreturn\u001b[39;00m (\n\u001b[0;32m--> 710\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_interpret_response_line(\n\u001b[1;32m 711\u001b[0m result\u001b[39m.\u001b[39;49mcontent\u001b[39m.\u001b[39;49mdecode(\u001b[39m\"\u001b[39;49m\u001b[39mutf-8\u001b[39;49m\u001b[39m\"\u001b[39;49m),\n\u001b[1;32m 712\u001b[0m result\u001b[39m.\u001b[39;49mstatus_code,\n\u001b[1;32m 713\u001b[0m result\u001b[39m.\u001b[39;49mheaders,\n\u001b[1;32m 714\u001b[0m stream\u001b[39m=\u001b[39;49m\u001b[39mFalse\u001b[39;49;00m,\n\u001b[1;32m 715\u001b[0m ),\n\u001b[1;32m 716\u001b[0m \u001b[39mFalse\u001b[39;00m,\n\u001b[1;32m 717\u001b[0m )\n", "File \u001b[0;32m~/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/openai/api_requestor.py:775\u001b[0m, in \u001b[0;36mAPIRequestor._interpret_response_line\u001b[0;34m(self, rbody, rcode, rheaders, stream)\u001b[0m\n\u001b[1;32m 773\u001b[0m stream_error \u001b[39m=\u001b[39m stream \u001b[39mand\u001b[39;00m \u001b[39m\"\u001b[39m\u001b[39merror\u001b[39m\u001b[39m\"\u001b[39m \u001b[39min\u001b[39;00m resp\u001b[39m.\u001b[39mdata\n\u001b[1;32m 774\u001b[0m \u001b[39mif\u001b[39;00m stream_error \u001b[39mor\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39m200\u001b[39m \u001b[39m<\u001b[39m\u001b[39m=\u001b[39m rcode \u001b[39m<\u001b[39m \u001b[39m300\u001b[39m:\n\u001b[0;32m--> 775\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mhandle_error_response(\n\u001b[1;32m 776\u001b[0m rbody, rcode, resp\u001b[39m.\u001b[39mdata, rheaders, stream_error\u001b[39m=\u001b[39mstream_error\n\u001b[1;32m 777\u001b[0m )\n\u001b[1;32m 778\u001b[0m \u001b[39mreturn\u001b[39;00m resp\n", "\u001b[0;31mAuthenticationError\u001b[0m: Incorrect API key provided: sk-PzTV1***************************************uuhw. You can find your API key at https://platform.openai.com/account/api-keys." ] } ], "source": [ "answer = api_call(\n", " input_data=question,history={})" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Answer for the question is A.\n", "\n", "Explanation: The transport of ascorbic acid to the lens is done by myoinositol. Myoinositol participates in ascorbic acid transport in the lens and is actively transported into the lens by a sodium-dependent carrier-mediated mechanism.\n", "\n", "Documents used for reference are\n", "\n", "Document: 1.\n", ". Its levels are markedly CATARACT reduced in cataract. It is a precursor of membrane phosphoinositides which are Etiology involved in Na/Ka ATPase function. It also participates in ascorbic acid transport in a. Heredity: Usually dominant. the lens. b. Maternal factors: Lens 1. Malnutrition\n", "\n", "Document: 2.\n", ". 3. Thickness of the lens, i.e., the AP diameter is 3.5 mm–5 mm. 17. Antioxidative system of lens constitutes– vitamin C, i.e., ascorbic acid, glutathione, 4. Radius of curvature of the anterior surface myoinositol that helps in ascorbic acid is 10 mm. carrier system and detoxifying enzymes 5\n", "\n", "Document: 4.\n", ". Anterior and Posterior. Its levels are reduced in patients of cataract. Most common cause of acquired cataract is senile cataract.  Myoinositol is actively transported into the lens by sodium dependent carrier mediated CONGENITAL AND DEVELOPMENTAL mechanism\n" ] } ], "source": [ "print(answer)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "import numpy as np" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [], "source": [ "pred_rag = np.load(\"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/data/answer_pred_list_rag.npy\")" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [], "source": [ "pred_rag = [i.lower() for i in pred_rag]\n", "# pred_rag = [None for i in pred_rag if len(i) == 0]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "binary_value = []\n", "for i in range(len(pred_rag[:94])):\n", " true_list = " ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['a',\n", " 'a',\n", " 'a',\n", " '',\n", " '',\n", " 'd',\n", " '',\n", " 'a',\n", " 'c',\n", " '',\n", " 'c',\n", " 'b',\n", " 'a',\n", " '',\n", " '',\n", " 'c',\n", " 'b',\n", " 'a',\n", " 'b',\n", " 'c',\n", " 'd',\n", " 'c',\n", " 'b',\n", " 'a',\n", " 'c',\n", " 'b',\n", " 'd',\n", " '',\n", " 'b',\n", " 'a',\n", " 'b',\n", " 'a',\n", " 'a',\n", " 'a, b',\n", " 'a',\n", " '',\n", " 'e',\n", " 'b',\n", " 'd',\n", " 'a, b, c, d, e',\n", " 'b',\n", " '',\n", " 'c',\n", " '',\n", " '',\n", " '',\n", " 'b',\n", " 'a',\n", " 'a',\n", " 'a',\n", " 'a',\n", " 'a',\n", " 'a, d',\n", " 'd',\n", " 'd',\n", " 'a',\n", " 'd',\n", " 'c',\n", " '',\n", " 'd',\n", " '',\n", " '',\n", " 'c',\n", " '',\n", " 'b',\n", " '',\n", " 'c',\n", " 'd',\n", " 'd',\n", " 'a',\n", " 'd',\n", " 'a',\n", " 'b',\n", " 'd',\n", " 'c',\n", " '',\n", " '',\n", " 'a',\n", " 'b',\n", " 'd',\n", " 'd',\n", " '',\n", " 'b',\n", " 'd',\n", " '',\n", " 'c',\n", " 'c',\n", " 'b',\n", " 'b',\n", " '',\n", " 'a',\n", " '',\n", " '',\n", " '',\n", " 'a',\n", " '',\n", " 'b',\n", " 'c',\n", " 'a',\n", " '',\n", " 'c',\n", " '',\n", " '',\n", " 'd',\n", " 'b',\n", " '']" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pred_rag" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [], "source": [ "from sklearn.metrics import classification_report\n", "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [], "source": [ "true_csv = pd.read_csv(\"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/data/chapter_1_mcq_true.csv\")" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [], "source": [ "true_ans = true_csv[\"answer\"].tolist()" ] }, { "cell_type": "code", "execution_count": 45, "metadata": {}, "outputs": [], "source": [ "binary_value = []\n", "binary_true = []\n", "for i in range(len(pred_rag[:94])):\n", " true_list = true_ans[i].replace(\" \", \"\").split(\",\")\n", " if pred_rag[i] in true_list:\n", " binary_value.append(1)\n", " else:\n", " binary_value.append(0)\n", " \n", " binary_true.append(1)" ] }, { "cell_type": "code", "execution_count": 48, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "('a', 'a')\n", "('a', 'a')\n", "('a', 'b')\n", "('', 'b')\n", "('', 'a')\n", "('d', 'c')\n", "('', 'a')\n", "('a', 'b')\n", "('c', 'b')\n", "('', 'c')\n", "('c', 'b')\n", "('b', 'a')\n", "('a', 'a')\n", "('', 'c')\n", "('', 'c')\n", "('c', 'b')\n", "('b', 'a')\n", "('a', 'a')\n", "('b', 'c')\n", "('c', 'a')\n", "('d', 'b')\n", "('c', 'b')\n", "('b', 'c')\n", "('a', 'c')\n", "('c', 'd')\n", "('b', 'd')\n", "('d', 'a')\n", "('', 'b')\n", "('b', 'c')\n", "('a', 'b')\n", "('b', 'b')\n", "('a', 'a')\n", "('a', 'b')\n", "('a, b', 'a')\n", "('a', 'b')\n", "('', 'a')\n", "('e', 'a')\n", "('b', 'c')\n", "('d', 'c')\n", "('a, b, c, d, e', 'a')\n", "('b', 'a')\n", "('', 'a')\n", "('c', 'a')\n", "('', 'a')\n", "('', 'd')\n", "('', 'd')\n", "('b', 'b')\n", "('a', 'c')\n", "('a', 'd')\n", "('a', 'd')\n", "('a', 'a')\n", "('a', 'b')\n", "('a, d', 'c')\n", "('d', 'a')\n", "('d', 'b')\n", "('a', 'b')\n", "('d', 'a')\n", "('c', 'd')\n", "('', 'd')\n", "('d', 'a')\n", "('', 'd')\n", "('', 'a')\n", "('c', 'b')\n", "('', 'b')\n", "('b', 'c')\n", "('', 'b')\n", "('c', 'a')\n", "('d', 'b')\n", "('d', 'd')\n", "('a', 'b')\n", "('d', 'b')\n", "('a', 'b')\n", "('b', 'd')\n", "('d', 'a')\n", "('c', 'a')\n", "('', 'c')\n", "('', 'd')\n", "('a', 'b')\n", "('b', 'a')\n", "('d', 'a')\n", "('d', 'a')\n", "('', 'b')\n", "('b', 'a')\n", "('d', 'c')\n", "('', 'b')\n", "('c', 'c')\n", "('c', 'd')\n", "('b', 'd')\n", "('b', 'c')\n", "('', 'a')\n", "('a', 'b')\n", "('', 'd')\n", "('', 'b')\n", "('', 'a')\n" ] } ], "source": [ "for i in zip(pred_rag[:94], true_ans):\n", " print(i)" ] }, { "cell_type": "code", "execution_count": 47, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['a',\n", " 'a',\n", " 'a',\n", " '',\n", " '',\n", " 'd',\n", " '',\n", " 'a',\n", " 'c',\n", " '',\n", " 'c',\n", " 'b',\n", " 'a',\n", " '',\n", " '',\n", " 'c',\n", " 'b',\n", " 'a',\n", " 'b',\n", " 'c',\n", " 'd',\n", " 'c',\n", " 'b',\n", " 'a',\n", " 'c',\n", " 'b',\n", " 'd',\n", " '',\n", " 'b',\n", " 'a',\n", " 'b',\n", " 'a',\n", " 'a',\n", " 'a, b',\n", " 'a',\n", " '',\n", " 'e',\n", " 'b',\n", " 'd',\n", " 'a, b, c, d, e',\n", " 'b',\n", " '',\n", " 'c',\n", " '',\n", " '',\n", " '',\n", " 'b',\n", " 'a',\n", " 'a',\n", " 'a',\n", " 'a',\n", " 'a',\n", " 'a, d',\n", " 'd',\n", " 'd',\n", " 'a',\n", " 'd',\n", " 'c',\n", " '',\n", " 'd',\n", " '',\n", " '',\n", " 'c',\n", " '',\n", " 'b',\n", " '',\n", " 'c',\n", " 'd',\n", " 'd',\n", " 'a',\n", " 'd',\n", " 'a',\n", " 'b',\n", " 'd',\n", " 'c',\n", " '',\n", " '',\n", " 'a',\n", " 'b',\n", " 'd',\n", " 'd',\n", " '',\n", " 'b',\n", " 'd',\n", " '',\n", " 'c',\n", " 'c',\n", " 'b',\n", " 'b',\n", " '',\n", " 'a',\n", " '',\n", " '',\n", " '',\n", " 'a',\n", " '',\n", " 'b',\n", " 'c',\n", " 'a',\n", " '',\n", " 'c',\n", " '',\n", " '',\n", " 'd',\n", " 'b',\n", " '']" ] }, "execution_count": 47, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pred_rag" ] }, { "cell_type": "code", "execution_count": 46, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " precision recall f1-score support\n", "\n", " 0 0.00 0.00 0.00 0\n", " 1 1.00 0.11 0.19 94\n", "\n", " accuracy 0.11 94\n", " macro avg 0.50 0.05 0.10 94\n", "weighted avg 1.00 0.11 0.19 94\n", "\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/sklearn/metrics/_classification.py:1471: UndefinedMetricWarning: Recall and F-score are ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.\n", " _warn_prf(average, modifier, msg_start, len(result))\n", "/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/sklearn/metrics/_classification.py:1471: UndefinedMetricWarning: Recall and F-score are ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.\n", " _warn_prf(average, modifier, msg_start, len(result))\n", "/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/sklearn/metrics/_classification.py:1471: UndefinedMetricWarning: Recall and F-score are ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.\n", " _warn_prf(average, modifier, msg_start, len(result))\n" ] } ], "source": [ "print(classification_report(binary_true, binary_value))" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/pinecone/index.py:4: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", " from tqdm.autonotebook import tqdm\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Downloading model\n", "\n", "\n", "Models downloaded\n", "Running on local URL: http://127.0.0.1:7860\n", "\n", "Could not create share link. Please check your internet connection or our status page: https://status.gradio.app.\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2023/11/02 10:43:28 [W] [service.go:132] login to server failed: EOF\n" ] }, { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from demo_rag_gpt_4 import api_call\n", "\n", "import gradio as gr\n", "\n", "# answer = api_call(\n", "# input_data=question,\n", "# service = \"openai\",\n", "# top_k=20,\n", "# prompt_file=\"/projectnb/ds549/students/aakash07/DrVai/prompts/version_1.txt\",\n", "# )\n", "\n", "gr.ChatInterface(api_call).launch(share=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ ">>> from datasets import load_dataset\n", ">>> dataset = load_dataset('squad', split='train')" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ " JSON: {\n", " \"object\": \"list\",\n", " \"data\": [\n", " {\n", " \"id\": \"text-search-babbage-doc-001\",\n", " \"object\": \"model\",\n", " \"created\": 1651172509,\n", " \"owned_by\": \"openai-dev\"\n", " },\n", " {\n", " \"id\": \"gpt-3.5-turbo-16k-0613\",\n", " \"object\": \"model\",\n", " \"created\": 1685474247,\n", " \"owned_by\": \"openai\"\n", " },\n", " {\n", " \"id\": \"curie-search-query\",\n", " \"object\": \"model\",\n", " \"created\": 1651172509,\n", " \"owned_by\": \"openai-dev\"\n", " },\n", " {\n", " \"id\": \"gpt-3.5-turbo-16k\",\n", " \"object\": \"model\",\n", " \"created\": 1683758102,\n", " \"owned_by\": \"openai-internal\"\n", " },\n", " {\n", " \"id\": \"text-search-babbage-query-001\",\n", " \"object\": \"model\",\n", " \"created\": 1651172509,\n", " \"owned_by\": \"openai-dev\"\n", " },\n", " {\n", " \"id\": \"babbage\",\n", " \"object\": \"model\",\n", " \"created\": 1649358449,\n", " \"owned_by\": \"openai\"\n", " },\n", " {\n", " \"id\": \"babbage-search-query\",\n", " \"object\": \"model\",\n", " \"created\": 1651172509,\n", " \"owned_by\": \"openai-dev\"\n", " },\n", " {\n", " \"id\": \"text-babbage-001\",\n", " \"object\": \"model\",\n", " \"created\": 1649364043,\n", " \"owned_by\": \"openai\"\n", " },\n", " {\n", " \"id\": \"whisper-1\",\n", " \"object\": \"model\",\n", " \"created\": 1677532384,\n", " \"owned_by\": \"openai-internal\"\n", " },\n", " {\n", " \"id\": \"text-similarity-davinci-001\",\n", " \"object\": \"model\",\n", " \"created\": 1651172505,\n", " \"owned_by\": \"openai-dev\"\n", " },\n", " {\n", " \"id\": \"davinci-similarity\",\n", " \"object\": \"model\",\n", " \"created\": 1651172509,\n", " \"owned_by\": \"openai-dev\"\n", " },\n", " {\n", " \"id\": \"code-davinci-edit-001\",\n", " \"object\": \"model\",\n", " \"created\": 1649880484,\n", " \"owned_by\": \"openai\"\n", " },\n", " {\n", " \"id\": \"curie-similarity\",\n", " \"object\": \"model\",\n", " \"created\": 1651172510,\n", " \"owned_by\": \"openai-dev\"\n", " },\n", " {\n", " \"id\": \"babbage-search-document\",\n", " \"object\": \"model\",\n", " \"created\": 1651172510,\n", " \"owned_by\": \"openai-dev\"\n", " },\n", " {\n", " \"id\": \"curie-instruct-beta\",\n", " \"object\": \"model\",\n", " \"created\": 1649364042,\n", " \"owned_by\": \"openai\"\n", " },\n", " {\n", " \"id\": \"text-search-ada-doc-001\",\n", " \"object\": \"model\",\n", " \"created\": 1651172507,\n", " \"owned_by\": \"openai-dev\"\n", " },\n", " {\n", " \"id\": \"davinci-instruct-beta\",\n", " \"object\": \"model\",\n", " \"created\": 1649364042,\n", " \"owned_by\": \"openai\"\n", " },\n", " {\n", " \"id\": \"gpt-4\",\n", " \"object\": \"model\",\n", " \"created\": 1687882411,\n", " \"owned_by\": \"openai\"\n", " },\n", " {\n", " \"id\": \"text-similarity-babbage-001\",\n", " \"object\": \"model\",\n", " \"created\": 1651172505,\n", " \"owned_by\": \"openai-dev\"\n", " },\n", " {\n", " \"id\": \"text-search-davinci-doc-001\",\n", " \"object\": \"model\",\n", " \"created\": 1651172505,\n", " \"owned_by\": \"openai-dev\"\n", " },\n", " {\n", " \"id\": \"babbage-similarity\",\n", " \"object\": \"model\",\n", " \"created\": 1651172505,\n", " \"owned_by\": \"openai-dev\"\n", " },\n", " {\n", " \"id\": \"text-embedding-ada-002\",\n", " \"object\": \"model\",\n", " \"created\": 1671217299,\n", " \"owned_by\": \"openai-internal\"\n", " },\n", " {\n", " \"id\": \"davinci-search-query\",\n", " \"object\": \"model\",\n", " \"created\": 1651172505,\n", " \"owned_by\": \"openai-dev\"\n", " },\n", " {\n", " \"id\": \"text-similarity-curie-001\",\n", " \"object\": \"model\",\n", " \"created\": 1651172507,\n", " \"owned_by\": \"openai-dev\"\n", " },\n", " {\n", " \"id\": \"text-davinci-001\",\n", " \"object\": \"model\",\n", " \"created\": 1649364042,\n", " \"owned_by\": \"openai\"\n", " },\n", " {\n", " \"id\": \"text-search-davinci-query-001\",\n", " \"object\": \"model\",\n", " \"created\": 1651172505,\n", " \"owned_by\": \"openai-dev\"\n", " },\n", " {\n", " \"id\": \"ada-search-document\",\n", " \"object\": \"model\",\n", " \"created\": 1651172507,\n", " \"owned_by\": \"openai-dev\"\n", " },\n", " {\n", " \"id\": \"ada-code-search-code\",\n", " \"object\": \"model\",\n", " \"created\": 1651172505,\n", " \"owned_by\": \"openai-dev\"\n", " },\n", " {\n", " \"id\": \"babbage-002\",\n", " \"object\": \"model\",\n", " \"created\": 1692634615,\n", " \"owned_by\": \"system\"\n", " },\n", " {\n", " \"id\": \"davinci-002\",\n", " \"object\": \"model\",\n", " \"created\": 1692634301,\n", " \"owned_by\": \"system\"\n", " },\n", " {\n", " \"id\": \"davinci-search-document\",\n", " \"object\": \"model\",\n", " \"created\": 1651172509,\n", " \"owned_by\": \"openai-dev\"\n", " },\n", " {\n", " \"id\": \"curie-search-document\",\n", " \"object\": \"model\",\n", " \"created\": 1651172508,\n", " \"owned_by\": \"openai-dev\"\n", " },\n", " {\n", " \"id\": \"babbage-code-search-code\",\n", " \"object\": \"model\",\n", " \"created\": 1651172509,\n", " \"owned_by\": \"openai-dev\"\n", " },\n", " {\n", " \"id\": \"text-search-ada-query-001\",\n", " \"object\": \"model\",\n", " \"created\": 1651172505,\n", " \"owned_by\": \"openai-dev\"\n", " },\n", " {\n", " \"id\": \"code-search-ada-text-001\",\n", " \"object\": \"model\",\n", " \"created\": 1651172507,\n", " \"owned_by\": \"openai-dev\"\n", " },\n", " {\n", " \"id\": \"babbage-code-search-text\",\n", " \"object\": \"model\",\n", " \"created\": 1651172509,\n", " \"owned_by\": \"openai-dev\"\n", " },\n", " {\n", " \"id\": \"code-search-babbage-code-001\",\n", " \"object\": \"model\",\n", " \"created\": 1651172507,\n", " \"owned_by\": \"openai-dev\"\n", " },\n", " {\n", " \"id\": \"ada-search-query\",\n", " \"object\": \"model\",\n", " \"created\": 1651172505,\n", " \"owned_by\": \"openai-dev\"\n", " },\n", " {\n", " \"id\": \"ada-code-search-text\",\n", " \"object\": \"model\",\n", " \"created\": 1651172510,\n", " \"owned_by\": \"openai-dev\"\n", " },\n", " {\n", " \"id\": \"text-search-curie-query-001\",\n", " \"object\": \"model\",\n", " \"created\": 1651172509,\n", " \"owned_by\": \"openai-dev\"\n", " },\n", " {\n", " \"id\": \"text-davinci-002\",\n", " \"object\": \"model\",\n", " \"created\": 1649880484,\n", " \"owned_by\": \"openai\"\n", " },\n", " {\n", " \"id\": \"text-davinci-edit-001\",\n", " \"object\": \"model\",\n", " \"created\": 1649809179,\n", " \"owned_by\": \"openai\"\n", " },\n", " {\n", " \"id\": \"code-search-babbage-text-001\",\n", " \"object\": \"model\",\n", " \"created\": 1651172507,\n", " \"owned_by\": \"openai-dev\"\n", " },\n", " {\n", " \"id\": \"gpt-3.5-turbo\",\n", " \"object\": \"model\",\n", " \"created\": 1677610602,\n", " \"owned_by\": \"openai\"\n", " },\n", " {\n", " \"id\": \"gpt-3.5-turbo-instruct-0914\",\n", " \"object\": \"model\",\n", " \"created\": 1694122472,\n", " \"owned_by\": \"system\"\n", " },\n", " {\n", " \"id\": \"ada\",\n", " \"object\": \"model\",\n", " \"created\": 1649357491,\n", " \"owned_by\": \"openai\"\n", " },\n", " {\n", " \"id\": \"text-ada-001\",\n", " \"object\": \"model\",\n", " \"created\": 1649364042,\n", " \"owned_by\": \"openai\"\n", " },\n", " {\n", " \"id\": \"ada-similarity\",\n", " \"object\": \"model\",\n", " \"created\": 1651172507,\n", " \"owned_by\": \"openai-dev\"\n", " },\n", " {\n", " \"id\": \"code-search-ada-code-001\",\n", " \"object\": \"model\",\n", " \"created\": 1651172507,\n", " \"owned_by\": \"openai-dev\"\n", " },\n", " {\n", " \"id\": \"text-similarity-ada-001\",\n", " \"object\": \"model\",\n", " \"created\": 1651172505,\n", " \"owned_by\": \"openai-dev\"\n", " },\n", " {\n", " \"id\": \"gpt-3.5-turbo-0301\",\n", " \"object\": \"model\",\n", " \"created\": 1677649963,\n", " \"owned_by\": \"openai\"\n", " },\n", " {\n", " \"id\": \"gpt-3.5-turbo-instruct\",\n", " \"object\": \"model\",\n", " \"created\": 1692901427,\n", " \"owned_by\": \"system\"\n", " },\n", " {\n", " \"id\": \"text-search-curie-doc-001\",\n", " \"object\": \"model\",\n", " \"created\": 1651172509,\n", " \"owned_by\": \"openai-dev\"\n", " },\n", " {\n", " \"id\": \"text-davinci-003\",\n", " \"object\": \"model\",\n", " \"created\": 1669599635,\n", " \"owned_by\": \"openai-internal\"\n", " },\n", " {\n", " \"id\": \"gpt-4-0613\",\n", " \"object\": \"model\",\n", " \"created\": 1686588896,\n", " \"owned_by\": \"openai\"\n", " },\n", " {\n", " \"id\": \"text-curie-001\",\n", " \"object\": \"model\",\n", " \"created\": 1649364043,\n", " \"owned_by\": \"openai\"\n", " },\n", " {\n", " \"id\": \"curie\",\n", " \"object\": \"model\",\n", " \"created\": 1649359874,\n", " \"owned_by\": \"openai\"\n", " },\n", " {\n", " \"id\": \"gpt-4-0314\",\n", " \"object\": \"model\",\n", " \"created\": 1687882410,\n", " \"owned_by\": \"openai\"\n", " },\n", " {\n", " \"id\": \"davinci\",\n", " \"object\": \"model\",\n", " \"created\": 1649359874,\n", " \"owned_by\": \"openai\"\n", " },\n", " {\n", " \"id\": \"dall-e-2\",\n", " \"object\": \"model\",\n", " \"created\": 1698798177,\n", " \"owned_by\": \"system\"\n", " },\n", " {\n", " \"id\": \"gpt-3.5-turbo-0613\",\n", " \"object\": \"model\",\n", " \"created\": 1686587434,\n", " \"owned_by\": \"openai\"\n", " }\n", " ]\n", "}" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import os\n", "import openai\n", "openai.organization = \"org-0UQMhO1JHKnODDAGm43isRSP\"\n", "openai.api_key = \"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\"\n", "openai.Model.list()" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "d = openai.Model.list()" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "gpt-4\n" ] } ], "source": [ "for i in d['data']:\n", " if i['id'] == 'gpt-4':\n", " print(i['id'])" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'GB6Qr5nSr8uI70QxDJ2PT3BlbkFJTIfe5DGwsNfiiOHo3hyZ'" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "os.environ[\"OPENAI_API_KEY\"]" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/pinecone/index.py:4: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", " from tqdm.autonotebook import tqdm\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Downloading model\n", "\n", "\n", "Models downloaded\n" ] } ], "source": [ "from demo_rag_gpt_4 import api_call\n", "from tqdm import tqdm\n", "import numpy as np\n", "from langchain.prompts import PromptTemplate, HumanMessagePromptTemplate, ChatPromptTemplate\n", "from langchain.chat_models import ChatOpenAI\n", "from langchain.schema.messages import SystemMessage\n", "import os\n", "import json" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "prompt_file = \"prompts/version_1_wihtout_rag.txt\"\n", "prompt = open(prompt_file).read()\n", "\n", " # Create Chat Template\n", "\n", "chat_template = ChatPromptTemplate.from_messages(\n", "[\n", " SystemMessage(\n", " content=prompt, \n", " ),\n", " HumanMessagePromptTemplate.from_template(\"Answer the following question.\\n{question}\"),\n", " # HumanMessagePromptTemplate.from_template(\"Answer this question. Give only the option followed by a brief explanation as output\\\\n{text}\"),\n", "]\n", ")" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "llm = ChatOpenAI(model=\"gpt-4\", temperature=0.9, openai_organization=os.getenv(\"ORGANIZATION_KEY\"))" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "question_list = np.load(\"data/medmcqa/question_list.npy\")\n", "true = np.load(\"data/medmcqa/answer_list.npy\")" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ " 57%|█████▋ | 127/221 [19:04<17:53, 11.42s/it]Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.._completion_with_retry in 4.0 seconds as it raised Timeout: Request timed out: HTTPSConnectionPool(host='api.openai.com', port=443): Read timed out. (read timeout=600).\n", "100%|██████████| 221/221 [49:37<00:00, 13.47s/it] \n" ] } ], "source": [ "pred_list_without_rag = []\n", "doc_list_without_rag = []\n", "exception_list_without_rag = []\n", "for question in tqdm(question_list[279:500]):\n", " complete_prompt = chat_template.format_messages(question=question)\n", " answer = llm(complete_prompt).content\n", " try:\n", " answer = json.loads(answer)\n", " option = answer[\"option\"]\n", " # doc = answer[\"doc_no\"]\n", " pred_list_without_rag.append(option)\n", " # doc_list_without_rag.append([int(i) for i in doc.split(',')])\n", " except Exception as e:\n", " print(e)\n", " exception_list_without_rag.append([e, answer])" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'{\"option\": \"C\", \"explanation\": \"Central serous retinopathy generally does not cause sudden loss of vision. It typically presents with mild to moderate vision loss or distortion that develops slowly over time. On the other hand, Angle closure glaucoma, endophthalmitis, and corneal ulceration can all lead to a rapid onset of visual loss.\"}'" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "answer" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "arr_after_279 = np.array(pred_list_without_rag)" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "np.save(\"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/prediction/wo_rag/medmcqa/arr_after_279.npy\", arr_after_279)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "arr_279 = np.array(pred_list_without_rag)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "np.save(\"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/prediction/wo_rag/medmcqa/arr_279.npy\", arr_279)" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [], "source": [ "# arr_1 = np.load(\"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/prediction/wo_rag/medmcqa/pred.npy\")\n", "# arr_2= np.load(\"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/prediction/w_rag/medmcqa/array_131.npy\")" ] }, { "cell_type": "code", "execution_count": 36, "metadata": {}, "outputs": [], "source": [ "pred_list = np.load(\"prediction/wo_rag/medmcqa/pred.npy\")\n", "true_list = np.load(\"data/medmcqa/answer_list.npy\")" ] }, { "cell_type": "code", "execution_count": 40, "metadata": {}, "outputs": [], "source": [ "map_list = {\"a\":0, \"b\": 1, \"c\": 2, \"d\": 3}\n", "option_list = [\"a\", \"b\", \"c\", \"d\"]\n" ] }, { "cell_type": "code", "execution_count": 45, "metadata": {}, "outputs": [], "source": [ "pred_pross = []\n", "for i in range(len(pred_list)):\n", " pred = pred_list[i]\n", " actual = true_list[i]\n", " if pred.lower() in option_list:\n", " p = map_list[pred.lower()]\n", " if p == actual:\n", " pred_pross.append(True)\n", " else:\n", " pred_pross.append(False)\n", " else:\n", " pred_pross.append(False)" ] }, { "cell_type": "code", "execution_count": 51, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[True,\n", " False,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " False,\n", " True,\n", " True,\n", " False,\n", " True,\n", " True,\n", " False,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " False,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " False,\n", " True,\n", " True,\n", " True,\n", " False,\n", " False,\n", " True,\n", " True,\n", " True,\n", " True,\n", " False,\n", " True,\n", " False,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " False,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " False,\n", " True,\n", " True,\n", " True,\n", " False,\n", " False,\n", " False,\n", " True,\n", " True,\n", " False,\n", " True,\n", " True,\n", " True,\n", " False,\n", " False,\n", " False,\n", " False,\n", " True,\n", " True,\n", " True,\n", " False,\n", " True,\n", " False,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " False,\n", " False,\n", " False,\n", " True,\n", " True,\n", " True,\n", " True,\n", " False,\n", " True,\n", " False,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " False,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " False,\n", " True,\n", " False,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " False,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " False,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " False,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " False,\n", " True,\n", " True,\n", " False,\n", " False,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " False,\n", " True,\n", " False,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " False,\n", " False,\n", " True,\n", " False,\n", " True,\n", " False,\n", " False,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " False,\n", " True,\n", " False,\n", " True,\n", " False,\n", " False,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " False,\n", " True,\n", " True,\n", " True,\n", " False,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " False,\n", " True,\n", " True,\n", " True,\n", " False,\n", " False,\n", " True,\n", " False,\n", " False,\n", " True,\n", " True,\n", " True,\n", " False,\n", " True,\n", " False,\n", " True,\n", " True,\n", " True,\n", " False,\n", " False,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " False,\n", " False,\n", " True,\n", " True,\n", " True,\n", " True,\n", " False,\n", " True,\n", " False,\n", " True,\n", " True,\n", " True,\n", " False,\n", " True,\n", " False,\n", " False,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " False,\n", " False,\n", " True,\n", " True,\n", " True,\n", " True,\n", " False,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " False,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " False,\n", " False,\n", " False,\n", " True,\n", " False,\n", " True,\n", " True,\n", " True,\n", " True,\n", " False,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " False,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " False,\n", " True,\n", " False,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " False,\n", " True,\n", " True,\n", " False,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " False,\n", " True,\n", " True,\n", " False,\n", " True,\n", " True,\n", " True,\n", " True,\n", " False,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " False,\n", " True,\n", " True,\n", " True,\n", " False,\n", " True,\n", " True,\n", " True,\n", " False,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " False,\n", " True,\n", " True,\n", " False,\n", " True,\n", " True,\n", " True,\n", " True,\n", " False,\n", " False,\n", " False,\n", " True,\n", " True,\n", " True,\n", " False,\n", " False,\n", " False,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " False,\n", " True,\n", " True,\n", " False,\n", " True,\n", " False,\n", " True,\n", " False,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " False,\n", " True,\n", " True,\n", " True,\n", " True,\n", " False,\n", " True,\n", " False,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " False,\n", " True,\n", " True,\n", " True,\n", " True,\n", " False,\n", " False,\n", " True,\n", " True,\n", " False,\n", " True,\n", " True,\n", " False,\n", " True,\n", " False,\n", " True,\n", " False,\n", " True,\n", " True,\n", " False,\n", " True,\n", " True,\n", " True,\n", " True,\n", " False,\n", " True,\n", " True,\n", " True,\n", " True,\n", " False,\n", " True,\n", " True,\n", " True,\n", " False,\n", " False,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " False,\n", " False,\n", " True,\n", " False,\n", " True,\n", " True,\n", " False,\n", " False,\n", " True,\n", " True,\n", " True,\n", " False,\n", " True,\n", " False,\n", " False,\n", " False,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " True,\n", " False,\n", " True]" ] }, "execution_count": 51, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pred_pross" ] }, { "cell_type": "code", "execution_count": 52, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 0,\n", " 0,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 0,\n", " 0,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 0,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 0,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 0,\n", " 1,\n", " 0,\n", " 1,\n", " 0,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 0,\n", " 1,\n", " 0,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 0,\n", " 1,\n", " 0,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 0,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 0,\n", " 0,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 0,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 0,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 0,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 0,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 0,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 0,\n", " 1,\n", " 0,\n", " 1,\n", " 1,\n", " 0,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 1,\n", " 0,\n", " 0,\n", " 0,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 1,\n", " 0,\n", " 1]" ] }, "execution_count": 52, "metadata": {}, "output_type": "execute_result" } ], "source": [ "actual" ] }, { "cell_type": "code", "execution_count": 55, "metadata": {}, "outputs": [], "source": [ "actual = [1 for pred in pred_pross]" ] }, { "cell_type": "code", "execution_count": 47, "metadata": {}, "outputs": [], "source": [ "from sklearn.metrics import classification_report" ] }, { "cell_type": "code", "execution_count": 56, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/sklearn/metrics/_classification.py:1471: UndefinedMetricWarning: Recall and F-score are ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.\n", " _warn_prf(average, modifier, msg_start, len(result))\n", "/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/sklearn/metrics/_classification.py:1471: UndefinedMetricWarning: Recall and F-score are ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.\n", " _warn_prf(average, modifier, msg_start, len(result))\n", "/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/sklearn/metrics/_classification.py:1471: UndefinedMetricWarning: Recall and F-score are ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.\n", " _warn_prf(average, modifier, msg_start, len(result))\n" ] } ], "source": [ "report = classification_report(actual, pred_pross)" ] }, { "cell_type": "code", "execution_count": 57, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " precision recall f1-score support\n", "\n", " 0 0.00 0.00 0.00 0\n", " 1 1.00 0.76 0.86 500\n", "\n", " accuracy 0.76 500\n", " macro avg 0.50 0.38 0.43 500\n", "weighted avg 1.00 0.76 0.86 500\n", "\n" ] } ], "source": [ "print(report)" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array(['A', 'C', 'C', 'A', 'B', 'A', 'B', 'D', 'A', 'C', 'A', 'A', 'C',\n", " 'C', 'B', 'C', 'D', 'B', 'D', 'A', 'C', 'B', 'A', 'A', 'A', 'A',\n", " 'A', 'C', 'C', 'D', 'C', 'C', 'D', 'C', 'C', 'B', 'D', 'A', 'B',\n", " 'D', 'D', 'B', 'C', 'B', 'C', 'D', 'A', 'B', 'A', 'C', 'C', 'B',\n", " 'A', 'D', 'A', 'B', 'B', 'B', 'D', 'C', 'C', 'B', 'A', 'B', 'C',\n", " 'D', 'A', 'D', 'C', 'A', 'B', 'B', 'D', 'D', 'A', 'D', 'D', 'D',\n", " 'B', 'A', 'D', 'C', 'B', 'D', 'C', 'A', 'A', 'D', 'D', 'A', 'A',\n", " 'C', 'A', 'B', 'A', 'B', 'D', 'A', 'C', 'C', 'B', 'A', 'C', 'B',\n", " 'D', 'B', 'A', 'C', 'B', 'C', 'C', 'C', 'B', 'A', 'D', 'C', 'B',\n", " 'D', 'A', 'D', 'C', 'A', 'A', 'C', 'A', 'D', 'D', 'D', 'B', 'D',\n", " 'D', 'A', 'A', 'D', 'C', 'C', 'B', 'D', 'D', 'A', 'A', 'A', 'C',\n", " 'B', 'B', 'B', 'C', 'D', 'B', 'D', 'B', 'B', 'A', 'D', 'B', 'A',\n", " 'B', 'D', 'B', 'C', 'B', 'C', 'A', 'C', 'B', 'A', 'D', 'A', 'C',\n", " 'C', 'C', 'A', 'C', '', 'A', 'A', 'C', 'A', 'D', 'B', 'A', 'C',\n", " 'C', 'C', 'C', 'C', 'D', 'C', 'D', 'B', 'C', 'C', 'C', 'D', 'A',\n", " 'D', 'C', 'A', 'B', 'D', 'B', 'B', 'A', 'D', 'A', 'D', 'D', 'D',\n", " 'C', 'B', 'D', 'A', 'B', 'B', 'A', 'D', 'A', 'B', '', 'B', 'B',\n", " 'C', 'A', 'B', 'B', 'B', 'C', 'C', 'C', 'C', 'C', 'A', 'C', 'A',\n", " 'A', 'D', 'B', 'D', 'B', 'B', 'C', 'D', 'A', 'A', 'D', 'B', 'C',\n", " 'A', 'D', 'B', 'A', 'D', 'A', 'A', 'D', 'A', 'C', 'A', 'B', 'A',\n", " 'B', 'B', 'D', 'D', 'C', 'B', 'A', 'C', 'D', 'B', 'B', 'A', 'B',\n", " 'A', 'B', 'D', 'B', 'D', 'A', 'A', 'Missing', 'B', 'B', 'A', 'D',\n", " 'D', 'B', 'A', 'B', 'B', 'A', 'D', 'C', 'B', 'A', 'A', 'D', 'B',\n", " 'B', 'B', 'D', 'B', 'B', 'B', 'B', 'C', 'B', 'C', 'A', 'C', 'C',\n", " 'D', 'A', 'D', 'B', 'D', 'C', 'C', 'A', 'D', 'D', 'D', 'C', 'A',\n", " 'A', 'B', 'A', 'A', 'C', 'C', 'A', 'C', 'B', 'D', 'C', 'A', 'A',\n", " 'A, B', 'C', 'A', 'B', 'C', 'A', 'A', 'A', 'D', 'B', 'D', 'C', 'B',\n", " 'A', 'A', 'A', 'B', 'A', 'D', 'A', 'None of the above', 'B', 'D',\n", " 'B', 'A', 'A', 'A', 'B', 'C', 'A', 'D', 'B', 'B', 'B', 'A', 'B',\n", " 'B', 'B', 'C', 'A', 'B', 'D', 'A', 'D', 'A', 'D', 'C', 'B', 'C',\n", " 'B', 'D', 'B', 'B', 'D', 'D', 'D', 'B', 'D', 'A', 'D', 'C', 'A',\n", " 'D', 'B', 'D', 'A', 'A', 'A', 'D', 'C', 'B', 'A', 'C', 'B', 'C',\n", " 'D', 'A', 'A', 'D', 'D', 'A', 'C', 'C', 'B', 'B', 'D', 'C', 'C',\n", " 'A', 'A', 'A', 'B', 'A', 'C', 'B', 'D', 'D', 'A', 'C', 'D', 'A',\n", " 'B', 'C', 'D', 'C', 'A', 'C', 'D', 'C', 'B', 'C', 'A', 'A', 'D',\n", " 'C', 'C', 'A', 'C', 'B', 'A', 'A', 'C', 'B', 'C', 'B', 'D', 'D',\n", " 'D', 'A', 'B', 'B', 'D', 'D', 'D', 'A', 'B', 'A', 'B', 'D', 'B',\n", " 'A', 'B', 'B', 'C', 'B', 'B', 'C', 'A', 'A', 'D', 'B', 'C', 'B',\n", " 'C', 'A', 'A', 'C', 'B', 'A', 'A', 'A', 'C', 'B'], dtype='._completion_with_retry in 4.0 seconds as it raised Timeout: Request timed out: HTTPSConnectionPool(host='api.openai.com', port=443): Read timed out. (read timeout=600).\n", " 54%|█████▍ | 271/500 [22:30<16:43, 4.38s/it]" ] }, { "name": "stdout", "output_type": "stream", "text": [ "(429)\n", "Reason: Too Many Requests\n", "HTTP response headers: HTTPHeaderDict({'content-type': 'application/json', 'Content-Length': '75', 'date': 'Mon, 06 Nov 2023 23:23:33 GMT', 'x-envoy-upstream-service-time': '3', 'server': 'envoy', 'Via': '1.1 google', 'Alt-Svc': 'h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000'})\n", "HTTP response body: {\"code\":8,\"message\":\"Too many requests. Please retry shortly\",\"details\":[]}\n", "\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ " 67%|██████▋ | 334/500 [26:46<10:24, 3.76s/it]" ] }, { "name": "stdout", "output_type": "stream", "text": [ "(429)\n", "Reason: Too Many Requests\n", "HTTP response headers: HTTPHeaderDict({'content-type': 'application/json', 'Content-Length': '75', 'date': 'Mon, 06 Nov 2023 23:27:50 GMT', 'x-envoy-upstream-service-time': '0', 'server': 'envoy', 'Via': '1.1 google', 'Alt-Svc': 'h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000'})\n", "HTTP response body: {\"code\":8,\"message\":\"Too many requests. Please retry shortly\",\"details\":[]}\n", "\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ " 96%|█████████▌| 481/500 [37:20<01:12, 3.82s/it]" ] }, { "name": "stdout", "output_type": "stream", "text": [ "(429)\n", "Reason: Too Many Requests\n", "HTTP response headers: HTTPHeaderDict({'content-type': 'application/json', 'Content-Length': '75', 'date': 'Mon, 06 Nov 2023 23:38:24 GMT', 'x-envoy-upstream-service-time': '1', 'server': 'envoy', 'Via': '1.1 google', 'Alt-Svc': 'h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000'})\n", "HTTP response body: {\"code\":8,\"message\":\"Too many requests. Please retry shortly\",\"details\":[]}\n", "\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "100%|██████████| 500/500 [38:41<00:00, 4.64s/it]\n" ] } ], "source": [ "import concurrent.futures\n", "from tqdm import tqdm\n", "import time # Import the time module\n", "\n", "pred_list = []\n", "exception_list = []\n", "doc_list = []\n", "\n", "def process_question(question):\n", " answer = None # Initialize answer before the try block\n", " try:\n", " answer = api_call(question, history={})\n", " option = answer[\"option\"]\n", " doc = answer[\"doc_no\"]\n", " pred_list.append(option)\n", " doc_list.append([i for i in doc.split(',')])\n", " pbar.update(1) # Update the tqdm progress bar\n", " time.sleep(5) # Add a 1-second delay between API calls (adjust as needed)\n", " except Exception as e:\n", " print(e)\n", " exception_list.append([e, answer])\n", " pred_list.append(\"\")\n", " pbar.update(1) # Update the tqdm progress bar\n", " time.sleep(5) # Add a 1-second delay even when an exception occurs\n", "\n", "question_list = question_list[:500]\n", "\n", "# Specify the number of threads by setting max_workers\n", "num_threads = 4 # You can adjust this number as needed\n", "with tqdm(total=len(question_list)) as pbar:\n", " with concurrent.futures.ThreadPoolExecutor(max_workers=num_threads) as executor:\n", " list(executor.map(process_question, question_list))\n" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "arr = np.array(pred_list)\n", "np.save(\"prediction/w_rag/medmcqa/pred_error.npy\", arr)" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[['1'],\n", " [''],\n", " ['1', '4'],\n", " ['2'],\n", " [''],\n", " ['1', '2'],\n", " ['1', '4'],\n", " ['1'],\n", " ['No document used'],\n", " ['Document 3'],\n", " ['1', '2'],\n", " ['4'],\n", " [''],\n", " ['No document used'],\n", " ['1'],\n", " ['2'],\n", " ['1', '2'],\n", " ['1'],\n", " ['1'],\n", " ['4'],\n", " ['3'],\n", " ['Not mentioned in the provided documents'],\n", " ['1'],\n", " [''],\n", " ['1'],\n", " ['1', '4'],\n", " ['1'],\n", " [''],\n", " ['4'],\n", " ['2'],\n", " ['5'],\n", " ['1'],\n", " ['1'],\n", " ['1'],\n", " ['3'],\n", " ['1', '2', '4'],\n", " ['Not available in documents'],\n", " [''],\n", " ['2'],\n", " ['None'],\n", " ['1', '4'],\n", " ['3'],\n", " ['1', '2'],\n", " ['No document used'],\n", " ['None'],\n", " ['1'],\n", " ['1'],\n", " ['1'],\n", " ['3'],\n", " [''],\n", " ['1', '3'],\n", " ['1'],\n", " ['1'],\n", " ['1', '2', '4'],\n", " ['Not available in provided documents'],\n", " ['2'],\n", " ['1', ' 2', ' 3'],\n", " ['1'],\n", " [''],\n", " ['2'],\n", " ['1'],\n", " ['2'],\n", " ['4'],\n", " ['2'],\n", " ['4'],\n", " ['5'],\n", " ['Not mentioned in provided documents'],\n", " ['1', '3'],\n", " ['1'],\n", " ['4', '2'],\n", " ['No Document Used'],\n", " ['2'],\n", " ['2'],\n", " ['4'],\n", " ['3'],\n", " ['Not applicable'],\n", " ['1', ' 4'],\n", " ['1', '2'],\n", " ['1'],\n", " ['5'],\n", " ['2'],\n", " ['1'],\n", " ['1', '2'],\n", " ['1', '2'],\n", " ['1', '5'],\n", " [''],\n", " ['2'],\n", " ['4'],\n", " ['3'],\n", " ['2'],\n", " ['1', '2', '4', '5'],\n", " ['1'],\n", " [''],\n", " ['2'],\n", " ['1', '3', '4'],\n", " ['3'],\n", " ['N/A'],\n", " ['1', '4', '5'],\n", " ['1'],\n", " ['2'],\n", " ['1'],\n", " ['1'],\n", " [''],\n", " ['1', '2'],\n", " [''],\n", " [''],\n", " ['1'],\n", " ['1', '3', '5'],\n", " ['3', '5'],\n", " ['1', '2'],\n", " ['1'],\n", " ['Not used'],\n", " ['2'],\n", " ['5'],\n", " ['4'],\n", " ['5'],\n", " ['1'],\n", " ['1', '2', '3', '4'],\n", " ['1'],\n", " ['Document 1', ' Document 2', ' Document 4', ' Document 5'],\n", " ['4'],\n", " ['2'],\n", " [''],\n", " [''],\n", " ['1'],\n", " ['1'],\n", " ['None'],\n", " ['3', '4'],\n", " ['1'],\n", " ['5'],\n", " ['2'],\n", " ['Not mentioned in any document'],\n", " ['1'],\n", " ['1'],\n", " ['1', '3'],\n", " ['1', '2', '3'],\n", " ['1'],\n", " ['1'],\n", " ['1'],\n", " ['1', '3'],\n", " ['5'],\n", " ['Not applicable'],\n", " ['2'],\n", " ['3'],\n", " [''],\n", " ['1', '4'],\n", " ['None'],\n", " ['4'],\n", " ['2'],\n", " ['1'],\n", " ['3'],\n", " ['3'],\n", " [''],\n", " ['Based on medical knowledge'],\n", " ['1', '2', '3', '4'],\n", " ['1'],\n", " ['2'],\n", " ['1'],\n", " ['1', '2'],\n", " ['3'],\n", " ['1'],\n", " ['1'],\n", " ['1'],\n", " ['1'],\n", " [''],\n", " ['1', '2', '3'],\n", " ['1'],\n", " ['3'],\n", " ['1'],\n", " ['Document: 1', ' Document: 2'],\n", " ['2'],\n", " ['1'],\n", " [''],\n", " ['3'],\n", " ['1', '2', '5'],\n", " ['Not explicitly stated in the provided documents'],\n", " ['3'],\n", " ['1'],\n", " [''],\n", " [''],\n", " ['1', ' 4'],\n", " ['2'],\n", " [''],\n", " ['1', '3', '4', '5'],\n", " ['1', '2'],\n", " ['1'],\n", " ['1', ' 2'],\n", " ['No document used.'],\n", " ['1', '3'],\n", " ['1'],\n", " ['3'],\n", " [''],\n", " ['None'],\n", " ['4', '5'],\n", " ['1', ' 2', ' 3'],\n", " ['1', '4'],\n", " ['4'],\n", " ['1'],\n", " ['1'],\n", " [''],\n", " [''],\n", " ['No document used'],\n", " ['5'],\n", " ['1', '5'],\n", " ['4'],\n", " ['1', '2', '5'],\n", " ['1', '2', '3'],\n", " [''],\n", " ['0'],\n", " ['2'],\n", " ['5'],\n", " ['3'],\n", " ['1'],\n", " ['2'],\n", " ['4'],\n", " ['1', '3'],\n", " ['1', '2', '3'],\n", " ['1'],\n", " ['1', '4', '5'],\n", " ['None'],\n", " ['Not mentioned in provided documents'],\n", " ['1'],\n", " ['2', '4'],\n", " ['1'],\n", " ['3'],\n", " ['3'],\n", " [''],\n", " ['2'],\n", " ['N/A'],\n", " ['4'],\n", " ['1'],\n", " ['1'],\n", " ['1'],\n", " ['1'],\n", " ['Not Mentioned'],\n", " ['1', '2', '3', '4'],\n", " ['5'],\n", " ['Not mentioned in any document'],\n", " [''],\n", " [''],\n", " ['2'],\n", " ['1'],\n", " ['1', '2'],\n", " ['None used'],\n", " ['2', '3', '5'],\n", " ['Not mentioned'],\n", " ['1', '2', '3'],\n", " ['3'],\n", " ['1'],\n", " ['4', '5'],\n", " ['1', '3'],\n", " ['1'],\n", " ['2'],\n", " ['1', '5'],\n", " ['2'],\n", " ['1'],\n", " ['2'],\n", " [''],\n", " ['1'],\n", " ['None'],\n", " ['2'],\n", " ['1'],\n", " ['5'],\n", " ['3', ' 2'],\n", " ['3'],\n", " [''],\n", " ['3'],\n", " ['1'],\n", " ['1'],\n", " [''],\n", " ['1'],\n", " ['1'],\n", " ['1'],\n", " ['2'],\n", " ['4'],\n", " ['4'],\n", " ['2'],\n", " ['1'],\n", " ['2', '3'],\n", " ['3', ' 4'],\n", " [''],\n", " ['3'],\n", " ['2'],\n", " ['2'],\n", " ['1'],\n", " ['1'],\n", " ['2'],\n", " ['1', '3', '4'],\n", " ['1', '2'],\n", " ['5'],\n", " ['1', '2'],\n", " ['1', '2'],\n", " ['No Document used. This information comes from general ophthalmological knowledge.'],\n", " ['1'],\n", " [''],\n", " [''],\n", " ['3'],\n", " ['1'],\n", " ['1'],\n", " [''],\n", " ['1', '2'],\n", " ['1'],\n", " ['1', '4'],\n", " ['2'],\n", " ['1'],\n", " [''],\n", " ['Not mentioned in the provided documents but answered based on general knowledge'],\n", " ['1'],\n", " ['2', '3'],\n", " ['2'],\n", " ['2', '3'],\n", " ['1', '2'],\n", " ['5'],\n", " ['1'],\n", " ['3'],\n", " ['2', '4'],\n", " ['1', '4'],\n", " ['1'],\n", " ['1'],\n", " ['4'],\n", " ['1'],\n", " [''],\n", " ['Not mentioned in the provided documents'],\n", " ['1', '3'],\n", " ['4'],\n", " ['None'],\n", " ['None'],\n", " ['1'],\n", " ['2'],\n", " ['4'],\n", " ['4'],\n", " ['5'],\n", " ['1'],\n", " ['1', '2'],\n", " ['5'],\n", " ['1', ' 2', ' 4'],\n", " ['1', '2', ' and 4'],\n", " ['1'],\n", " [''],\n", " ['4'],\n", " ['1'],\n", " ['4'],\n", " ['2'],\n", " ['2', '5'],\n", " ['1'],\n", " ['None'],\n", " ['1'],\n", " ['4'],\n", " ['1'],\n", " [''],\n", " ['1', '5'],\n", " ['1', '3'],\n", " ['2'],\n", " ['1', '2', '3', '4'],\n", " ['1'],\n", " ['1', '4'],\n", " ['1'],\n", " ['1', '3'],\n", " ['1'],\n", " ['1'],\n", " [''],\n", " ['3'],\n", " ['1', '2'],\n", " ['1', '3'],\n", " ['4'],\n", " ['1', '3'],\n", " ['5'],\n", " ['none'],\n", " ['1', '2'],\n", " [''],\n", " ['3'],\n", " ['1'],\n", " ['1'],\n", " ['Not explicitly mentioned in the documents'],\n", " ['1', '2'],\n", " [''],\n", " ['Not found in documents', ' knowledge based answer'],\n", " ['1'],\n", " ['1'],\n", " ['1', '3'],\n", " ['No document used'],\n", " ['1', '2', '4'],\n", " ['2'],\n", " ['4'],\n", " ['1'],\n", " ['1'],\n", " ['1'],\n", " ['1'],\n", " [''],\n", " [''],\n", " ['1'],\n", " ['Not applicable'],\n", " [''],\n", " [''],\n", " ['1'],\n", " ['1', '2'],\n", " ['1', '2'],\n", " ['3'],\n", " ['Not mentioned in the provided documents'],\n", " ['1', '3'],\n", " ['Not mentioned in provided documents'],\n", " ['1', ' 3', ' 5'],\n", " ['3', '5'],\n", " ['1', '2', '3'],\n", " ['Not mentioned in the documents'],\n", " ['Not provided in the given documents'],\n", " ['Not applicable'],\n", " ['1', '2', '3'],\n", " ['1'],\n", " ['1', ' 4'],\n", " ['1', '4'],\n", " [''],\n", " ['1'],\n", " ['5'],\n", " [''],\n", " ['No document used'],\n", " ['1'],\n", " ['1', '5'],\n", " ['1', '2', '4'],\n", " ['3', '4'],\n", " ['2'],\n", " ['1', '2'],\n", " ['1'],\n", " [''],\n", " ['3'],\n", " ['1'],\n", " [''],\n", " ['Not applicable'],\n", " ['1'],\n", " ['1'],\n", " ['1', '5'],\n", " ['1'],\n", " ['1', '2'],\n", " ['1', '2'],\n", " ['1', '2'],\n", " ['1', '2', '3'],\n", " ['1'],\n", " ['1'],\n", " ['1'],\n", " [''],\n", " ['4'],\n", " ['3'],\n", " ['1', '2', '3'],\n", " ['1'],\n", " ['1', '2'],\n", " ['1'],\n", " ['2'],\n", " ['1'],\n", " ['5'],\n", " ['1'],\n", " [''],\n", " ['1'],\n", " ['1'],\n", " ['2'],\n", " ['1', '3'],\n", " [''],\n", " ['2'],\n", " ['1', '2', '3', '5'],\n", " ['1'],\n", " ['3'],\n", " ['4'],\n", " [''],\n", " ['2'],\n", " ['4'],\n", " ['3'],\n", " ['1', '4'],\n", " [''],\n", " ['1', ' 2', ' 3'],\n", " ['1', '2', '3'],\n", " ['1', '2'],\n", " ['1', '2'],\n", " [''],\n", " ['3'],\n", " ['1'],\n", " ['None'],\n", " ['1', '3'],\n", " ['1', '2'],\n", " ['1'],\n", " ['2'],\n", " ['No document used'],\n", " ['4'],\n", " ['4'],\n", " [''],\n", " ['1'],\n", " ['1'],\n", " ['4'],\n", " ['2', '3'],\n", " ['1', '3'],\n", " [''],\n", " ['1'],\n", " ['None'],\n", " ['1'],\n", " ['1'],\n", " ['1'],\n", " ['2'],\n", " ['4'],\n", " ['4']]" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "doc_list" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [], "source": [ "doc_str = [str(i) for i in doc_list]" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [], "source": [ "arr = np.array(pred_list)\n", "np.save(\"prediction/w_rag/medmcqa/pred.npy\", pred_list)" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [], "source": [ "exp_list = []\n", "for i in range(len(pred_list)):\n", " if len(arr[i]) == 0:\n", " exp_list.append(i)" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[270, 333, 480]" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "exp_list" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [], "source": [ "exp_ques = [question_list[i] for i in exp_list]" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ " 0%| | 0/500 [00:00, received 2.\n", " warnings.warn(\n", "/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/utils.py:820: UserWarning: Expected at least 3 arguments for function , received 2.\n", " warnings.warn(\n" ] } ], "source": [ "with gr.Blocks() as demo:\n", " chatbot = gr.ChatInterface(random_response)\n", " # print(chatbot)\n", " radio = gr.Radio([\"Correct\", \"InCorrect\", \"Partially Corrext\"], label=\"accuracy\", info=\"Please rate the system response\")\n", " submit_radio = gr.Button(value=\"Submit\")\n", " t = gr.Textbox(value=\"\", label=\"Input\")\n", " txt_3 = gr.Textbox(value=\"\", label=\"Output\")\n", " submit_radio.click(random_response, inputs=[t, radio], outputs=[txt_3])\n", " # msg.submit(random_response, [msg, chatbot], [msg, chatbot])" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "ename": "ModuleNotFoundError", "evalue": "No module named 'global_variable_module'", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)", "\u001b[1;32m/Users/aakashbhatnagar/Documents/masters/ophthal_llm/temp.ipynb Cell 99\u001b[0m line \u001b[0;36m1\n\u001b[0;32m----> 1\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mglobal_variable_module\u001b[39;00m \u001b[39mimport\u001b[39;00m global_var\n", "\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'global_variable_module'" ] } ], "source": [ "from global_variable_module import global_var" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Running on local URL: http://127.0.0.1:7860\n", "\n", "To create a public link, set `share=True` in `launch()`.\n" ] }, { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" }, { "name": "stderr", "output_type": "stream", "text": [ "/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/helpers.py:796: UserWarning: Unexpected argument. Filling with None.\n", " warnings.warn(\"Unexpected argument. Filling with None.\")\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "\n", "hi\n", "[]\n" ] } ], "source": [ "demo.launch()" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", " from .autonotebook import tqdm as notebook_tqdm\n", "/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/langchain/vectorstores/pinecone.py:59: UserWarning: Passing in `embedding` as a Callable is deprecated. Please pass in an Embeddings object instead.\n", " warnings.warn(\n" ] } ], "source": [ "import gradio as gr\n", "from conversation import run\n", "import random\n", "import time\n", "import random\n", "\n", "global USERNAME\n", "global PASSWORD\n", "global INPUT\n", "global OUTPUT\n", "global SOURCE\n", "global DOCS\n", "\n", "def auth_function(username, password):\n", " USERNAME = username\n", " user_name = username\n", " return username == password\n", "\n", "def random_response(message):\n", " # print(type(message))\n", " # print(message)\n", " # print(accuracy)\n", " \n", " out = random.choice([\"Yes\", \"No\"])\n", " # open a txt file\n", " # with open(\"function hit\", \"a+\") as f:\n", " # f.write(message)\n", " return out, \"THIS IS SOURCE\", \"THIS IS DOCS\"\n", "\n", "\n", "def make_conversation(message, history):\n", " INPUT = message\n", " text_, source, docs = random_response(message)\n", " OUTPUT = text_\n", " SOURCE = source\n", " DOCS = docs\n", "\n", " print(\"INPUT: \", INPUT)\n", " print(\"OUTPUT: \", OUTPUT)\n", " print(\"SOURCE: \", SOURCE)\n", " print(\"DOCS: \", DOCS)\n", "\n", " for i in range(len(text_)):\n", " time.sleep(0.001)\n", " yield text_[: i+1]\n", "\n", "def insert_text(accuracy, correct_output):\n", " print(accuracy)\n", " print(\"input \", INPUT)\n", " print(\"output \", OUTPUT)\n", " print(\"correct output\", correct_output)\n", " print(\"source \", SOURCE)\n", " print(\"docs \", DOCS)\n", "\n", " return \"DONE\"\n", "\n", "with gr.Blocks() as demo:\n", " chatbot = gr.ChatInterface(make_conversation)\n", " # print(chatbot)\n", " radio = gr.Radio([\"Correct\", \"InCorrect\", \"Partially Corrext\"], label=\"accuracy\", info=\"Please rate the system response\")\n", " t = gr.Textbox(value=\"\", label=\"Input\")\n", " submit_radio = gr.Button(value=\"Submit\")\n", " txt_3 = gr.Textbox(value=\"\", label=\"Output\")\n", " submit_radio.click(insert_text, inputs=[t, radio], outputs=[txt_3])\n", " # msg.submit(random_response, [msg, chatbot], [msg, chatbot])\n", "\n", "# with gr.Blocks(css=\"style.css\") as demo:\n", "# gr.Markdown(\"##DR. VAI\")\n", "# gr.ChatInterface(make_conversation).queue()\n", "\n", "# demo.launch()" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Running on local URL: http://127.0.0.1:7860\n", "\n", "To create a public link, set `share=True` in `launch()`.\n" ] }, { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" }, { "name": "stdout", "output_type": "stream", "text": [ "INPUT: hi\n", "OUTPUT: No\n", "SOURCE: THIS IS SOURCE\n", "DOCS: THIS IS DOCS\n", "this is correct\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Traceback (most recent call last):\n", " File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/queueing.py\", line 427, in call_prediction\n", " output = await route_utils.call_process_api(\n", " File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/route_utils.py\", line 232, in call_process_api\n", " output = await app.get_blocks().process_api(\n", " File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/blocks.py\", line 1497, in process_api\n", " result = await self.call_function(\n", " File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/blocks.py\", line 1119, in call_function\n", " prediction = await anyio.to_thread.run_sync(\n", " File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/anyio/to_thread.py\", line 33, in run_sync\n", " return await get_asynclib().run_sync_in_worker_thread(\n", " File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/anyio/_backends/_asyncio.py\", line 877, in run_sync_in_worker_thread\n", " return await future\n", " File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/anyio/_backends/_asyncio.py\", line 807, in run\n", " result = context.run(func, *args)\n", " File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/utils.py\", line 665, in wrapper\n", " response = f(*args, **kwargs)\n", " File \"/var/folders/73/1kdzs7qn01v55rn5825j1cjr0000gn/T/ipykernel_7321/1082532790.py\", line 49, in insert_text\n", " print(\"input \", INPUT)\n", "NameError: name 'INPUT' is not defined\n", "Traceback (most recent call last):\n", " File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/queueing.py\", line 427, in call_prediction\n", " output = await route_utils.call_process_api(\n", " File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/route_utils.py\", line 232, in call_process_api\n", " output = await app.get_blocks().process_api(\n", " File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/blocks.py\", line 1497, in process_api\n", " result = await self.call_function(\n", " File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/blocks.py\", line 1119, in call_function\n", " prediction = await anyio.to_thread.run_sync(\n", " File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/anyio/to_thread.py\", line 33, in run_sync\n", " return await get_asynclib().run_sync_in_worker_thread(\n", " File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/anyio/_backends/_asyncio.py\", line 877, in run_sync_in_worker_thread\n", " return await future\n", " File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/anyio/_backends/_asyncio.py\", line 807, in run\n", " result = context.run(func, *args)\n", " File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/utils.py\", line 665, in wrapper\n", " response = f(*args, **kwargs)\n", " File \"/var/folders/73/1kdzs7qn01v55rn5825j1cjr0000gn/T/ipykernel_7321/1082532790.py\", line 49, in insert_text\n", " print(\"input \", INPUT)\n", "NameError: name 'INPUT' is not defined\n", "\n", "The above exception was the direct cause of the following exception:\n", "\n", "Traceback (most recent call last):\n", " File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/queueing.py\", line 472, in process_events\n", " response = await self.call_prediction(awake_events, batch)\n", " File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/queueing.py\", line 436, in call_prediction\n", " raise Exception(str(error) if show_error else None) from error\n", "Exception: None\n" ] } ], "source": [ "demo.launch()" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'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'" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import os\n", "\n", "os.getenv(\"OPENAI_API_KEY\")" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/utils.py:816: UserWarning: Expected 2 arguments for function , received 1.\n", " warnings.warn(\n", "/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/utils.py:820: UserWarning: Expected at least 2 arguments for function , received 1.\n", " warnings.warn(\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Running on local URL: http://127.0.0.1:7862\n", "\n", "To create a public link, set `share=True` in `launch()`.\n" ] }, { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import gradio as gr\n", "from conversation import run, auth_function\n", "import random\n", "import time\n", "import random\n", "\n", "\n", "\n", "def random_response(message):\n", " \n", " out = random.choice([\"Yes\", \"No\"])\n", " return out, \"THIS IS SOURCE\", \"THIS IS DOCS\"\n", "\n", "\n", "def make_conversation(message, history):\n", " text_, source, docs = run(message)\n", " return text_, str(history)\n", "\n", "\n", "with gr.Blocks() as demo:\n", " input_history = gr.State([])\n", " output1_history = gr.State([])\n", " output_2_history = gr.State([])\n", "\n", " \n", "\n", " chatbot = gr.ChatInterface(make_conversation)\n", " # print(chatbot)\n", " radio = gr.Radio([\"Correct\", \"InCorrect\", \"Partially Corrext\"], label=\"accuracy\", info=\"Please rate the system response\")\n", " t = gr.Textbox(value=\"\", label=\"Input\")\n", " submit_radio = gr.Button(value=\"Submit\")\n", " txt_3 = gr.Textbox(value=\"\", label=\"Output\")\n", " \n", " # msg.submit(random_response, [msg, chatbot], [msg, chatbot])\n", "\n", " def make_conversation(message, history):\n", " text_, source, docs = run(message)\n", " return {\n", " input_history: message,\n", " output1_history: text_,\n", "\n", " }\n", " \n", " submit_radio.click(insert_text, inputs=[chatbot], outputs=[txt_3])\n", "# with gr.Blocks(css=\"style.css\") as demo:\n", "# gr.Markdown(\"##DR. VAI\")\n", "# gr.ChatInterface(make_conversation).queue()\n", "\n", "demo.launch()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", " from .autonotebook import tqdm as notebook_tqdm\n", "/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/langchain/vectorstores/pinecone.py:59: UserWarning: Passing in `embedding` as a Callable is deprecated. Please pass in an Embeddings object instead.\n", " warnings.warn(\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Running on local URL: http://127.0.0.1:7860\n", "\n", "To create a public link, set `share=True` in `launch()`.\n" ] }, { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" }, { "name": "stdout", "output_type": "stream", "text": [ "\n", "\n", "\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n", "\u001b[32;1m\u001b[1;3mHello Aakash, I'm Dr.V AI, an assistant to ophthalmologists. I'm designed to help answer medical questions related to ophthalmology. If you have any questions about eye health, eye diseases, or eye care, feel free to ask!\u001b[0m\n", "\n", "\u001b[1m> Finished chain.\u001b[0m\n", "Hello Aakash, I'm Dr.V AI, an assistant to ophthalmologists. I'm designed to help answer medical questions related to ophthalmology. If you have any questions about eye health, eye diseases, or eye care, feel free to ask!\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Traceback (most recent call last):\n", " File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/queueing.py\", line 427, in call_prediction\n", " output = await route_utils.call_process_api(\n", " File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/route_utils.py\", line 232, in call_process_api\n", " output = await app.get_blocks().process_api(\n", " File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/blocks.py\", line 1506, in process_api\n", " data = self.postprocess_data(fn_index, result[\"prediction\"], state)\n", " File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/blocks.py\", line 1396, in postprocess_data\n", " outputs_cached = processing_utils.move_files_to_cache(prediction_value, block) # type: ignore\n", " File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/processing_utils.py\", line 294, in move_files_to_cache\n", " return client_utils.traverse(data, _move_to_cache, client_utils.is_file_obj)\n", " File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio_client/utils.py\", line 782, in traverse\n", " new_obj.append(traverse(item, func, is_root))\n", " File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio_client/utils.py\", line 782, in traverse\n", " new_obj.append(traverse(item, func, is_root))\n", " File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio_client/utils.py\", line 777, in traverse\n", " new_obj[key] = traverse(value, func, is_root)\n", " File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio_client/utils.py\", line 773, in traverse\n", " return func(json_obj)\n", " File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/processing_utils.py\", line 287, in _move_to_cache\n", " temp_file_path = move_resource_to_block_cache(payload.path, block)\n", " File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/processing_utils.py\", line 265, in move_resource_to_block_cache\n", " temp_file_path = save_file_to_cache(\n", " File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/processing_utils.py\", line 191, in save_file_to_cache\n", " temp_dir = hash_file(file_path)\n", " File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/processing_utils.py\", line 118, in hash_file\n", " with open(file_path, \"rb\") as f:\n", "FileNotFoundError: [Errno 2] No such file or directory: \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/Hello Aakash, I'm Dr.V AI, an assistant to ophthalmologists. I'm designed to help answer medical questions related to ophthalmology. If you have any questions about eye health, eye diseases, or eye care, feel free to ask!\"\n", "Traceback (most recent call last):\n", " File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/queueing.py\", line 427, in call_prediction\n", " output = await route_utils.call_process_api(\n", " File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/route_utils.py\", line 232, in call_process_api\n", " output = await app.get_blocks().process_api(\n", " File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/blocks.py\", line 1506, in process_api\n", " data = self.postprocess_data(fn_index, result[\"prediction\"], state)\n", " File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/blocks.py\", line 1396, in postprocess_data\n", " outputs_cached = processing_utils.move_files_to_cache(prediction_value, block) # type: ignore\n", " File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/processing_utils.py\", line 294, in move_files_to_cache\n", " return client_utils.traverse(data, _move_to_cache, client_utils.is_file_obj)\n", " File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio_client/utils.py\", line 782, in traverse\n", " new_obj.append(traverse(item, func, is_root))\n", " File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio_client/utils.py\", line 782, in traverse\n", " new_obj.append(traverse(item, func, is_root))\n", " File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio_client/utils.py\", line 777, in traverse\n", " new_obj[key] = traverse(value, func, is_root)\n", " File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio_client/utils.py\", line 773, in traverse\n", " return func(json_obj)\n", " File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/processing_utils.py\", line 287, in _move_to_cache\n", " temp_file_path = move_resource_to_block_cache(payload.path, block)\n", " File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/processing_utils.py\", line 265, in move_resource_to_block_cache\n", " temp_file_path = save_file_to_cache(\n", " File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/processing_utils.py\", line 191, in save_file_to_cache\n", " temp_dir = hash_file(file_path)\n", " File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/processing_utils.py\", line 118, in hash_file\n", " with open(file_path, \"rb\") as f:\n", "FileNotFoundError: [Errno 2] No such file or directory: \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/Hello Aakash, I'm Dr.V AI, an assistant to ophthalmologists. I'm designed to help answer medical questions related to ophthalmology. If you have any questions about eye health, eye diseases, or eye care, feel free to ask!\"\n", "\n", "The above exception was the direct cause of the following exception:\n", "\n", "Traceback (most recent call last):\n", " File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/queueing.py\", line 472, in process_events\n", " response = await self.call_prediction(awake_events, batch)\n", " File \"/Users/aakashbhatnagar/Documents/masters/ophthal_llm/myenv/lib/python3.10/site-packages/gradio/queueing.py\", line 436, in call_prediction\n", " raise Exception(str(error) if show_error else None) from error\n", "Exception: None\n" ] } ], "source": [ "import gradio as gr\n", "from conversation import make_conversation, auth_function\n", "import random\n", "\n", "demo = gr.ChatInterface(make_conversation).queue()\n", "\n", "demo.launch(auth=auth_function)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Token will not been saved to git credential helper. Pass `add_to_git_credential=True` if you want to set the git credential as well.\n", "Token is valid (permission: write).\n", "Your token has been saved to /Users/aakashbhatnagar/.cache/huggingface/token\n", "Login successful\n" ] } ], "source": [ "# !huggingface-cli login\n", "# or using an environment variable\n", "!huggingface-cli login --token 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" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "ename": "AttributeError", "evalue": "'Dependency' object has no attribute 'launch'", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", "\u001b[1;32m/Users/aakashbhatnagar/Documents/masters/ophthal_llm/temp.ipynb Cell 109\u001b[0m line \u001b[0;36m2\n\u001b[1;32m 1\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mgradio\u001b[39;00m \u001b[39mas\u001b[39;00m \u001b[39mgr\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m gr\u001b[39m.\u001b[39;49mInterface\u001b[39m.\u001b[39;49mload(\u001b[39m\"\u001b[39;49m\u001b[39mhuggingface/drvai/drvai\u001b[39;49m\u001b[39m\"\u001b[39;49m)\u001b[39m.\u001b[39;49mlaunch()\n", "\u001b[0;31mAttributeError\u001b[0m: 'Dependency' object has no attribute 'launch'" ] } ], "source": [ "import gradio as gr\n", "gr.Interface.load(\"huggingface/drvai/drvai\").launch()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "myenv", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.9" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }