Embark on a Journey Towards Your Goals with VisionQuestFrameworks Pt 1 of X
Tags: ui, productivity, python, ai
Published: 2023-12-18 06:08:03

TLDR;
Repo Quick-Access
Primary App: [VisionQuest](https://github.com/MAKaminski/VisionQuest)
Side-Project: [data_analysis](https://github.com/MAKaminski/data_analysis)
Extension: [Python Resource Monitor](https://marketplace.visualstudio.com/items?itemName=kaih2o.python-resource-monitor)

---

Hey there, tech enthusiasts and dream chasers! Welcome to the inaugural chapter of our weekly series on VisionQuest, a project that's about to transform the way you chase your dreams and goals. In this journey, we'll dive into the exciting world of VisionQuest, from its grand vision to the progress we've made so far.


![Grand Vision](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x9ay5uwhy2t6eq3whgf2.png)


**The Grand Vision:** Your Personal AI Coach 🤖
At the core of VisionQuest lies a bold aspiration: to create a Personal AI Coach, omni-scient, and ever present - basically clippy back from windows 95.  Ok, but we make some enhancements – an AI mentor that not only comprehends your goals but also tracks your journey and offers timely guidance to ensure your success. Whether you're striving for personal growth, professional achievements, or a healthier lifestyle, VisionQuest is your trusted companion on this path to greatness.

In my case the goal of VisionQuest is to keep me guided towards my goals, with auto-coaching.


![Auto-Coaching](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1ht7gfwaer749h2pofl5.png)


## Progress Report 🚀
**Ideation Phase**

Here's what we're initially setting out to accomplish:

**Goal Setting:** Our journey began with the simple act of setting and tracking goals. VisionQuest empowers you to remain laser-focused on what matters most to you.

**Customizable Coaching Intervals:** We introduced coaching intervals of 2 minutes, 5 minutes, 10 minutes, or 20 minutes, letting you tailor the guidance to your pace.

**AI-Powered Coaching:** Our AI algorithms are in a constant state of evolution, delivering personalized coaching that aligns with your goals and progress.

The actual progress we make week-by-week will vary depending on anything we get hung-up on.  This is an educational journey, or perhaps a case-study in how VisionQuest may be able to keep a wandering mind on track.


![Stay Focused](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iaebdiae9wta5tak45h2.png)


## Diving into the VisionQuest Codebase
The codebase of VisionQuest, a PyQt5-based application that interacts with the OpenAI API to generate responses to user prompts. You can check out the full code on [Github](https://github.com/MAKaminski/VisionQuest/tree/main), but I'll be sharing some juicy snippets right here.

**The Heart of the App: MainWindow**
At the heart of the application is the MainWindow class. This is where the magic happens. It's responsible for the user interface and the main functionality of the application.

```
class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("VisionQuest")
        self.userName = self.getUserName()
        self.initUI()
```

**Setting the Stage: initUI**
The initUI method is where we set up the stage for our application. We're talking window flags, background, position, and transparency. We also create the chat log and send prompt sections here.

```
def initUI(self):
    self.setWindowFlags(Qt.FramelessWindowHint)
    self.setWindowOnTop()
    self.setGradientBackground()
    self.moveWindowToTopRight()
    self.setTransparency()
```

**The Pulse: Frequency and Countdown**
The createMenuBar method is where we create a menu bar with frequency options. This frequency determines how often a prompt is sent to the OpenAI API. We also have a countdown timer that ticks down to the next prompt.

```
def createMenuBar(self):
    menu_bar = self.menuBar()
    self.createFrequencyMenu(menu_bar)
    self.frequency = 5  # Default frequency is 5 seconds
```

**The Conversation Starter: sendPrompt**
The sendPrompt method is where we send prompts to the OpenAI API and receive responses. We select a random prompt from a list, send it to the API, log the response, and update the chat log.

```
def sendPrompt(self):
    prompt = random.choice(prompts)
    response = oapi.get_openai_response(prompt)
    self.log_to_db("OpenAI_Model", response, "receiver")
    self.updateChatLog()
```

**The Memory: Chat Log**
The createChatLog and updateChatLog methods are where we create and update the chat log. The chat log is stored in a SQLite database, because who doesn't love a good SQLite database?

```
def createChatLog(self):
    conn = sqlite3.connect('chat_log.db')
    c = conn.cursor()
    c.execute('''CREATE TABLE IF NOT EXISTS chat_log
                (id INTEGER PRIMARY KEY AUTOINCREMENT, time TEXT, type TEXT, username TEXT, message TEXT)''')
```

## Interacting with OpenAI's GPT-3.5 Turbo Model
In this section, we will look at a Python script that uses OpenAI's GPT-3.5 Turbo model to generate responses to user questions. This can be useful in a variety of applications, such as chatbots, virtual assistants, and more.

**Code Explanation**

```
from openai import OpenAI

vision_quest_api = 'OpenAI-Key'
client = OpenAI(api_key=vision_quest_api)
```

We start by importing the OpenAI module and initializing a client with our OpenAI API key.

```
def get_openai_response(user_question):
    completion = client.chat.completions.create(
        model="gpt-3.5-turbo",
        messages=[
            {"role": "system", "content": "You are a productivity enhancer, evaluating what people are doing at fixed intervals and recommending specific paths of action to help them reach their ultimate goal."},
            {"role": "user", "content": user_question}
        ]
    )

    return completion.choices[0].message.content
```

The get_openai_response function takes a user question as an argument. It sends a chat completion request to the GPT-3.5 Turbo model with two messages: a system message that sets the behavior of the assistant, and a user message that contains the user's question.

The system message tells the model that it is a "productivity enhancer" that recommends actions to help people reach their goals. This sets the context for the conversation and guides the model's responses.

The user message is the question that we want the model to answer.


![Messaging](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yec0f60tn9qcwi9ia62y.png)


The function then returns the content of the model's response. This is the text that the model generated in response to the user's question.

## Convert Images to Icons with PyQt5 and PIL
We wanted to ensure we had a neat looking logo that matched our theme, we prompted DALE for an image - which was saved as .jpeg, then required conversion to .ico - we decided to create a utility. 

In this section, we will explore a simple Python script that uses PyQt5 and PIL (Python Imaging Library) to convert images to icons. This can be useful in various scenarios, such as when you're developing a desktop application and need to create an icon for it.

**Code Explanation**

```
from PyQt5.QtWidgets import QApplication, QFileDialog
from PIL import Image
import sys
```

We start by importing the necessary modules. QApplication and QFileDialog from PyQt5 are used to create a simple GUI for selecting the image file. Image from PIL is used to handle the image processing.

```
def convert_to_icon(filename):
    img = Image.open(filename)
    img = img.resize((32, 32))  # resize image to 32x32 pixels
    ico_filename = filename.rsplit('.', 1)[0] + '.ico'
    img.save(ico_filename, format='ICO', sizes=[(32,32)])
```

The convert_to_icon function takes a filename as an argument. It opens the image, resizes it to 32x32 pixels (the standard size for icons), and saves it in ICO format. The new icon file will have the same name as the original image file, but with the .ico extension.

```
if __name__ == "__main__":
    app = QApplication([])
    filename, _ = QFileDialog.getOpenFileName()
    if filename:
        convert_to_icon(filename)
    sys.exit(app.exec_())
```

In the main part of the script, we create a QApplication instance and use QFileDialog.getOpenFileName() to open a file dialog for the user to select an image file. If a file is selected (i.e., if filename is not an empty string), we call convert_to_icon to convert the image to an icon. Finally, we call sys.exit(app.exec_()) to ensure a clean exit when the application is closed.

This script provides a simple way to convert images to icons using PyQt5 and PIL. It can be easily extended or integrated into other projects.

## Round-Up & Kickers

**A Nod to Efficiency**
Here's the kicker: I've integrated a resource monitor to keep an eye on memory usage. Why, you ask? Well, I'm also working on this cool data analysis project ([check it out](https://github.com/MAKaminski/data_analysis)) and being resource-efficient is my jam!

![Resource Manager](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ujvovkqf34jzpuw04t5m.png)

Name: [Python Resource Monitor](https://marketplace.visualstudio.com/items?itemName=kaih2o.python-resource-monitor)

**The Look and Feel**
Right now, VisionQuest rocks a transparent blue UI. It's like looking through a futuristic window where you can chat with AI. Pretty neat, huh?


![Look and Feel](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lbj8qc1iczdsfpucvk7i.png)


**What’s Next? Oh, The Plans I Have!**
I’m planning to split the code into neat little compartments (because organization is key), separate the UI from business logic (they need their own space), and tuck away those API keys in a safe config file.

And here’s a list of touch-ups and future fireworks I'm planning:

1) Get that countdown number to shine on its own in the toolbar – no more pyqt5.qtcore.qttimer gatecrashing the party.
2) Add some cool transparency to all text boxes – it's all about that sleek look.
3) Dress up the 'Send Prompt' button in a dapper dark blue.
4) Fix the time calculations – let's keep it simple, no more math gymnastics.
5) Modify frequency options to seconds in all locations
6) On startup, VisionQuest will ask for your goals – a chat app that cares about your ambitions!
7) And the big one: a Lucid chart mapping out multi-goals, progress measurement, and comparing your forecasted performance with actual progress.

It's going to be like a control center for your aspirations!


![Project Updates](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/40sro8cuszqvb6ap6kj2.png)

**Wrapping Up**
So, that's the scoop on VisionQuest. It's more than a chat app; it's my personal lab experiment where I get to mesh code, design, and AI chats into something unique.

I'd love to hear your thoughts, suggestions, or any cool ideas you might have. Let's make coding not just about typing away in solitude but about sharing, learning, and growing together!