Search This Blog

Wednesday, January 29, 2025

AI: Prompt Engineering

The other day I got an advertising on social media about a free certificate in responsible AI use and Prompt Engineering. The course was a collaboration between Microsoft and Founderz who hosted AI Skills 4 All which was educational and interesting.

As a regular user of both Copilot and Edge I decided to give it a go, it was free and took less than 8 hours, so I thought why not?

Basically they brought up the basics of how generative AI work, how to write good prompts and how they leverage the Edge browser. 

The way we should see Copilot is not as the primary agent of choice, but rather our second pilot, that can offload us from certain tasks. We are still responsible for what we do with the tool in that sense. At this stage these generative AI:s, especially Copilot, is better at texts and images than math.

Its strengths are brainstorming, handling large amount of information and creating general ideas for the low risk scenarios. The general downsides of Copilot is that it does not think or feel, it is not always accurate and you can't rely on it as a friend. It also comes with biases of its own.

Improve your prompts

Writing good prompts for AI consists of four main parts.

1. A goal, such as creating a bunch of bullet points detailing the last quarter

2. Context, such as defining a setting where the material will be used, for example a breakfast presentation. You could also specify what type of people that will attend. For example whether it is marketers, competitors or managers.

3. Source of the information, make sure to ask Copilot where to get the data from. This is important because not only is it your job to ensure the quality of the result, but you might know that some sources are better in certain fields. You will notice that the sources are linked in the result as well, if you want to continue your research.

4. Expectations, define what you want out of the material, what sort of result should it create?

Customizing your prompts further

There are additional things that you need to think about in order to create better prompts, such as being rich with details. Remember to add the most important things first, it is valued higher, this is especially true when creating images.

Here is an example of the prompt "Create an image of the planet Mars"


This is the result of the prompt "Now create an image of the planet Mars, from the surface of the planet, where you can an early human settlement, do not include any people. The sky should be daytime."



You can also ask the AI to ask you controlling questions back to you before presenting the result. This increased content quality. You could ask Copilot to return five questions about the material as an example.

To shape the content further, ask the chatbot to take on certain personas. You could for instance ask it to act as an PR-expert to create a certain effect with the text.

Keep in mind that if you are logged in, you can save a history of previous chats. You can also attempt to regenerate the reply, by simply asking it to do so, you might then get a variation of the reply.

What to avoid

There are a few things to avoid when you work with the Copilot, these pointers will also help you make better decisions when taking the help from AI. 

1. Avoid math that you cannot check yourself afterwards, this is due to the probabilistic nature of the generative AI. It uses mathematical models to predict what the next "token" in a sentence is, such as a word or another small piece of data. You can in worst case get different results from the same question. Instead try to focus on outputting text and code for example.

2. Don't be too sparse with the details, it will negatively impact your results.

3. Don't upload information, data, images and so on that might be sensitive or personal.

Troubleshooting the output

If an error occurs you can try to figure out what could have been causing the mishap.

For this it is also important to know how Copilot works. First it searches, then a Large Language Model is used to summarize the content and then it is filtered and presented. 

You can ask yourself these questions when troubleshooting the result:

  • Is there an issue with how the question was asked?
  • Are there problems with the sources used? Can other sources be used instead?
  • Was there something wrong at the search stage?
  • Was there an issue with the summarizing stage?
  • Did something happen when it was presented?

Different ways to use Copilot

One thing that I myself learned from the course was an efficient way to use Copilot in the sidebar together with Microsoft Office in the browser. This is handy as Copilot is not necessarily integrated into the Office programs that you install on your PC, at the time of this blogpost.

Use the sidebar AI in Microsoft Edge to analyse, summarize, correct or improve Word documents that you have open in the browser, when you are working in Office online. You can of course use it on other sites too and let it assist you in evaluating and working with different content. Another hack I like to use is to take a snippet and upload it, and ask questions about the content.

There is also a speech function and if you use it, you will notice that it speaks back to you.

For mobile they have a dedicated app for Copilot as well, it pretty much fills the same role there, a plus for using the app is that you can use the camera to identify objects for example or transcribe text that you take a photo of.

Summary

Let's wrap this post up by saying that Copilot has helped me a lot, both professionally and in private. Personally I use it as an advanced search engine sometimes, with whom I can discuss the results and ask clarifying questions. I also use it to generate PowerShell code these days, but I try to understand the concept before I ask it to produce the code, this is so that I can evaluate the result better. It is a philosophy of mine that it is better to have done something the hard way (or at least have tried) first, because it gives a better intuitions of the subject.

The course raised my awareness of the probabilistic side of the AI, which explains the interesting results that one sometimes gets. Remember to use the up and down thumb to continue to train the AI, so that it becomes better.

Enjoy!

Saturday, January 11, 2025

Hardware: Building a gaming computer


Background

Just like the jedi knights of Star Wars needs to build their own lightsaber, we techies should build our own computer to get a greater understanding for the tech we use and because it is an interesting project and a test of our ability.

This is the second proper gaming desktop that I have, the first was a prebuild that lasted me for 10 years (with some repairs included), but this was before my career in IT. Now I wanted to take on the challenge of building my own gaming computer. As a sidenote the primary games I wanted to play with this new computer were Enlisted, Minecraft, World of Warcraft and Skyrim. Later on I also want to try GTA 5 and League of Legends.

Building was the quick part, while budgeting and planning was the slower part of the adventure. This will be a post about my observations and what I learned. 

Preparations

The decision to build a computer started roughly a year ago, or a bit more. I postponed it for two reasons, I needed to save up some money and I wanted to wait for prices to go down. Furthermore I was also not sure about the parts or even the process itself. So I started by putting together many various setups using the online tool at Inet where I would play around, see what the best parts would give me or how expensive some setups could be. Some setups would be around 2500 euros, which is a lot. So a part of the problem was knowing how much to scale down the computer in performance to lower the costs. It took quite a few sample builds before I realized what would be "good enough".

So my lesson for you is that you can save a lot of money on your build by adapting it for the realistic use case. Maxing everything out is probably fun and definitely expensive. It would future proof your build as well. Which is something you want to keep in mind. You could for example focus on getting parts that are modern, but not necessarily the best performers, to allow for reasonable upgrades in the future.  

So when it was finally time to pick out the parts I would use for my real build what I focused on was getting enough performance for my games and getting relatively modern pieces, this allowed me to cut the costs down to 1200 euro. I can still upgrade RAM, processor and add more storage for example.

These are the parts I ordered for my build, two of the small fans were never used.

  • Chassi: Chieftec Pro Mini Svart
  • Processor: AMD Ryzen 7 8700F 4.1 GHz 24MB
  • Graphics card: ASRock Radeon RX 6600 8GB Challenger
  • Motherboard: ASUS Prime B650M-R
  • RAM: Kingston 32GB (2x16GB) DDR5 5200MHz CL36 FURY Beast AMD EXPO/Intel XMP 3.0
  • Storage: Kingston KC3000 M.2 NVMe SSD Gen 4 512GB
  • Big fans: Phanteks M25 140mm PWM Svart
  • Small fans: Arctic P12 PWM Svart PST Svart
  • CPU-cooler: Cooler Master Hyper 212 Black Edition
  • Power supply: Chieftec Proton 750W

I chose 32 GB ram to give me ample of headroom, while allowing me to upgrade to 96 GB in the future. The NVMe on 512 GB allows me to quickly boot up the computer, store all of my games at the same time while still leaving me a bit of room. I have a whole slot that I can install a much larger storage into later as well. The CPU felt quite modern and it didn't come with integrated graphics, which means I am 100% reliant on the graphics card. 

Another part of the preparations was to create a bootable USB-drive with Windows 11 Pro, so that I instantly could install it once the computer was ready.

Building the computer

Seeing as this was the first build I had no complete desktop building experience to draw upon. Instead I had a bit of laptop maintenance experience and knowledge from general tinkering and exploring. 

The first step was to gather all the boxes with components and look it over, bringing a general screwdriver and a knife for opening the boxes. The general principle is to complete your motherboard first, before putting it into the chassis. 

So after unboxing what had to be unboxed right away, I put the CPU, RAM and SSD in place. The RAM was the easiest, just make sure to put it facing the right direction and that it fits the slot. The SSD is also quite easy once you know how to keep it in place, in this case I used a locking mechanism made from some type of plastic. The CPU was a bit interesting, make sure to align the corners properly and drop it in straight from above. Then you use the clasp to hold it in place, at this point a plastic cover flew off which I wasn't prepared for. Scary!

Once the CPU was equipped, I first used a default CPU cooler, it already had thermal paste on. But later when I had research the non-stock cooler I equipped it using thermal paste that comes with the cooler in a tube. The CPU cooler was relatively easy to install, the trick is to lower it down on top of the CPU in an even fashion to not create too much bubbles in the thermal paste. Remember to remove the plastic sticker covering the area that connects to the CPU. Fasten the screws a bit at a time, once again making sure to spread the pressure evenly until it sits properly against the CPU.

Next step was to prepare the chassis, I installed the backplate for the motherboard. The secret to installing this backplate is to push it out evenly from the inside, just make sure to align the holes correctly. The role of the backplate is to protect the computer, it can help with both heat and to some degree interference, it also offers extra stability.

Continuing on the journey I now installed the front fans. This was very tricky because it was a challenge to get the front cover off. If I could have traveled back in time, I would perhaps have installed it earlier. I also installed the chassis to the motherboard, along with the power supply. At times it was a bit tricky to see which component that needed which cable, and in some case it was difficult to connect them to the motherboard. Here I also could have done a better cable management job, by running some of the cables behind the motherboard (there is a space there). My advice is that if you are working in a dark chassis, bring plenty of light, a lamp on the forehead would have helped a lot.

Lastly I put in the graphics card, I noted that it looks like it sits upside down in this build and on the backside you only need to remove the sliders that makes room for the card's interface. The graphics card was relatively easy to install, in part thanks to a combination of a good enough chassis and that the PCIe-slot didn't cause any issues. The graphics card needs electricity too, so I connected the power to it from the power supply.

Finally I installed some additional fans (and it was after this that I installed the non-stock CPU cooler).

Setup, first time use and finishing touches

I must admit that the first time I started the computer, I stretched my arm out to the power button, just in case it would explode. But fortunately, it worked on the first go. However, I did not connect it to my main setup at this stage, I had a small touch screen connected just to get through the Windows 11 setup and then of course the USB drive with the operative system.

After making sure it was correctly setup and working, I brought it to my desk and connected it to the ethernet cable and monitor, along with peripherals. 

First thing to do was running Windows Update, downloading specific drivers and update the firmware.

When everything was set and done it was time to download games and start enjoying the product, and what a relief it was to finally be able to play the favorite games again on full graphics. As the games were installed on the desktop I could also remove the from my Framework 13, who had been struggling even at the lowest graphics. 

Sunday, January 5, 2025

Flipper Zero: Ducky scripts

Yesterday I received my Flipper Zero and after a long wait I was ready to tinker away with it.

After capturing some infrared signals and replicating them, it was time to test the legendary Bad USB functionality.

The content of this post is based on the GitHub page.

The BadUsb app on the Flipper Zero uses extended Ducky script syntax which is compatible with the classic USB Rubber Ducky 1.0 language but with extra components such as custom USB ID (how the keyboard is identified), ALT-codes (pressing ALT and numbers on the numpad) and the old SYSRQ command. Both \n and \r\n line endings are supported, empty lines are allowed and you can use spaces or tabs for line indentation.

The script is written in simple .txt files and can be copied over to the Flipper Zero using the Windows app for example, and it must be located in the correct Bad USB folder.

To use the Bad USB function, make sure to have a USB-C to USB-A cable that you connect between the Flipper and the computer that you want to run your script on.

Navigate to "Bad USB" in the main menu, select the script that you want to execute and then press run.
Almost instantly it will execute the keypresses that you preprogrammed.

Here is a simple example that helps you start a PowerShell window with administrative privileges.

GUI r
DELAY 500
STRING powershell
CTRL-SHIFT ENTER
DELAY 500
ALT Y
DELAY 500
STRING write-host "This script is running as admin"
ENTER

Spoof keyboard ID

You can set the custom ID of the Flipper USB HID device. ID command should be in the **first line** of script, it is executed before script run. VID and PID are hex codes and are mandatory. Manufacturer and Product are text strings and are optional.

ID, VID:PID Manufacturer:Product        

Example: "ID 1234:abcd Flipper Devices:Flipper Zero".

Delay, comments, holding down

DELAY, one delay value in ms

DEFAULT_DELAY, delay value in ms before every next command

DEFAULTDELAY, alternative to DEFAULT_DELAY

REM, commenting is done by writing REM followed by a single line of text

HOLD, press and hold key until RELEASE command. Up to 5 keys can be held at the same time.

RELEASE, release key

Arrow keys

DOWNARROW / DOWN

LEFTARROW / LEFT

RIGHTARROW / RIGHT

UPARROW / UP

Various buttons

APP, same as MENU, context menu key (right-clicking)

BACKSPACE

BREAK

CAPSLOCK

DELETE

END

ENTER

ESCAPE / ESC

Fx, F1-F12 keys

HOME

INSERT

MENU, same as APP, context menu key (right-clicking)

NUMLOCK

PAGEDOWN

PAGEUP

PAUSE

PRINTSCREEN

SCROLLLOCK

SPACE

TAB

You can combine the following with a special key command or a single character.

CONTROL / CTRL

SHIFT

ALT

WINDOWS / GUI, the Windows key

CTRL-ALT, ctrl plus alt

CTRL-SHIFT, ctrl plus shift

ALT-SHIFT, alt plus shift

ALT-GUI, alt plus the Windows key

GUI-SHIFT, the Windows key plus shift

GUI-CTRL, the Windows key plus ctrl

Strings and delay between keypresses

STRING, print text string, such as writing something in a terminal

STRINGLN, print text string and press enter after it

STRING_DELAY, delay value in ms which is applied once to next appearing STRING command

STRINGDELAY, an alternative to STRING_DELAY  

DEFAULT_STRING_DELAY, delay value in ms, applied to every appearing STRING command

DEFAULTSTRINGDELAY, alternative to DEFAULT_STRING_DELAY

REPEAT   Number of additional repeats  Repeat previous command

WAIT_FOR_BUTTON_PRESS, will wait for the user to press a button to continue script execution. Will wait indefinitely for a button to be pressed.

On Windows and some Linux systems, you can print characters by holding ALT key and entering its code on Numpad.

ALTCHAR, print single character

ALTSTRING, print text string using ALT+Numpad method

ALTCODE, same as ALTSTRING, presents in some Duckyscript implementations

Send SysRq command, which is a way to interact with the computer even in a frozen state.

SYSRQ, single character

Media keys

Some Media/Consumer Control keys can be pressed with "MEDIA" command

MEDIA, used with commands in the list below:

POWER

REBOOT

SLEEP

LOGOFF

EXIT

BRIGHT_UP, brightness up

BRIGHT_DOWN, brightness down

HOME

BACK

FORWARD

REFRESH

SNAPSHOT, take photo in a camera app

PLAY

PAUSE

PLAY_PAUSE

NEXT_TRACK

PREV_TRACK

STOP

EJECT

MUTE

VOLUME_UP

VOLUME_DOWN

FN, Fn/Globe key on Mac keyboard

GLOBE, special key or single character (Fn/Globe key commands for Mac/iPad)