Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

Symptom Diagnostic Telegram Bot

A beginner-friendly Telegram chatbot that uses OpenAI to provide symptom analysis and health information. This bot demonstrates three key concepts: API calling, custom tools, and function calling.

🏥 Features

  • Symptom Analysis: Describe your symptoms and get possible conditions
  • Health Recommendations: Receive general health advice and when to see a doctor
  • Emergency Detection: Automatically detect symptoms that may require immediate attention
  • Symptom Categories: Browse common symptom categories
  • Educational Focus: Provides information for educational purposes only

🔧 Key Concepts Demonstrated

1. API Calling

  • What it is: Making HTTP requests to external services (like OpenAI)
  • Example in this bot: client.chat.completions.create() to get AI responses
  • Why it's important: Allows your bot to access powerful AI capabilities

2. Custom Tools

  • What it is: Functions that extend your bot's capabilities beyond just chat
  • Examples in this bot:
    • get_emergency_guidance() - Detects emergency symptoms
    • get_severity_assessment() - Assesses symptom severity
  • Why it's important: Gives your bot specialized functionality

3. Function Calling

  • What it is: AI can automatically decide when to use specific tools
  • How it works: AI analyzes user input and calls appropriate functions
  • Example: User mentions "chest pain" → AI calls get_emergency_guidance()
  • Why it's important: Makes your bot more intelligent and responsive

📁 Project Structure

symptom-diagnostic-bot/
├── bot.py              # Main bot logic (Telegram handlers)
├── utils.py            # OpenAI API calls and custom tools
├── requirements.txt    # Python dependencies
├── .env               # Environment variables (create this)
└── README.md          # This file

🚀 Setup Instructions

1. Create Telegram Bot

  1. Message @BotFather on Telegram
  2. Send /newbot and follow instructions
  3. Save your bot token

2. Get OpenAI API Key

  1. Go to OpenAI Platform
  2. Create account and get API key
  3. Save your API key

3. Setup Environment

# Create project directory
mkdir symptom-diagnostic-bot
cd symptom-diagnostic-bot

# Create virtual environment
python -m venv bot-venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Create .env file
echo "TELEGRAM_BOT_TOKEN=your_telegram_bot_token_here" > .env
echo "OPENAI_API_KEY=your_openai_api_key_here" >> .env

4. Run the Bot

python bot.py

💡 How to Use

  1. Start the bot: Send /start to your bot
  2. Get diagnosis: Use /diagnose and describe your symptoms
  3. Browse symptoms: Use /symptoms to see common categories
  4. Get help: Use /help for command list

⚠️ Important Disclaimers

  • Educational Purpose Only: This bot provides general health information for educational purposes
  • Not Medical Advice: Always consult healthcare professionals for proper diagnosis
  • No Emergency Service: For emergencies, call emergency services immediately
  • AI Limitations: AI responses may not always be accurate or complete

🔍 Code Examples

API Calling Example

# Making OpenAI API call
response = client.chat.completions.create(
    model="gpt-3.5-turbo",
    messages=[{"role": "user", "content": "Analyze these symptoms"}],
    temperature=0.3
)

Custom Tool Example

def get_emergency_guidance(symptoms: str) -> str:
    emergency_keywords = ['chest pain', 'difficulty breathing']
    # Check for emergency symptoms
    # Return appropriate guidance

Function Calling Example

# Define tools for AI to use
tools = [
    {
        "type": "function",
        "function": {
            "name": "get_emergency_guidance",
            "description": "Check for emergency symptoms"
        }
    }
]

🛠️ Advanced Features

The bot includes advanced function calling capabilities in utils.py:

  • Emergency symptom detection
  • Severity assessment
  • Structured JSON responses
  • Error handling and fallbacks

📚 Learning Resources

🤝 Contributing

Feel free to improve this bot by:

  • Adding more custom tools
  • Enhancing error handling
  • Improving the UI/UX
  • Adding more health-related features

📄 License

This project is for educational purposes. Please ensure compliance with OpenAI's terms of service and Telegram's bot policies.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages