File size: 4,726 Bytes
9b5b26a
2117aee
9b5b26a
8b3b9a0
3138651
8b3b9a0
 
9b5b26a
 
c19d193
6aae614
8fe992b
9b5b26a
 
2117aee
 
 
 
 
 
 
 
 
 
9b5b26a
4a5a8b3
 
9b5b26a
4a5a8b3
9b5b26a
4a5a8b3
 
 
 
 
 
 
 
9b5b26a
 
4a5a8b3
 
9b5b26a
4a5a8b3
9b5b26a
4a5a8b3
 
 
 
 
 
 
 
 
 
 
 
 
2117aee
 
4a5a8b3
 
936b91e
4a5a8b3
936b91e
4a5a8b3
 
 
 
 
 
 
 
 
 
 
 
56ba493
4a5a8b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f553381
4a5a8b3
8c01ffb
4a5a8b3
 
 
 
 
 
56ba493
63d2490
 
861422e
 
9b5b26a
8c01ffb
8fe992b
4a5a8b3
8c01ffb
 
 
 
 
 
861422e
8fe992b
 
8c01ffb
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
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
from PIL import Image
import datetime
import os
import io
import qrcode
import base64
import requests
import pytz
import yaml
from tools.final_answer import FinalAnswerTool

from Gradio_UI import GradioUI

def image_path_to_markdown(path: str) -> str:
    try:
        with open(path, "rb") as f:
            img_bytes = f.read()
        img_base64 = base64.b64encode(img_bytes).decode("utf-8")
        return f"![Generated Image](data:image/png;base64,{img_base64})"
    except Exception as e:
        return f"Image saved at: {path} (Failed to embed image: {str(e)})"


@tool
def greeting_tool(greeting: str) -> str:
    """A tool to respond to user greetings and start a conversation.
    Args:
        greeting: The greeting message from the user (e.g., 'Hello', 'Hi')
    """
    responses = [
        "Hello! I'm your Tech Troubleshooting Assistant. How can I help you today?",
        "Hi there! What tech issue are you experiencing?",
        "Greetings! I'm here to help with your technical problems. What's troubling you?",
        "Hello! Ready to solve some tech problems? What's the issue?"
    ]
    import random
    return random.choice(responses)

@tool
def basic_troubleshooting(problem: str) -> str:
    """Provides basic troubleshooting steps for common tech issues.
    Args:
        problem: Description of the technical problem
    """
    common_solutions = {
        "internet": "1. Restart your router\n2. Check cable connections\n3. Restart your device\n4. Contact your ISP if problem persists",
        "printer": "1. Check power and connections\n2. Restart printer\n3. Reinstall drivers\n4. Check for paper jams",
        "slow computer": "1. Close unused programs\n2. Run disk cleanup\n3. Check for malware\n4. Add more RAM if needed",
        "email": "1. Check internet connection\n2. Verify login credentials\n3. Check server status\n4. Try webmail version"
    }
    
    problem_lower = problem.lower()
    for key in common_solutions:
        if key in problem_lower:
            return f"For {problem}:\n\n{common_solutions[key]}"
    
    return f"For {problem}, try these general steps:\n1. Restart the device\n2. Check for updates\n3. Verify connections\n4. Search online for specific solutions"

@tool
def check_service_status(service: str) -> str:
    """Checks the status of popular online services.
    Args:
        service: Name of the service to check (e.g., 'Gmail', 'AWS')
    """
    status_pages = {
        "gmail": "https://www.google.com/appsstatus",
        "aws": "https://health.aws.amazon.com/",
        "microsoft": "https://portal.office.com/servicestatus",
        "slack": "https://status.slack.com/",
        "zoom": "https://status.zoom.us/"
    }
    
    service_lower = service.lower()
    if service_lower in status_pages:
        return f"You can check {service}'s status here: {status_pages[service_lower]}"
    return f"I don't have a direct link for {service}'s status page. Try searching 'Is {service} down?' on a search engine."

@tool
def software_update_check(os_type: str) -> str:
    """Provides instructions for checking software updates on different operating systems.
    Args:
        os_type: The operating system (Windows, Mac, Linux, Android, iOS)
    """
    instructions = {
        "windows": "1. Open Settings\n2. Go to Update & Security\n3. Click Check for updates",
        "mac": "1. Click Apple menu\n2. Select System Preferences\n3. Click Software Update",
        "linux": "For Ubuntu: Run 'sudo apt update && sudo apt upgrade' in terminal",
        "android": "1. Open Settings\n2. Tap System\n3. Tap Advanced\n4. Tap System update",
        "ios": "1. Open Settings\n2. Tap General\n3. Tap Software Update"
    }
    
    os_lower = os_type.lower()
    if os_lower in instructions:
        return f"To check for updates on {os_type}:\n\n{instructions[os_lower]}"
    return f"I don't have specific instructions for {os_type}. Try searching online for 'how to check updates on {os_type}'."

final_answer = FinalAnswerTool()

model = HfApiModel(
    max_tokens=2096,
    temperature=0.5,
    model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
    custom_role_conversions=None,
)

search_tool = DuckDuckGoSearchTool()

with open("prompts.yaml", 'r') as stream:
    prompt_templates = yaml.safe_load(stream)
    
agent = CodeAgent(
    model=model,
    tools=[final_answer, greeting_tool, basic_troubleshooting, check_service_status, software_update_check, search_tool],
    max_steps=6,
    verbosity_level=1,
    grammar=None,
    planning_interval=None,
    name=None,
    description=None,
    prompt_templates=prompt_templates
)

GradioUI(agent).launch()