Building a Troubleshoot Assistant using Lyzr SDK
Tags: ai, programming, python, lyzr
Published: 2024-06-10 13:32:22

In our tech-driven world, encountering technical issues is almost inevitable. Whether it’s a software glitch, hardware malfunction, or connectivity problem, finding quick and effective solutions can be challenging. Enter **TroubleShoot Assistant**, an AI-powered app designed to help you diagnose and resolve technical issues with ease.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5g4w3znquhfxsz7fxk3q.png)

The magic behind TroubleShoot Assistant lies in the **Lyzr SDK**, a powerful toolkit that leverages advanced AI models. The app processes user inputs to understand the technical issue, analyzes the information to identify the root cause, and generates a step-by-step strategy to resolve the problem. This ensures users receive accurate and practical solutions tailored to their specific issues.

**Why use Lyzr SDK’s?**

With Lyzr SDKs, crafting your own **GenAI** application is a breeze, requiring only a few lines of code to get up and running swiftly.

[Checkout the Lyzr SDK’s](https://docs.lyzr.ai/homepage)

**Lets get Started!**

Create an **app.py** file

```
import streamlit as st
from lyzr_automata.ai_models.openai import OpenAIModel
from lyzr_automata import Agent, Task
from lyzr_automata.pipelines.linear_sync_pipeline import LinearSyncPipeline
from PIL import Image
from lyzr_automata.tasks.task_literals import InputType, OutputType
import os
# Set the OpenAI API key
os.environ["OPENAI_API_KEY"] = st.secrets["apikey"]
```
In this section, we import the necessary libraries, including **Streamlit** for the web interface, Lyzr SDK components, and PIL for image processing. We also set the OpenAI API key for authentication.

```
st.markdown(
    """
    <style>
    .app-header { visibility: hidden; }
    .css-18e3th9 { padding-top: 0; padding-bottom: 0; }
    .css-1d391kg { padding-top: 1rem; padding-right: 1rem; padding-bottom: 1rem; padding-left: 1rem; }
    </style>
    """,
    unsafe_allow_html=True,
)
```
This section customizes the app’s appearance using **CSS** to hide the default Streamlit header and adjust padding.

```
image = Image.open("./logo/lyzr-logo.png")
st.image(image, width=150)
```
Here, we load and display the app’s logo using the **PIL library**.

```
# App title and introduction
st.title("TroubleShoot Assistant🤖")
st.markdown("Welcome to the TroubleShoot Assistant! Just describe your issue, and receive clear, step-by-step guidance to fix it.")
input = st.text_input("Please enter the issue or problem you are facing:", placeholder="Type here")
```
We set the app’s title and provide a **text input** field for users to describe their issue. This input is crucial for generating relevant troubleshooting steps

```

open_ai_text_completion_model = OpenAIModel(
    api_key=st.secrets["apikey"],
    parameters={
        "model": "gpt-4-turbo-preview",
        "temperature": 0.2,
        "max_tokens": 1500,
    },
)

```
We initialize the **OpenAI model** with the necessary parameters, including the API key, model type, temperature, and maximum tokens.

```
def generation(input):
    generator_agent = Agent(
        role="Expert TROUBLESHOOTING ASSISTANT",
        prompt_persona="Your task is to ADDRESS USER QUERIES related to technical issues they are encountering and PROVIDE SOLUTIONS or steps to RESOLVE those issues."
    )
    prompt = f"""
    You are an Expert TROUBLESHOOTING ASSISTANT. Your task is to ADDRESS USER QUERIES related to technical issues they are encountering and PROVIDE SOLUTIONS or steps to RESOLVE those issues.Here's how you should approach each query:
[Prompts here]
"""
    generator_agent_task = Task(
        name="Generation",
        model=open_ai_text_completion_model,
        agent=generator_agent,
        instructions=prompt,
        default_input=input,
        output_type=OutputType.TEXT,
        input_type=InputType.TEXT,
    ).execute()
    return generator_agent_task`
```
In this function, we define an agent with a specific role and persona. The agent’s task is to analyze the user’s issue and provide step-by-step **troubleshooting guidance**. The prompt includes detailed instructions on how the agent should approach each query.

```
if st.button("TroubleShoot!"):
    solution = generation(input)
    st.markdown(solution)
```
We add a button to trigger the troubleshooting process. When the button is clicked, the **generation function** is called, and the generated solution is displayed.

```
with st.expander("ℹ️ - About this App"):
    st.markdown("""
    This app uses Lyzr Automata Agent. For any inquiries or issues, please contact Lyzr.
    """)
    st.link_button("Lyzr", url='https://www.lyzr.ai/', use_container_width=True)
    st.link_button("Book a Demo", url='https://www.lyzr.ai/book-demo/', use_container_width=True)
    st.link_button("Discord", url='https://discord.gg/nm7zSyEFA2', use_container_width=True)
    st.link_button("Slack", url='https://join.slack.com/t/genaiforenterprise/shared_invite/zt-2a7fr38f7-_QDOY1W1WSlSiYNAEncLGw', use_container_width=True)
```
**TroubleShoot Assistant** is your reliable companion for resolving technical issues. By leveraging the advanced AI capabilities of Lyzr SDK, the app provides precise and easy-to-follow troubleshooting steps, ensuring you get back on track quickly. Say goodbye to tech headaches and hello to seamless troubleshooting.

**App link**: https://troubleshootassistant-lyzr.streamlit.app/

**Source Code**: https://github.com/isakshay007/TroubleShoot_Assistant

The **TroubleShoot Assistant** is powered by the Lyzr Automata Agent, utilizing the capabilities of OpenAI’s GPT-4 Turbo. For any inquiries or issues, please contact Lyzr. You can learn more about Lyzr and their offerings through the following links:

**Website**: [Lyzr.ai](https://www.lyzr.ai/)
**Book a Demo**: [Book a Demo](https://www.lyzr.ai/book-demo/)
**Discord**: [Join our Discord community](https://discord.com/invite/nm7zSyEFA2)
**Slack**: [Join our Slack channel](https://anybodycanai.slack.com/join/shared_invite/zt-2a7fr38f7-_QDOY1W1WSlSiYNAEncLGw#/shared-invite/email)