This application demonstrates how to build a chatbot that interacts with the Congress.gov API using Go, Fiber, and LangChainGo, deployable on Tanzu Platform for Cloud Foundry.
A web-based chatbot application that allows users to interact with the Congress.gov API to fetch information about bills, amendments, summaries, and members in natural language. The application uses LangChainGo to integrate with GenAI's LLM service for natural language processing.
The chatbot features a toggle that allows users to switch between:
- API Tools Mode (enabled by default): Uses real-time API calls to Congress.gov for up-to-date information
- Model-Only Mode: Relies on the LLM's pre-trained knowledge without making external API calls
- Go 1.18+ installed locally for development
- Access to Congress.gov API (get your API key at https://api.congress.gov/sign-up/)
- For Tanzu deployment:
- Tanzu Platform for Cloud Foundry environment
- Access to GenAI tile and LLM service instances
- Cloud Foundry CLI installed
Build a binary:
go build -o congress-chatbot cmd/server/main.gogit clone https://github.com/cf-toolsuite/tanzu-genai-showcase.git
cd tanzu-genai-showcase/go-fiber-langchaingocp .env.example .envEdit the .env file to include your API keys:
CONGRESS_API_KEY=your_congress_api_key
GENAI_API_KEY=your_GENAI_API_KEY
GENAI_API_BASE_URL=your_GENAI_API_BASE_URL
LLM=gpt-4o-mini
Note: The
LLMenvironment variable allows you to specify which language model to use. If not set, it defaults togpt-4o-mini.
go mod tidygo run cmd/server/main.goThe application will be available at http://localhost:8080
- Open the application in your web browser at http://localhost:8080
- You'll see the chatbot interface with a toggle switch labeled "Use API Tools" in the top-right corner
- By default, the toggle is enabled, which means the chatbot will make real-time API calls to Congress.gov for up-to-date information
- You can disable the toggle if you want the chatbot to rely solely on the LLM's pre-trained knowledge without making external API calls
- Type your question in the input field and press Enter or click the Send button
- When API Tools mode is enabled, responses will include a small "🔧 Response generated using API tools" indicator
With API Tools enabled (recommended for current information):
- "Who are the current senators from Washington state?"
- "What is the status of bill S.1260 in the 117th Congress?"
- "List the committees in the House of Representatives"
With API Tools disabled (for general knowledge questions):
- "How does a bill become a law?"
- "What is the role of the Speaker of the House?"
- "Explain the difference between the House and Senate"
cf push --no-start
cf set-env congress-chatbot CONGRESS_API_KEY ${CONGRESS_API_KEY}# List available plans for the GenAI service offering
cf marketplace -e genai
# Create an LLM service instance (if not already created)
cf create-service genai PLAN_NAME congress-llmImportant
Replace PLAN_NAME above with the name of an available plan of the GenAI tile service offering
# Bind the service to your application
cf bind-service congress-chatbot congress-llm
# Start your application to apply the binding
cf start congress-chatbot- Go: Programming language
- Fiber: Web framework for building the API and serving the web interface
- LangChainGo: Framework for building applications with large language models
- Congress.gov API: External API for fetching legislative data
- GenAI LLM Service: Large language model service provided by Tanzu Platform for Cloud Foundry
Detailed documentation is available in the docs/ directory:
- Architecture: System architecture, components, and data flow
- API: API endpoints and usage
- Development: Development setup and workflow
- Deployment: Deployment instructions and environments
- Testing: Testing strategies and procedures
- Troubleshooting: Common issues and solutions
- Features: Detailed feature descriptions
- Implementation: Implementation details
- Logging: Logging configuration and usage
├── api/ # API clients (Congress.gov)
├── cmd/ # Application entry points
├── config/ # Configuration handling
├── docs/ # Documentation
├── internal/ # Private application code
├── pkg/ # Public libraries
├── .env.example # Example environment variables
├── go.mod # Go module definition
├── manifest.yml # Cloud Foundry manifest
└── README.md # This file