Spaces:
Sleeping
Sleeping
File size: 5,488 Bytes
c10e5be |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# π¬ PubMed Tool Configuration Guide
## Environment Variable Required
To enable the PubMed search tool in your ID Agents app, you need to set the following environment variable:
### **`NCBI_EMAIL`**
This is your email address that will be sent to NCBI (National Center for Biotechnology Information) with each API request.
---
## Why is Email Required?
NCBI requires an email address for E-utilities API access for the following reasons:
1. **API Usage Monitoring**: NCBI uses email to track API usage patterns
2. **Contact for Issues**: If there are problems with your requests, NCBI can contact you
3. **Terms of Service**: It's part of NCBI's E-utilities usage guidelines
4. **Rate Limiting**: Helps NCBI manage and enforce rate limits appropriately
---
## How to Set It Up
### Option 1: HuggingFace Space (Recommended)
1. Go to your HuggingFace Space: https://huggingface.co/spaces/John-jero/IDWeekAgents
2. Click on **"Settings"** (gear icon)
3. Navigate to **"Repository secrets"**
4. Click **"Add a secret"**
5. Enter:
- **Name**: `NCBI_EMAIL`
- **Value**: Your email address (e.g., `[email protected]`)
6. Click **"Save"**
7. **Restart your space** for changes to take effect
### Option 2: Local Development (.env file)
If running locally, create/edit your `.env` file:
```bash
# .env file
OPENAI_API_KEY=your-openai-api-key-here
[email protected]
```
---
## What Email Should I Use?
### β
Recommended:
- **Institutional email**: `[email protected]`
- **Work email**: `[email protected]`
- **Academic email**: `[email protected]`
### β οΈ Acceptable:
- Personal email (Gmail, Yahoo, etc.)
- Any valid email address
### β Not Recommended:
- Fake or invalid emails
- Generic emails like `[email protected]`
- Temporary/disposable emails
**Best Practice**: Use a real, professional email address associated with your institution or work.
---
## Optional: NCBI API Key
For **higher rate limits**, you can also register for a free NCBI API key:
### How to Get an NCBI API Key:
1. Go to: https://www.ncbi.nlm.nih.gov/account/
2. **Sign in** or **Register** for an NCBI account
3. Go to **Settings** β **API Key Management**
4. Click **"Create an API Key"**
5. Copy your API key
### Add to HuggingFace Space:
- **Name**: `NCBI_API_KEY`
- **Value**: Your NCBI API key
### Benefits:
- **Without API Key**: 3 requests/second
- **With API Key**: 10 requests/second
---
## Default Behavior
If you **don't set** `NCBI_EMAIL`, the tool will use a default:
```python
# From tools/pubmed_search.py line 67:
if not email:
email = "[email protected]"
logger.info("Using default email for NCBI API access")
```
This will work, but it's **better to set your own email** for:
- β
Proper attribution
- β
NCBI can contact you if needed
- β
Better compliance with NCBI guidelines
---
## How to Verify It's Working
### Test in Your Agent:
1. **Create an agent** with the **"search_pubmed"** skill
2. **Chat with the agent** and ask:
```
"Search PubMed for recent articles on C. difficile treatment"
```
3. **Check the response**:
- β
Should return recent articles with titles, authors, PMIDs
- β If error, check your email is set correctly
### Check Logs:
In your HuggingFace Space logs, you should see:
```
INFO: Using email: [email protected] for NCBI API access
```
---
## Complete Environment Variables Setup
For full functionality, set these in HuggingFace Space Settings β Repository secrets:
### **Required**:
```
OPENAI_API_KEY=sk-...your-openai-key
AUTH_CREDENTIALS=username:password,user2:pass2
```
### **Optional (but recommended)**:
```
NCBI[email protected]
NCBI_API_KEY=your-ncbi-api-key
SERPER_API_KEY=your-serper-key
```
---
## Troubleshooting
### Problem: PubMed search returns no results or errors
**Solution 1**: Check email is set
```bash
# In Space Settings β Secrets, verify:
NCBI_EMAIL = [email protected]
```
**Solution 2**: Restart your space after adding the secret
**Solution 3**: Check logs for specific error messages
### Problem: Rate limit errors
**Solution**: Add `NCBI_API_KEY` to increase rate limit from 3 to 10 requests/second
### Problem: "Invalid email" errors
**Solution**: Use a properly formatted email address: `[email protected]`
---
## Code Reference
The PubMed tool code is in: `tools/pubmed_search.py`
Key lines:
```python
# Line 37: Email parameter with environment variable default
"email": {"type": "string", "description": "user email for NCBI API",
"default": os.getenv("NCBI_EMAIL", "")}
# Line 62-67: Email fallback logic
if not email:
email = os.getenv("NCBI_EMAIL", "")
if not email:
email = "[email protected]"
logger.info("Using default email for NCBI API access")
```
---
## Quick Setup Checklist
- [ ] Go to HuggingFace Space Settings
- [ ] Navigate to Repository secrets
- [ ] Add secret: `NCBI_EMAIL` = your email
- [ ] (Optional) Add secret: `NCBI_API_KEY` = your API key
- [ ] Restart your space
- [ ] Test PubMed search with an agent
- [ ] Verify results are returned
---
## Summary
**Environment Variable**: `NCBI_EMAIL`
**Value**: Your email address
**Location**: HuggingFace Space Settings β Repository secrets
**Required**: Technically optional, but strongly recommended
**Format**: `[email protected]`
**After setting it, restart your space and the PubMed tool will work with your email!** π§π¬
|