A simple Streamlit web application for testing the CUHK Azure OpenAI API. This tool helps students learn and experiment with the API while monitoring their usage.
- This repository is for learning purposes only
- Run the application locally on your machine
- Do NOT deploy to cloud platforms
- Keep your API keys secure and never expose them online
- For learning use only
This application is designed for local development and learning purposes only. Deploying it to the cloud or public servers poses several risks:
-
API Key Exposure: Your CUHK Azure OpenAI API key could be exposed, leading to:
- Unauthorized usage of your quota
- Potential misuse of CUHK's resources
- Risk of exceeding rate limits
-
Access Control: The app doesn't implement:
- User authentication
- Rate limiting
- IP restrictions
- Other security measures needed for production
-
Compliance: Public deployment may violate:
- CUHK's API usage policies
- Data protection requirements
- Service terms and conditions
Always run this application locally and never share your API keys!
CUHK places very high importance on academic honesty. Use of these APIs must comply with CUHK's Policy on Academic Honesty:
-
Appropriate Use:
- Use the API as a learning tool to understand AI capabilities
- Practice responsible AI development
- Enhance your understanding of AI concepts
-
Prohibited Uses:
- Do NOT use the API to generate assignments or exam answers
- Do NOT submit AI-generated content as your own work
- Do NOT use the API to assist in any form of academic dishonesty
-
Consequences:
- CUHK maintains a zero-tolerance policy on academic dishonesty
- Violations may lead to disciplinary action
- Serious cases may result in termination of studies
Always consult with your professors about appropriate use of AI tools in your coursework. When in doubt, ask first!
-
API Key Protection:
- NEVER share your API key with anyone
- NEVER commit your
.env
file to version control - NEVER expose your key in public repositories or forums
- NEVER include your key in screenshots or shared code
- Immediately report if you suspect your key has been compromised
-
Local Development Only:
- This app is designed for local use only
- DO NOT deploy to public servers or cloud platforms
- DO NOT expose the app outside your local network
- Always run on localhost (127.0.0.1)
-
Data Privacy:
- Be mindful of what data you send to the API
- DO NOT submit sensitive or personal information
- DO NOT submit confidential university data
- Consider data privacy regulations when using the service
Please be aware of the following regarding AI-generated content:
-
Accuracy: While AI models strive for accuracy, they may occasionally:
- Provide incorrect or outdated information
- Make mistakes in calculations or reasoning
- Generate plausible-sounding but inaccurate responses
-
Limitations:
- AI responses should be verified, especially for critical applications
- Models may exhibit biases present in their training data
- Complex or nuanced topics may require human expertise and verification
-
Best Practices:
- Always verify important information from authoritative sources
- Use AI-generated content as a starting point, not the final answer
- Exercise critical thinking and professional judgment
- When in doubt, consult with professors or domain experts
- Test API calls with predefined cases
- Monitor API usage and rate limits
- View code examples
- Track API response times
- Export usage statistics
- This is a learning tool - use it responsibly
- Keep your API key secure
- Monitor your usage to avoid hitting limits
- Plan ahead if you need expanded access
- CUHK account
- Python 3.8 or higher
- Git (for cloning the repository)
-
Prerequisites:
# Make sure you have Python 3.8+ installed python --version # Create and activate a virtual environment python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Installation:
# Clone this repository git clone https://github.com/gai4learning/apip.git cd apip # Install dependencies pip install -r requirements.txt # Set up environment variables cp .env.example .env # Edit .env with your API key
-
Running the App:
streamlit run app.py
-
First Time Setup:
- Get your API key (see Getting Your API Key below)
- Enter your key in the app
- Test with a simple prompt first
- Check the logs to ensure everything works
-
Troubleshooting:
- Check the logs in the sidebar
- Verify your API key is correct
- Ensure you're within rate limits
- Read error messages carefully
-
Access the Portal
- Go to CUHK API Developer Portal
- Sign up / in with your CUHK account (top right corner)
-
Subscribe to Starter Plan
- Navigate to "Products" in the top menu
- Click on "Starter"
- Under "Your subscription", enter "Starter" as "Your new product subscription name"
- Click "Subscribe"
- You should be automatically re-directed to "Profile" to review the Subscription information
-
Get Your API Keys
- After approval, you'll see both Primary and Secondary keys
- Use either key in your
.env
file - Regenerate your keys as needed or regularly
-
Monitor Your usage
- Regularly review your usage of the APIs under "Reports"
-
Chat Models:
gpt-4o-mini
: Quick responses, good for testing and simple tasksgpt-4o
: Complex reasoning, detailed explanations, and longer contextso1-mini
: Latest model with improved efficiency and quality
-
Image Generation:
dall-e-3
: Create detailed images from text descriptions- Photorealistic images
- Artistic illustrations
- Technical diagrams
- Educational visuals
-
Embedding Models:
text-embedding-ada-002
: Legacy model for:- Basic semantic search
- Text similarity
- Content clustering
text-embedding-3-small
: Latest model for:- Improved semantic understanding
- Better multilingual support
- More accurate similarity comparisons
- 5 calls per minute
- 100 calls per week maximum
- Email notification at 75% of quota
- Weekly quota renewal
Your API usage is monitored by CUHK. Please note:
-
Usage Tracking:
- All API calls are logged and monitored
- Usage patterns are analyzed for abnormal behavior
- Rate limits and weekly quotas are strictly enforced
-
Warning: Excessive or abnormal usage patterns and use of the APIs for purposes other than learning will result in:
- Immediate suspension of your API access
- Investigation of usage patterns
- Reporting to relevant academic units
- Possible disciplinary actions
-
Prohibited Activities:
- Attempting to circumvent rate limits
- Sharing API keys with others
- Using the service for non-academic purposes
- Automated mass requests
- Any form of commercial use
Use the API responsibly and only for authorized academic purposes. If you need increased limits for legitimate academic work, please follow the proper channels to request expanded access.
If you need higher rate limits or access to additional features, you'll need to request expanded access.
- Hitting rate limits frequently
- Need higher throughput
- Require access to more models
- Working on research projects
-
Prepare Information:
- Project name and description
- Course code (if applicable)
- Expected duration
- Usage requirements
- Technical justification
-
Submit Request:
- Access the ITSC Service Desk System:
- Create a new General Enquiry under Category E-Learning Service
- Category: "Azure OpenAI API - Access Extension Request"
- Include your supervisor's information if applicable
-
Request Template:
Subject: Azure OpenAI API - Access Extension Request
Project Details:
- Name: [Your Project Name]
- Course: [Course Code, if applicable]
- Duration: [Expected timeline]
Current Limitations:
- [Describe what limits you're hitting]
Requested Access:
- [Specify needed rate limits]
- [List required models]
Justification:
- [Brief explanation]