{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import pandas as pd\n",
"import langchain\n",
"from langchain.agents import OpenAIFunctionsAgent, AgentExecutor\n",
"from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder\n",
"from langchain.tools import PythonAstREPLTool\n",
"from langchain.chat_models import ChatOpenAI\n",
"from pydantic import BaseModel, Field\n",
"from langchain.memory import ConversationBufferMemory\n",
"from langchain.schema.output_parser import StrOutputParser\n",
"import json\n",
"import gradio as gr\n",
"from dotenv import load_dotenv\n",
"load_dotenv()"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {},
"outputs": [],
"source": [
"langchain.debug = True\n",
"data_dir_path = os.path.join(os.getcwd())\n",
"pd.set_option('display.max_rows', 20)\n",
"pd.set_option('display.max_columns', 20)\n",
"NUM_ROWS_TO_RETURN = 5"
]
},
{
"cell_type": "code",
"execution_count": 93,
"metadata": {},
"outputs": [],
"source": [
"def get_data_str_from_df_for_prompt(df, use_head=True, num_rows_to_return=NUM_ROWS_TO_RETURN):\n",
" data = df.head(num_rows_to_return) if use_head else df.tail(num_rows_to_return)\n",
" return f'
\n", " | case_date | \n", "lastname | \n", "firstname | \n", "case_type | \n", "case_id | \n", "court_fee | \n", "jurisdiction | \n", "
---|---|---|---|---|---|---|---|
0 | \n", "2023-05-12 | \n", "Kim | \n", "Miguel | \n", "Civil | \n", "CR-1095 | \n", "100 | \n", "BOSTON | \n", "
1 | \n", "2023-04-20 | \n", "Lee | \n", "John | \n", "Criminl | \n", "CR-8597 | \n", "150 | \n", "houston | \n", "
2 | \n", "2023-02-10 | \n", "Smith | \n", "Dmitri | \n", "Criminal | \n", "CR-6833 | \n", "200 | \n", "chicago | \n", "
3 | \n", "2023-03-16 | \n", "Patel | \n", "Dmitri | \n", "Criminal | \n", "CR-2899 | \n", "100 | \n", "BOSTON | \n", "
4 | \n", "2023-06-15 | \n", "Ivanov | \n", "Jane | \n", "Family | \n", "CR-5997 | \n", "200 | \n", "houston | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
95 | \n", "2023-08-13 | \n", "Rodriguez | \n", "Jane | \n", "Familly | \n", "CR-8883 | \n", "200 | \n", "chicago | \n", "
96 | \n", "2023-03-27 | \n", "Patel | \n", "John | \n", "Familly | \n", "CR-2838 | \n", "100 | \n", "BOSTON | \n", "
97 | \n", "2023-07-27 | \n", "Okafor | \n", "Miguel | \n", "Criminal | \n", "CR-3885 | \n", "250 | \n", "new York | \n", "
98 | \n", "2023-01-14 | \n", "Ivanov | \n", "Alan | \n", "Family | \n", "CR-1066 | \n", "250 | \n", "houston | \n", "
99 | \n", "2023-03-20 | \n", "Okafor | \n", "Oluwaseun | \n", "Criminl | \n", "CR-9851 | \n", "200 | \n", "chicago | \n", "
100 rows × 7 columns
\n", "