Logo Lanfrica

laws-africa/knowledge-base-examples

Domaine:

natural language processing

Type de record:

software
Créateur:
law
Hôte:
# Laws.Africa Knowledge Base Examples This repo contains an example of using the Laws.Africa Knowledge Base API in a simple RAG setup with LangGraph. The example restricts its queries to Cape Town using the place code `za-cpt`. ## What it does 1. Takes a user **query** as input 2. Uses an LLM to come up with a search query for the Knowledge Base, based on the user's query. 3. Searches the Knowledge Base using the generated search query to retrieve relevant documents. 4. Answers the user's query using the retrieved documents as context. ## Requirements 1. Python 3.11 or later 2. An OpenAI API key. 3. A Laws.Africa API key. You can get one by following these instructions. ## Setup 1. Clone this repository and navigate to the project directory: ```bash git clone cd laws-africa-knowledge-base-examples ``` 2. Setup a virtual environment (optional but recommended): ```bash python -m venv venv source venv/bin/activate ``` 3. Install dependencies: ```bash pip install -r requirements.txt ``` ## Configuration 1. Set your OpenAI and Laws.Africa API keys as environment variables, or add them to a new `.env` file: ```bash export OPENAI_API_KEY='your-openai-api-key' export LAWS_AFRICA_API_KEY='your-laws-africa-api-key' ``` ## Running the agent ### Running the agent with LangGraph CLI This is a simple visual way to run the agent, using the LangGraph CLI and LangGraph's Agent Chat UI. ```bash langgraph dev --no-browser ``` Open your browser and go to agentchat.vercel.app Type in `legislation_agent` or `judgment_agent` to choose the respective agent and click Continue. That will present you with a chat interface where you can interact with the agent. Ask: `How many dogs can I own?` or `Cases for delict in a slip and trip scenario` ### Running the agent with a Python script You can also run the agent directly using the provided `agent.py` script. It requires a single argument to choose which knowledge base agent to run: …