This repository contains the code for a movie recommendation chatbot, inspired by classic conversational agents like ELIZA and GUS, and extended with modern LLM (Large Language Model) capabilities. The chatbot interacts with users to learn their movie preferences and recommends films using collaborative filtering. It supports three modes:
- Starter (GUS) Mode: Classic rule-based movie recommendation.
- LLM Prompting Mode: Uses prompt engineering to guide an LLM for movie-focused conversations.
- LLM Programming Mode: Combines Python logic and LLM calls for advanced, creative chatbot features.
- Features
- Project Structure
- Setup & Installation
- Usage
- Testing
- Data & Resources
- Extending the Chatbot
- Contributing
- License
- Conversational Movie Recommendations: Learns user preferences and suggests movies.
- Sentiment Analysis: Detects positive, negative, or neutral sentiment about movies.
- Title Extraction: Identifies movie titles from user input, including handling of foreign titles.
- Collaborative Filtering: Recommends movies using item-item cosine similarity.
- LLM Integration: Supports both prompt-based and programmatic LLM calls for richer interactions.
- Scripted and Interactive Testing: Includes scripts and tools for automated and manual testing.
pa7-chatbot-main/
│
├── chatbot.py # Main chatbot logic (all modes)
├── repl.py # REPL interface for interactive/chat mode
├── util.py # Utility functions (data loading, LLM calls)
├── porter_stemmer.py # (Optional) Stemming utility
├── data/
│ ├── movies.txt # Movie titles and genres
│ ├── ratings.txt # User-movie ratings matrix
│ └── sentiment.txt # Sentiment lexicon
├── examples/
│ ├── json_llm_example.py # Example: LLM JSON output
│ └── simple_llm_example.py # Example: LLM prompt output
├── testing/
│ ├── sanitycheck.py # Sanity check script for core functions
│ ├── run_all_scripts.sh # Run all test scripts
│ └── test_scripts/
│ ├── simple.txt
│ ├── standard/
│ │ ├── fail_gracefully.txt
│ │ └── recommend.txt
│ ├── llm_prompting/
│ │ ├── distraction_easy.txt
│ │ ├── distraction_hard.txt
│ │ ├── recommend.txt
│ │ └── simple.txt
│ └── llm_programming/
│ ├── arbitrary.txt
│ ├── emotions.txt
│ ├── foreign.txt
│ └── persona.txt
├── outputs-for-scripts/ # Output transcripts for test scripts
├── generate_submission.sh # Script to create submission.zip
├── rubric.txt # Rubric for grading (edit to indicate features)
└── README.md # Original assignment README
-
Clone the repository:
git clone <repo-url> cd pa7-chatbot-main
-
Set up the Python environment:
- Recommended: Use the
cs124conda environment from PA0. - Install required packages:
conda activate cs124 pip install openai
- Recommended: Use the
-
API Key for LLM Features:
- For LLM modes, add your Together API key to
api_keys.py:TOGETHER_API_KEY = "your-key-here"
- See Together API instructions.
- For LLM modes, add your Together API key to
-
Starter Mode (default):
python3 repl.py
-
LLM Prompting Mode:
python3 repl.py --llm_prompting
-
LLM Programming Mode:
python3 repl.py --llm_programming
-
Run a test script:
python3 repl.py < testing/test_scripts/simple.txt -
Run all test scripts:
sh testing/run_all_scripts.sh
-
Run sanity checks:
python3 testing/sanitycheck.py # or for LLM mode: python3 testing/sanitycheck.py --llm_programming
- Movie Data:
data/movies.txt(titles, genres),data/ratings.txt(user ratings) - Sentiment Lexicon:
data/sentiment.txt(word,sentiment pairs) - LLM Examples: See
examples/for how to use LLM calls in both prompt and JSON modes.
- All main logic is in
chatbot.py. Implement or extend:extract_titles,find_movies_by_title,extract_sentiment,recommend,binarize, and LLM-related methods.
- For LLM Programming Mode, see the
llm_enabledflag and the use ofutil.simple_llm_callandutil.json_llm_call. - Add new features or experiment with creative LLM prompts!
- Test Scripts: Located in
testing/test_scripts/:llm_prompting/– LLM prompt mode testsllm_programming/– LLM programming mode testsstandard/– Standard mode testssimple.txt– Basic interaction test
- Outputs: See
outputs-for-scripts/for sample outputs.
- Please follow the assignment guidelines.
- If you add dependencies, place them in a
deps/folder. - Keep your submission under 100KB as required.
This project is for educational use in Stanford CS124. See assignment policies for details.
- Based on the CS124 PA7 assignment.
- MovieLens dataset used for movie data.
- LLM integration via Together API.
For more details, see the in-depth assignment instructions in the original README and the rubric.