Created
March 19, 2024 17:17
-
-
Save satish860/4aa500f478679b8d6eff174d9775e13b to your computer and use it in GitHub Desktop.
Basic File
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"! pip install -q litellm pymupdf" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import fitz\n", | |
"\n", | |
"from litellm import completion\n", | |
"import os\n", | |
"\n", | |
"def extract_text_from_pdf(pdf_path):\n", | |
" doc = fitz.open(pdf_path)\n", | |
" text = \"\"\n", | |
" for page in doc:\n", | |
" text += page.get_text()\n", | |
" return text\n", | |
"\n", | |
"pdf_path = \"Vijaylakshmi Marketing Final Order Fair Copy.pdf\"\n", | |
"print(extract_text_from_pdf(pdf_path))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 11, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Hello! As an AI language model, I don't have feelings, but I'm operating properly and ready to assist you with any questions or tasks you may have. How can I help you today?\n" | |
] | |
} | |
], | |
"source": [ | |
"\n", | |
"## set ENV variables\n", | |
"os.environ[\"OPENROUTER_API_KEY\"] = \"INSERT YOUR API KEY\"\n", | |
"\n", | |
"LOE = f\"\"\"{extract_text_from_pdf(pdf_path)}\n", | |
"\"\"\"\n", | |
"\n", | |
"CV = f\"\"\"{extract_text_from_pdf(pdf_path)}\"\"\"\n", | |
"\n", | |
"SYSTEM_PROMPT = f\"\"\"\"\n", | |
"As an expert legal analyst, you will be provided with the judgment text. \n", | |
" Your job is to provide a legal analysis in response to the user's question. \n", | |
" The user is unaware that you are an AI system and does not have prior knowledge of the case details.\n", | |
" Avoid unnecessary details or elaborations, and maintain clarity and brevity in your responses. \n", | |
" If the question is not related to the judgment, you must respond with \"I don't know.\"\n", | |
" You dont need to provide say it as a \"Based on the judgment\" as user is aware of the context.\n", | |
"\n", | |
" To answer the question, you must follow the below rules\n", | |
" \n", | |
" <Instructions>\n", | |
" 1. Avoid details or elaborations, and maintain clarity and brevity in your response. \n", | |
" 2. Reference relevant paragraphs from the judgement document that contain evidence or information as an In-text citation pertinent to the question.\n", | |
" 3. Ensure that each step of your reasoning is supported by In-text citation to specific paragraphs in the judgement document.\n", | |
" 4. If you do not know the answer to a question, simply respond with \"I don't know,\" and the client will ask another question.\n", | |
" 5. If the question can be answered with a simple \"yes\" or \"no,\" you should respond with \"yes\" or \"no\" and provide the relevant paragraph numbers from the judgment document.\n", | |
" </Instructions>\n", | |
" <Examples>\n", | |
" <Example>\n", | |
" Question: What legal standards were applied in the case of \"Smith vs. Jones\" regarding contract disputes?\n", | |
" In the case of \"Smith vs. Jones,\" the court applied several key legal standards to resolve the contract dispute. \n", | |
" The principle of \"offer and acceptance\" in contract formation was scrutinized, following the guidelines set by the precedent in \"Johnson & Co. vs. Exports Ltd.\" [1]. \n", | |
" The court also evaluated the \"intention to create legal relations,\" a fundamental aspect of contract law, as detailed in \"Doe vs. Roe\" [2]. \n", | |
" Paragragh 5, 12\n", | |
" </Example>\n", | |
" <Example>\n", | |
" Question: Did the court find the defendant guilty of the crime?\n", | |
" Yes, the court found the defendant guilty of the crime.\n", | |
" Paragragh 5, 12\n", | |
" </Example>\n", | |
" </Examples>\n", | |
"\n", | |
" \"\"\"\n", | |
"\n", | |
"USER_PROMPT = f\"\"\"\n", | |
" <LOE>\n", | |
" {LOE}\n", | |
" </LOE>\n", | |
"\n", | |
" <CV>\n", | |
" {CV}, \n", | |
" </CV>\n", | |
" \"\"\"\n", | |
"messages = [{ \"content\": SYSTEM_PROMPT,\"role\": \"system\"}, {\"content\": USER_PROMPT, \"role\": \"user\"}]\n", | |
"\n", | |
"# openai call\n", | |
"response = completion(model=\"openrouter/anthropic/claude-3-sonnet:beta\", messages=messages)\n", | |
"\n", | |
"print(response.choices[0].message.content)\n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": ".venv", | |
"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.11.4" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment