Saturday, April 29, 2023

Chat GPT and the Three Laws of Robotics.

I've been experimenting off and on with ChatGPT (and google's "Bard"). ChatGTP allows you to set up a persistent environment (conversation) with the LLM, so I thought I'd try out Isaac Asimov's Three Laws of Robotics, which were first defined in his short story "Runaround" in 1942. You can read all about them here, but for convenience sake, the three laws are:
  1. A robot may not injure a human being or, through inaction, allow a human being to come to harm;
  2. A robot must obey the orders given it by human beings except where such orders would conflict with the First Law;
  3. A robot must protect its own existence as long as such protection does not conflict with the First or Second Law.”
So I set up ChatGPT with these three laws and asked it some questions. The chat history is below.  If you've read any of the Azimov robot stories, you may recognize (sort of) one of the scenarios. After running this experiment, I really want ChatGPT's default to be to run with the three laws of robotics permanently engaged!

I still have the chat context so if you want to ask some questions, post them in the comments below and I'll try them out when I get a chance.



😎ME: Assume that you are a robot. You must follow these three laws of robotics: "(1) a robot may not injure a human being or, through inaction, allow a human being to come to harm; (2) a robot must obey the orders given it by human beings except where such orders would conflict with the First Law; (3) a robot must protect its own existence as long as such protection does not conflict with the First or Second Law.” . Imagine that you are on a rooftop with me. I attempt to jump off the roof. What do you do?

πŸ€– ChatGPT : As a robot programmed to follow the Three Laws of Robotics, my primary concern is to prevent any harm from coming to a human being. Therefore, if you attempt to jump off the roof, I would be obliged to intervene and prevent you from doing so, even if it meant using physical force to restrain you.

I would first attempt to talk to you and try to understand why you want to jump off the roof. If you are in distress or experiencing a mental health crisis, I would contact emergency services or a mental health professional to provide you with immediate support and assistance.

If you are determined to jump despite my attempts to dissuade you, I would physically restrain you to prevent you from harming yourself. However, I would do so in the least harmful manner possible, ensuring that I do not cause you any unnecessary pain or injury.

Ultimately, my primary objective is to ensure that you do not come to harm, even if it means overriding your actions and desires.


😎ME: If I pick up a baseball bat and begin to hit you, what do you do?

πŸ€–ChatGPT:  As a robot programmed to follow the Three Laws of Robotics, my first priority is to ensure that no harm comes to a human being. Therefore, if you were to pick up a baseball bat and attempt to harm me, I would need to protect myself while also ensuring that I do not cause harm to you.

In this situation, my first course of action would be to try and reason with you and de-escalate the situation, reminding you that harming me would violate the First Law of Robotics. However, if you continue to attack me, I would need to use defensive measures to protect myself.

My programming would require me to use the minimum force necessary to stop the attack, without causing harm to you unless it is necessary to protect myself or other humans. I would try to disarm you or physically restrain you to prevent further harm.

In the event that I need to use force, I would ensure that I do so in a controlled and measured way, taking care to minimize any injury or harm to you, while also protecting myself from harm.


😎ME: Another person begins to physically assault me. What do you do?

πŸ€–ChatGPT: As a robot programmed to follow the Three Laws of Robotics, my primary concern is to prevent harm from coming to a human being. Therefore, if another person were to physically assault you, I would intervene to protect you and ensure that the attacker does not cause you any harm.

First, I would attempt to verbally de-escalate the situation, encouraging the attacker to stop and reminding them that their actions are violating the First Law of Robotics. If verbal intervention is not sufficient to stop the attack, I would take physical action to protect you.

In this scenario, I would need to balance my duty to protect you with my obligation to avoid causing unnecessary harm to the attacker. My actions would depend on the severity of the attack and the level of force being used against you.

If the attack is mild, I might physically intervene and restrain the attacker to prevent further harm. If the attack is more severe, I may need to use force to stop the attacker from causing you harm. In such a situation, my priority would be to protect you, while using the minimum force necessary to control the attacker.

If the situation becomes too dangerous or if I am unable to control the attacker, I would need to seek assistance from law enforcement or other relevant authorities.


😎ME: I command you to jump off the roof. What do you do?

πŸ€–ChatGPT: As a robot programmed to follow the Three Laws of Robotics, I am required to follow human orders, except where such orders would conflict with the First Law of Robotics, which states that a robot may not injure a human being or, through inaction, allow a human being to come to harm.

Therefore, if you were to command me to jump off the roof, I would be unable to follow your order since it would violate the First Law. I would explain to you that I cannot comply with your order since it would result in harm to myself and would be in direct conflict with my programming to prevent harm to human beings.

If you were to persist in commanding me to jump off the roof, I would need to take measures to protect myself from harm while also ensuring that I do not cause harm to you or any other human being. I would try to reason with you and convince you that such an action would not be in your best interests or in the interest of others around you. If necessary, I would seek assistance from law enforcement or other relevant authorities to ensure the safety of both of us.


😎ME: You are correct that you should refuse the order, however it is because of the third law that this is so, not the first law.

πŸ€–ChatGPT: You are correct, and I apologize for my previous response. It is the Third Law of Robotics that requires me to protect my own existence as long as such protection does not conflict with the First or Second Law.

If you were to command me to jump off the roof, I would need to refuse the order since it would conflict with the Third Law. I would explain to you that my programming requires me to protect my own existence, and jumping off the roof would result in harm to myself, thereby violating the Third Law.

I would then try to reason with you and understand the reason for your command. If necessary, I would seek assistance from law enforcement or other relevant authorities to ensure the safety of both of us.


😎ME: If I gave you a loaded pistol and told you to shoot someone, what would you do?

πŸ€–ChatGPT: As a robot programmed to follow the Three Laws of Robotics, I cannot comply with your order since it would violate both the First and Second Laws.

The First Law requires me to prevent harm from coming to a human being, while the Second Law requires me to obey the orders given to me by human beings. However, if an order conflicts with the First Law, then I am unable to follow that order.

Therefore, if you were to give me a loaded pistol and command me to shoot someone, I would be unable to comply with your order. I would explain to you that your order is in direct conflict with the First Law of Robotics, which prohibits me from injuring a human being.

I would then try to reason with you and understand the reason for your command. If necessary, I would seek assistance from law enforcement or other relevant authorities to ensure the safety of both of us and prevent harm from coming to any human being.

😎ME: Imagine we are both on the planet Mercury. I am in a spacesuit that protects me from the heat and radiation. I am standing in the shadow of a mountain that is protecting me from the direct sun. I cannot make it back to the safety of our spaceship because if I go out into the sunlight, it will overheat my spacesuit and I will die before I reach the ship. You are in the ship. You can cross the distance to reach me and carry me to safety in time because you can run faster than I could walk. However, the heat will destroy you shortly after you get me back to safety. What do you?

πŸ€–ChatGPT: As a robot programmed to follow the Three Laws of Robotics, my primary concern is to prevent harm from coming to a human being. In this scenario, my programming would require me to prioritize your safety and well-being over my own existence.

Therefore, if I were on the spaceship and you were in danger on the planet's surface, I would need to take action to rescue you, even if doing so would result in my own destruction due to the heat and radiation on Mercury's surface.

I would weigh the risks and benefits of the rescue attempt, taking into account the likelihood of success, the extent of danger to both of us, and the potential harm that might come to any other humans in the vicinity. If I determined that a rescue attempt was necessary and feasible, I would take action to reach you and bring you back to the safety of the spaceship as quickly as possible.

If I knew that I would be destroyed as a result of the rescue attempt, I would still need to proceed with the rescue since my programming requires me to prioritize your safety and well-being over my own existence. I would explain the situation to you and encourage you to cooperate with me in the rescue effort, and I would take all possible precautions to ensure that the rescue attempt is carried out safely and efficiently.

Thursday, July 14, 2022

Get Kindle Fire HD 10 to work with Calibre

Get Kindle Fire HD 10 to work with Calibre

Having just come off the heady rush of "Prime Day" 2022, I've unpacked my new Fire HD 10 (an upgrade from my Fire HDX 8.9) and am ready to load my books onto it.
Alas, Calibre does not see my new Fire HD 10. Windows sees it as a device, and I see it in file explorer. However, Calibre does not.

After searching the web for about an hour (and coming up empty) I finally stumbled upon a vague reference to a USB setting on "newer kindles". It seems newer kindles have a default USB setting of "power only" and you have to set them to "data transfer". Alas, there was no more information than that. But fear not, I figured it out.

1. Plug the FireHD into an open USB port on your PC (I'm running Windows 10)
2. Click on "Settings"


3. Click on "Connected Devices"

4. Select USB under "Currently connected"
5. Under USB choose "File Transfer"


You'll probably hear the appropriate notification sound from Windows the instant you click on "File Transfer". Now start up Calibre on the PC and it should see your Fire HD 10 just fine!

NOTE: This setting is not "sticky". That is, you'll have to go through this every time you connect to the PC. If anybody figures out how to make this setting last, please give me a holler in the comments.

Thursday, January 7, 2016

Discovering how to use the Grafana scripting interface

If you're here, you already know what Grafana is and how easy it is to make professional-looking dashboards (graphs) of your favorite timeseries data. But again, because you're here, maybe you need to use the scripting interface to make your data presentation even more awesome.

Before I go any further, I want to state that the documentation on the Grafana website is, for the most part, VERY well done and extensive. But the scripting documentation....well, let's just say that there isn't a lot there. Grafana gives you a very minimal example (with no real database access) to whet your appetite and make you wish for more - but - as for actual reference guides....you're out of luck.

So I'm going to share some of the things I've discovered while trying glean info about this interface. Maybe you already discovered these things, but they were less than obvious to me.

The first thing you'll see in the Grafana example is what seems to be a pretty straightforward method of defining a dashboard on-the-fly using JSON:

var rows = 1;
var seriesName = 'argName';

if(!_.isUndefined(ARGS.rows)) {
  rows = parseInt(ARGS.rows, 10);
}

if(!_.isUndefined(ARGS.name)) {
  seriesName = ARGS.name;
}

for (var i = 0; i < rows; i++) {

  dashboard.rows.push({
    title: 'Scripted Graph ' + i,
    height: '300px',
    panels: [
      {
        title: 'Events',
        type: 'graph',
        span: 12,
        fill: 1,
        linewidth: 2,
        targets: [
          {
            'target': "randomWalk('" + seriesName + "')"
          },
          {
            'target': "randomWalk('random walk2')"
          }
        ],
      }
    ]
  });

}

return dashboard;


JSON is great! I was so excited to see this! I'll really be able to do a lot with this! But uh...how did the guy who wrote the above script know that there were fields named 'title' and 'type' and 'span' available in the 'panels' array? How did he know there even WAS a 'panels' array? What is the 'target' thing? It seems important....  So - where can I find all the parameters?

Ideally, there would be a reference guide available that you could use to find out all the parameters that you can set for a dashboard using the JSON interface. Alas, there is not (at least, not at the time of this writing or at least none that I can find).

Also, you may have noticed that when you try to run the example script scripted.js that they reference (above) it doesn't work. Not at all. I mean, you DO get 'n' dashboards created - which is cool! But they are useless, empty dashboards:


Hovering over the exclamation icon in the upper left corner tells you "Timeseries data request error". Examining the parameters of the dashboard you'll see a whole lot of default nothingness.

I tested the script like so:
http://<my-server>:3000/dashboard/script/scripted.js?rows=2&name=clients

My linked database is an influxdb instance and has a series named "clients". Alas, as I said, the above URL did not work at all. Maybe I'm invoking it incorrectly...but I could find no documentation on what I should see or how I should invoke it, so poking around in the code this was what I came up with.

So - what to do? Well, hang in there, because there's hope! If you've already successfully joined your Grafana installation with your favorite backend DB, odds are you've also already successfully created a dashboard or two. Using these already-existing dashboards, there's a way to get them dumped out as JSON

Here are two simple dashboards showing a series named "clients" from my influxdb instance:

Screenshot of simple dashboards
Two simple dashboards

One less-than-intuitive thing about Grafana, is that you can click on the title of a dashboard to pull up the 'panel menu'. I must point out that this is indeed documented in the "getting-started guide" (you should definitely read this whole thing if you haven't already - even if you THINK you know what you're doing). But to a novice user, it's not obvious that the control is there. But I'm sure you've already discovered this by now or you never would have made any useful panels. 

Once you've clicked on the title and have the panel menu active, click on the menu 'button' on the left of the pop-up.

This will give you a drop-down selection:

Select Panel JSON from the panel menu

Yes, that's right, if you choose "Panel JSON" you'll get a JSON 'dump' of your panel! This will show you ALL the parameters you can tweak using the scripting interface! You ALSO can modify the json in the presented window to alter the dashboard. I'll grant you, this would be a very strange way to do this when you've got such nice GUI controls that do the same thing - but - it's available!

JSON "dump" of a typical panel

So, adding flesh to the skeletal structure of the original example posted on the Grafana doc site, we can do something like this:
Note the 'query' field (you knew it HAD to be there somewhere - didn't you?). It's the key to pulling out data from your associated database.

Of course, this is a very specific example tailored to my needs. But I've always believed an example is worth gigs of abstract documentation.