Are You Nuts? Know your Fishing Knots! – Alberto Knot

https://www.alloutdoor.com/wp-content/uploads/2022/11/20221117_203049-e1668736058426.jpg

This week I’m covering another line-to-line connection knot, the Alberto Knot. This knot was invented by “Crazy Alberto” Alberto Knie for the specific purpose of connecting braided lines to monofilament lines. Being an avid surf fisherman from the east coast, often fishing in windy conditions Alberto wanted a strong knot that you can easily tie in the wind. The Alberto knot is similar to the Albright Knot from last week in which it also is tied to a doubled leader line. They also share the trait of being able to run through guides easily. For demonstration purposes, the black paracord is a stand-in for the thicker monofilament leader and the pink braid is a stand-in for your braided mainline.

Editor’s Note: I’m a novice at knot tying and enjoyed this step-by-step writeup from Eugene. I have also found the Animated Knots website to be helpful in the past.

Alberto Knot – Step 1

Start off with your main braided line and your thicker monofilament leader line, and then double up your monofilament leader line into a loop.

Are You Nuts? Know your Fishing Knots! – Alberto Knot

Step 2

The braided line is then run through the loop of the thicker leader line. You want to run about 10″ of the braided line through that loop.

Are You Nuts? Know your Fishing Knots! – Alberto Knot

Step 3

Holding the loop of the leader line with your left hand, start wrapping the braided line around the doubled leader line. You want to make 7 even wraps around the doubled loop of line.

Are You Nuts? Know your Fishing Knots! – Alberto Knot

Step 4

Once you finish the first seven wraps up the loop, you’re going to make seven more wraps back down the loop. Make sure the wraps are going right over the previous loops. Then run the tag end of the braided line back through the loop of your leader.

Are You Nuts? Know your Fishing Knots! – Alberto Knot

Step 5

Once the tag end is back in the original loop, evenly start pulling the Alberto Knot to tighten up the wraps. Once the wraps are all tight you can then cut off the tag ends and your Alberto Knot is ready to be fished.

Are You Nuts? Know your Fishing Knots! – Alberto Knot

The post Are You Nuts? Know your Fishing Knots! – Alberto Knot appeared first on AllOutdoor.com.

AllOutdoor.com

Hidden #Laravel Tip – The Fluent Class

http://img.youtube.com/vi/8PqgRoCe0N0/0.jpgHere, we will be looking at one of the hidden Laravel features that you might not know about. It is Fluent class. The best way to access array related data.Laravel News Links

The Best Air Fryer Toaster Oven

https://cdn.thewirecutter.com/wp-content/media/2022/11/airfryertoasterovens-2048px-1826-3×2-1.jpg?auto=webp&quality=60&width=630&dpr=2

The Best Air Fryer Toaster Oven

Air frying has come full circle. When we started testing pod-shaped air fryers in 2017, we concluded that they were too cramped and not versatile. We’ve since come around, but we still think convection toaster ovens (which use the same technology) can cook a wider variety of foods more evenly, if a little slower. Now, more and more companies are bridging the gap by making amped-up convection toaster ovens—sold as “air fryer toaster ovens”—with extra-powerful fans that produce crispy results in shorter times. After testing dozens of models, we think the Breville Smart Oven Air Fryer Pro is the only one that’s both an excellent air fryer and an excellent toaster oven—but it’s pricey.

Dismiss

Wirecutter: Reviews for the Real World

10 Commandments of Concealed Carry

https://cdn.athlonoutdoors.com/wp-content/uploads/sites/8/2008/10/10-Commandments-of-Concealed-Carry-2.jpg

Carrying a lethal weapon in public confers a grave power that carries with it great responsibilities. Those who lawfully engage in the practice realize that. Those who are considering concealed carry need to know what those experienced people know.

1 – If You Carry Concealed, Always Carry

The criminal is the actor, and the armed citizen is the reactor. The typical violent criminal arms himself only when he intends to do something with it. He picks the time and place of the assault, and initiates the attack. Therefore, he doesn’t need to worry about self-defense.

The armed citizen, the intended victim, does not know when or where that attack will come. Therefore, he or she must be constantly prepared and constantly vigilant. The “pistol-packer” learns to pick a comfortable holster and an appropriately sized handgun, and “dress around the firearm.” After a few days, or a few weeks, it becomes second nature to wear it.

When the defender does not know when the attack will come, the only reasonable expectation of safety lies in being always armed.

2 – Don’t Carry Concealed If You Aren’t Prepared To Use It

There is a great irony that attaches to the defensive firearm. When you analyze a great many defensive gun usages (DGUs) you discover that the great majority of the time, the protection weapon does its job with no blood being shed. Usually, the offender who is confronted with the prospect of being shot in self-defense either breaks off and runs or surrenders at gunpoint.

“The person who is prepared to kill if he or she must, is the person who is least likely to have to do so…”

Its most important asset turns out to be its power to deter. The irony is the fact that its power to deter comes directly from its power to kill.

Understand that criminals do not fear guns. They are, after all, an armed subculture themselves. What they fear is the resolutely armed man or woman who points that gun at them. Criminals are predators, and their stock in trade is their ability to read people and recognize victims. They are very, very good at reading “body language” and determining another’s intent to fight, or lack thereof. In short, you’re not likely to bluff them.

The Message You Send

If you carry a gun, you must be absolutely certain that you can use deadly force. The person who is hesitant or unwilling to do so will, in the moment of truth, communicate that vacillation to the hardened criminal they are attempting to hold at gunpoint. In such a case, it is quite likely that the offender will jump them, disarm them, and use the hesitant defenders’ own weapons against them.

If, however, that same criminal realizes that he is facing a resolute person who will, in fact, shoot him if he takes one more transgressive step, he is most unlikely to take that step.

The irony: The person who is prepared to kill if he or she must, is the person who is least likely to have to do so.

3 – Don’t Let The Gun Make You Reckless

Circa 1970, armed citizen Richard Davis invented the Second Chance vest, concealable body armor that for the first time could be worn constantly on duty, under the uniform, by any police officer. Some alarmists speculated that “being made bulletproof” would cause cops to become reckless. Those fears turned out to be totally unfounded. As any officer who has worn armor can attest, the vest is a constant reminder of danger and, if anything, makes its wearer more cautious.

“Like an officer’s body armor, the armed citizen’s gun is a reminder of danger, a symbol of the need for caution…”

It is much the same with concealed firearms in the hands of responsible private citizens. People unfamiliar with the practice fear that “the trigger will pull the finger,” of the carrier. As a result, armed citizens will go looking for a chance to exercise their deadly power. This, too, is a largely unfounded belief.

A Symbol of the Need for Caution

The collective experience of ordinary, law-abiding people who carry guns is that they don’t feel a sudden urge to go into Central Park at three o’clock in the morning and troll for muggers. They learn that being armed, they are held to “a higher standard of care,” in the eyes of the law. And are expected to avoid situations like traffic arguments. This is because they could escalate and, with a deadly weapon present, turn into killing situations.

Like an officer’s body armor, the armed citizen’s gun is a reminder of danger. A symbol of the need for caution. The late, great big game hunter and gun writer Finn Aagard once wrote, “Yet my pistol is more than just security. Like an Orthodox Jewish yarmulke or a Christian cross, it is a symbol of who I am, what I believe, and the moral standards by which I live.”

4 – Get The License!

You’ll hear some absolutists say, “No government has the right to permit me to carry a gun! I don’t need no stinking permit! The Second Amendment is my license to carry!”

“If you carry, make sure you carry legally…”

That is the sound of someone asking to go to jail. Like it or not, the laws of the land require, in 46 of the 50 states, a license to carry concealed. In two states, there is no legal provision for the ordinary citizen to carry at all. Realize that things are not as we wish they were; things are as they are. If things were as we wish they would be, we wouldn’t need to carry guns at all.

If you are diligent about studying carry license reciprocity, and about seeking non-resident concealed carry permits in states that don’t have reciprocity, you can become legal to carry in some forty or more states. It can get expensive, and it can get tiresome. However, allowing yourself to be made into a felon and being ramrodded through the courts is much more expensive. Not to mention far more tiresome.

Bottom line: if you carry, make sure you carry legally.

Know what to do with your carry gun. Above, the live-fire portion of an LFI-I class is in progress in Wisconsin.
Know what to do with your carry gun. Above, the live-fire portion of an LFI-I class is in progress in Wisconsin.

5 – Know What You’re Doing

You wouldn’t drive an automobile without knowing the rules of the road. Do not keep or carry lethal weapons for defense without knowing the rules of engagement. It is a myth to believe that you can shoot anyone in your home. When Florida rescinded the requirement to retreat before using deadly force if attacked in public, the anti-gun Brady Center introduced a publicity campaign claiming that the new law allowed Floridians to shoot anyone who frightened them. This, of course, was blatantly untrue, but a great many people believed it to be so because “they heard it on TV” or “they saw it in the paper.” Such dangerous misconceptions can cause the tragic death of people who don’t deserve to be shot, and can get good people sent to prison.

“A person who opens fire with a gun they don’t know how to shoot is a danger to all…”

It is the practitioner’s responsibility to “learn the rules of the road” when they take the path toward armed self-defense. There are many firearms training schools. At least one, the author’s Lethal Force Institute, specializes in teaching the rules of engagement. Information is available under the LFI section at www.ayoob.com. It is wise to take local classes that emphasize the rules of “deadly force decision-making.”

Understand the ramifications of concealed carry. Psychologist Aprill explains the emotional aftermath of using deadly force at an LFI-I class in Florida.
Understand the ramifications of concealed carry. Psychologist Aprill explains the emotional aftermath of using deadly force at an LFI-I class in Florida.

A Trained Shooter is a Safe Shooter

Similarly, a person who opens fire with a gun they don’t know how to shoot is a danger to all. If you need the firearm for its intended purpose, you will be under extreme stress. Learn to shoot under pressure. Quick drawing from concealment, safe holstering, proper tactics, and much more are on the curriculum. Likewise, they require practice if you’re serious about defending yourself and your loved ones to the best of your ability.

6 – Concealed Carry Means Concealed

A very few people carrying guns for the first time feel an irresistible urge to let others see that “they’ve got the power.” First-time carriers and rookie cops, usually young in both cases, may fall into this trap. It is a practice to avoid for several reasons.

“A harasser who has picked you as his victim and knows you carry a gun can create a situation where there are no other witnesses present…It is his word against yours…”

In most of this society, the only people the general public sees carrying guns in public are uniformed “protector figures,” such as police officers and security guards. When they see someone not identifiable as such, who is carrying a lethal weapon, they tend to panic. This makes no friends among the voting public for the gun owners’ rights movement—you do not make people into friends and sympathizers, by frightening them—and can lead to a panicky observer getting the wrong idea and reporting you to the police as a “man with a gun.” This can lead to all sorts of unpleasant confrontations.

False Accusations

Moreover, a harasser who has picked you as his victim and knows you carry a gun can create a situation where there are no other witnesses present. He can then make the false claim that you threatened him with the weapon. This is a very serious felony called Aggravated Assault. It is his word against yours. The fact that you are indeed carrying the gun he describes you pointing at him can make his lie more believable than your truth, to the ears of judge and jury.

MCRGO On Open Carry

MCRGO, Michigan Coalition of Responsible Gun Owners, is directly responsible for getting reform concealed carry legislation enacted in their state. Likewise, it has been in the forefront of fighting for the rights of armed citizens in that state. MCRGO’s Steve Dulan, in the organization’s Weekly E’News of 6/23/08, had some cogent points to make on the topic of private citizens carrying handguns visibly in public:

“Open carry of firearms, subject to MCL 750.234d, it is legal to carry a visible pistol in public. MCRGO has not adopted an official position on this subject,” wrote Dulan, who continued, “I agree with Ted Nugent and many others that it is a bad idea in almost every situation. Tactically, you are giving up the element of surprise should you face a deadly force situation. Furthermore, you run the risk of being called in to 9-1-1 as a ‘man with a gun.’ I have been on police ride-alongs when this call comes over the radio. It creates a very dangerous situation for all concerned. I do not carry openly. I have a CPL (Concealed Pistol License) and take care to choose a gun and holster that, along with appropriate clothing, allow me to keep my gun concealed unless/until I need it to save a life.”

The Open Carry Emergency Option

As cogent and valid as Steve Dulan’s arguments are, it still makes sense to have legal open carry available as an emergency option. If the wind blows your coat open and reveals the gun, an open carry provision assures you’ve committed no crime. If someone who has not yet felt the need to get a concealed carry license suddenly begins getting death threats, open carry provides an emergency avenue of self-protection until the paperwork can be processed to acquire the license to carry the weapon discreetly out of sight.

7 – Maximize Your Firearms Familiarity

The more you work with the firearm, the more reflexively skilled you’ll become in its emergency use and safe handling. If your home defense shotgun is a Remington 870, then when you go claybird shooting or hunting, use an 870 pump gun with a barrel and choke appropriate for each task. However, if you are a target shooter who uses the 1911 pistol platform at bull’s-eye matches and have become deeply familiar with it, it makes sense to acquire a concealable 1911 to use as your concealed carry gun, so that the ingrained skill will directly transfer. Likewise, if a double-action .44 Magnum is your hunting revolver, and another double-action revolver is your home defense gun, it makes sense to choose a carry-size revolver as your concealment handgun when you’re out and about.

Consider training classes or competition shoots where your chosen defensive firearm is appropriate to the course of fire. This skill-building will translate to self-defense ability if you ever have to use your concealed carry gun for defense. If training ammunition is too expensive, consider a .22 conversion unit for your semiautomatic pistol. Or you can purchase a .22 caliber revolver the same size as your defensive .38 or .357. The more trigger time you have with a similar gun, the more confidence/competence you’ll have with your carry gun. Especially if you can’t afford to practice as much as you’d like with the carry gun itself.

It’s “asking for trouble” to “go where you’re not wanted.” Taking time to read the fine print on the door of this jewelry store in the usually gun-friendly NH…

8 – Understand The Fine Points

Every state has different laws insofar as where you can and can’t carry a gun. It’s your responsibility to know all the details. In one state, it may be against the law to carry a weapon in a posted “no-gun” zone. In another, that sign may have no weight of law at all behind it. However, in a third, they may ask you to leave if they spot your gun. If you do not depart, you will be subject to arrest for Trespass After Warning.

In New Hampshire, it’s perfectly legal to carry your gun into a bar and sit down to have a drink. If you do the same in Florida, it’s an arrestable offense. Although you may have a cocktail in a restaurant with a liquor license. However, you must sit in a part of the establishment that earns less than 50% of its income from selling alcoholic beverages by the drink. In North Carolina, you can’t even walk into a restaurant that has a liquor license, with a gun on. And, perhaps strangest of all, in the state of Virginia, it’s illegal to enter a tavern with a concealed handgun. But it’s perfectly legal to belly up to the bar and sip a whiskey while open carrying a loaded handgun.

You can find a superb current compendium of gun laws in the 50 states at www.handgunlaw.us. Review it frequently for possible changes.

9 – Carry An Adequate Firearm

If you carry a single-shot, .22 Short caliber derringer, law enforcement will consider you armed with a deadly weapon. However, you will not be adequately prepared to stop a predictable attack by multiple armed assailants. Most experts recommend a five-shot revolver as the absolute minimum in firepower. Likewise, the .380/9mm/.38SPL range is the minimum potency level in terms of handgun caliber.

“Once you’ve found a carry gun that works for your needs, it’s a good idea to acquire another that’s identical or at least very similar…”

It is a good idea to carry spare ammunition. Many people in their first gunfight have quickly found themselves soon clicking an empty gun. A firearm without spare ammunition is a temporary gun. Moreover, many malfunctions in semiautomatic pistols require a fresh (spare) magazine to rectify. Some fear that carrying spare ammo will make them look paranoid. They need to realize that those who don’t like guns and dislike the people who carry them, will consider carrying the gun without spare ammunition to still be paranoid. It’s an easy argument to win in court. Cops carry spare ammunition. So should you.

Carrying a Concealed Backup

Carrying a second gun has saved the lives of many good people. For example, when a criminal’s bullet hits the primary weapon, rendering it unshootable. Or when it is knocked out of the defender’s hand, or a criminal snatches it away. Also, when the first gun runs out of ammo and there is no time to reload. The list of reasons is endless. It suffices to remember the words of street-savvy Phil Engeldrum: “If you need to carry a gun, you probably need to carry two of them.”

At the very least, once you’ve found a carry gun that works for your needs, it’s a good idea to acquire another that’s identical or at least very similar. If you have to use the first gun for self-defense, it will go into evidence for some time. But you want something you can immediately put on to protect yourself from vengeful cronies of the criminal you had to shoot. If the primary gun has to go in for repair, you don’t want to be helpless or carrying something less satisfactory while you’re waiting to get it back.

10 – Use Common Sense

The gun carries with it the power of life and death. That power belongs only in the hands of responsible people who care about consequences. Likewise, those who are respectful of life and limb and human safety. Carrying a gun is a practice that is becoming increasingly common among ordinary American citizens. Common sense must always accompany it.

Didn’t find what you were looking for?

The post 10 Commandments of Concealed Carry appeared first on Tactical Life Gun Magazine: Gun News and Gun Reviews.

Tactical Life Gun Magazine: Gun News and Gun Reviews

Are You Nuts? Know your Fishing Knots! – Albright Knot

https://www.alloutdoor.com/wp-content/uploads/2022/11/20221110_164657-e1668117566693.jpg

Today I’m going to cover another line-to-line connection with the Albright knot. A relatively simple knot that is moderately easy to tie. The Albright knot is a versatile knot that can be used to connect monofilament to braided line or braid to wire. It is also very useful for connecting monofilament lines that have a big difference in their line diameters. I know this knot is often used by surf fisherman in the northeast for connecting a heavy monofilament or fluorocarbon leader to the braid as they’re plugging in the surf. The knot is pretty low-profile making it great at sliding in and out of the line guides as you cast or when a big fish pulls enough drag to get your line to the backing. You can even use some glue to smooth the knot down even further to have a snag free option.

Step 1

Get your two lines side by side, the black cord is acting as a thicker leader line.

Are You Nuts? Know your Fishing Knots! – Albright Knot

Step 2

Double back the leader line and make a loop with it, then run the other line through the loop, making sure to have enough tag for the wraps that are coming up. You want the thicker line to be the line that forms the loop.

Are You Nuts? Know your Fishing Knots! – Albright Knot

Step 3

Take the line that you ran through the loop and start wrapping it neatly around the loop about 10 times. Make sure the loops are tight against each other and don’t overlap each other.

Are You Nuts? Know your Fishing Knots! – Albright Knot

Step 4

Once you got the loops all done and neat keep everything pretty snug and neat like this.

Are You Nuts? Know your Fishing Knots! – Albright Knot

Step 5

Run the tag end of the wrapping line back through the original loop.

Are You Nuts? Know your Fishing Knots! – Albright Knot

Step 6

Once the line is back through the loop moisten the knot and pull the Albright knot up tight. Then trim the tag ends of the lines and it is finished. There is one last optional step of using some glue to secure the knot up even further and flatten the tags down. This will make for the smoothest and strongest knot possible but not needed every time.

Are You Nuts? Know your Fishing Knots! – Albright Knot

The post Are You Nuts? Know your Fishing Knots! – Albright Knot appeared first on AllOutdoor.com.

AllOutdoor.com

Tiny TV 2 + Tiny TV Mini

https://theawesomer.com/photos/2022/11/tiny_tv_sets_t.jpg

Tiny TV 2 + Tiny TV Mini

 | Pledge | Link

You can run to the Walmart or Costco and pick up an 85″ TV. But if you think that’s overkill, perhaps TinyCircuits’ miniature TV cabinets are more your thing. The TinyTV 2 has a 1″ screen with a 216×135 resolution, while the TinyTV Mini has an even smaller 0.6″ display with a 64×64 pixel grid. They play videos uploaded to an SD card.

The Awesomer

Fisher Cerakote Space Pens

https://theawesomer.com/photos/2022/11/fisher_cerakote_space_pens_t.jpg

Fisher Cerakote Space Pens

 | Buy

Fisher Space Pens are known for their longevity and ability to write in tough conditions. Fisher teamed up with NIC Industries to create Cerakote versions of their Bullet and Cap-O-Matic Space Pens. This ceramic coating protects against grime while improving grip. They come in matte black, tungsten, and Black Cherry.

The Awesomer

How to build a Laravel app using the OpenAI API

https://tectalic.com/img/blog/openai/ogImg.png

Overview

This tutorial outlines how to build a web application that generates business name and tagline ideas using OpenAI.

Here’s a quick demo video:

The user nominates their business’ industry and a concept, and the app will generate a set of business name ideas using OpenAI’s GPT-3 model text-davinci-002.

If you aren’t already familiar with OpenAI, it is a paid service that allows you to access AI models (including GPT-3) using a REST API.

Starter App

To help get up and running quickly, we have created a starter Laravel application that implements the above functionality including user interface elements.

The starter app is built using Laravel, Livewire and Tailwind CSS.

The starter app shows hard-coded results at the beginning, and you integrate it with OpenAI’s API to return live results.

This tutorial will guide you through how to integrate OpenAI into this starter app, however, the basic steps can also be followed with your own app if you prefer.

The tutorial uses the free Tectalic OpenAI API client for PHP to make the development process faster and minimise manual coding.

You can also find the final implementation here if you’d like to jump straight to the solution.

Requirements

To follow along, you will need the following:

  • An OpenAI account. If you don’t already have one, go to openai.com and create an account.
  • An already configured PHP development environment, including:
    • PHP 8.0+
    • composer
    • git
    • node and NPM
  • A PHP-capable IDE such:
  • Familiarity with your terminal/shell.
  • Familiarity with Laravel will help but is not essential.

Build the User Interface

Clone the skeleton app from GitHub using the following terminal commands:

git clone https://github.com/tectalichq/the-ai-name-generator.git

cd the-ai-name-generator

At this point, you will have the Laravel skeleton app installed, with version 0.1 checked out.

Now we will build the JavaScript and CSS assets that are required:

npm install

npm run build

We are now ready to get started with integrating OpenAI into the application – read on for details.

Integrate the OpenAI API

Install the Tectalic OpenAI API Client

Install the Tectalic OpenAI API Client, following the installation instructions:

composer require tectalic/openai

The above command adds the package into our project.

Configure the OpenAI API Client

This step allows us to set up and easily access our OpenAI API Client from anywhere in our Laravel application.

Open your app/Providers/AppServiceProvider.php file, and add the following highlighted code block to the existing register() method:

<?php

public function register()

{

$this->app->singleton(\Tectalic\OpenAi\Client\Client::class, function ($app) {

if (\Tectalic\OpenAi\Manager::isGlobal()) {

// Tectalic OpenAI REST API Client already built.

return \Tectalic\OpenAi\Manager::access();

}

/**

* Build the Tectalic OpenAI REST API Client globally.

*/

$auth = new \Tectalic\OpenAi\Authentication(config('services.openai.token'));

$httpClient = new \GuzzleHttp\Client();

return \Tectalic\OpenAi\Manager::build($httpClient, $auth);

});

}

The above code does several things:

  • It adds the OpenAI API Client (Tectalic\OpenAi\Client\Client) to the Laravel Service Container.
  • It configures the OpenAI API Client’s Authentication token based on a value in Laravel’s configuration (more on that in the following step).
  • It configures the OpenAI API Client to use the already installed Guzzle HTTP Client for performing HTTP requests. Any other PSR-18 compatible HTTP client (such as the Symfony HTTP Client) could also be used.

Authenticating the OpenAI API Client

Next, we will add a Laravel configuration setting to our app so that the OpenAI API Client uses the specified API Token.

To do so, open your config/services.php file, and add the following three green lines to the existing array:

<?php

 

return [

 

'openai' => [

'token' => env('OPENAI_TOKEN'),

],

 

];

Next, open the .env.example file, and add the following line to it:

OPENAI_TOKEN=

Now copy .env.example to .env:

cp .env.example .env

Now go to your OpenAI API Keys page and create a new secret key.

Paste your actual secret key into your .env file, so that the OPENAI_TOKEN value is replaced with your unique OpenAI API key.

For example:

OPENAI_TOKEN=sk-1234

(where sk-1234 is your actual OpenAI secret API Key).

This means that any OpenAI API calls will be authenticated using your own OpenAI secret API Key from your .env file.

Query the OpenAI API During the Form Submission Process

Logic and UI are separated

In the skeleton app, the App\Http\Livewire\NameGenerator Livewire component is what implements the form and UI. While the generateNames() method in the the app/Http/Livewire/NameGenerator.php file holds the logic.

Prepare the request

In this example, we will be using the OpenAI create completions endpoint, which allows us to send a prompt to OpenAI, and OpenAI will respond with one or more completions that match our context.

For more details on this OpenAI API endpoint, please consult the OpenAI Documentation.

Open the app/Http/Livewire/NameGenerator.php file, and find the generateNames() method around line 300.

This method is executed whenever the user submits the form, so we will now modify this method so that it queries the OpenAI API instead of returning hard-coded results.

First of all, this method needs access to our OpenAI API Client, so we will modify the method signature as follows:

297 /**

298 * When the form is submitted.

299 */

300 public function generateNames(): void

300 public function generateNames(\Tectalic\OpenAi\Client $client): void

301 {

This change will instruct Laravel to use its Service Container to automatically inject an OpenAI API Client instance into this method when the form is submitted, allowing us to refer to it using $client.

Next we will build an OpenAI prompt, based on the industry and concept chosen by the user in the form:

300 public function generateNames(\Tectalic\OpenAi\Client $client): void

301 {

302 $validated = $this->validate();

303 

304 $this->clearValidation();

305 

306 $prompt = sprintf(

307 'Give me a business name and tagline for a company in the %s industry with a %s concept',

308 $validated['industry'],

309 $validated['concept'],

310 );

If you’ve never designed an OpenAI prompt before, read OpenAI’s prompt design documentation.

Building the Request

Write the code that builds the actual API request that will be sent to the OpenAI create completions endpoint with the prompt from the previous step:

You can see from the above video that we use our OpenAI API Client instance ($client) to access the completions API handler, then call the create completion API method.

The Tectalic API Client, when combined with an IDE such as PhpStorm, will show you code completion information as you type, making it simpler to understand which API Handlers and Methods are supported by the API Client.

This create completion API method expects one argument, a Tectalic\OpenAi\Models\Completions\CreateRequest class instance. This PHP class contains all the properties that you can send to a create completion API request.

The structured nature of the request parameters makes it simpler to understand the structure and information required to send the request using only your IDE – you don’t need to spend time reading and understanding the create completion documentation.

In our particular case, we are using the following properties for the request:

Property Description
model The text-davinci-007 OpenAI model.
prompt The already assembled prompt ($prompt).
max_tokens We override the default token limit from 16 to 2048, which ensures that OpenAI can interpret our prompt. See here if you’d like to learn more about OpenAI tokens.
prompt We set this to 5 so that we get 5 completions (choices) back from OpenAI.

If you’d like more detail on the create completion API request parameters, please see here.

Sending the Request

Now that our request is assembled, it’s time to actually send the request to the OpenAI API endpoint:

As you can see, sending the request is as simple as calling the toModel() method on our $request instance.

Parsing the Response

The toModel() function used in the previous step actually does two things:

  • It sends the API request to OpenAI.
  • It parses the raw API response from OpenAI, and returns it in a structured way – in this case a Tectalic\OpenAi\Models\Completions\CreateResponse class instance.

Behind the scenes, the method is also converting the request to a JSON formatted request, sending it to the correct OpenAI endpoint, and then parsing the raw JSON formatted response, ensuring that it matches the expected format.

This structured response object makes it simpler to understand the structure and information in the OpenAI response – without needing to spend time reading the create completion response documentation.

It also enables static analysis tools for PHP, such as PHPStan or Psalm, which helps detect errors such as typos without the code being executed.

Choosing the Relevant Data From the Response

Now that we have sent the API request to OpenAI and retrieved the response, it is time to choose the relevant data from the OpenAI response and display it to our user:

The structured response objects mean you can use IDE code completion suggestions to understand what information is returned from OpenAI.

From the OpenAI response, we are only interested in the text property from the choices objects.

We use Laravel’s Array Map helper to iterate over the OpenAI response and return a simple array of result text(s).

These choices are saved to the names class property on our Livewire Component, which Livewire then automatically displays to our user in the Results section of the user interface.

Error Handling

The above implementation should be working, so if you were to run your app at this point, everything should work as expected. Phew!

However, we’ve only considered and implemented the successful (happy) path – we haven’t yet handled the unsuccessful (unhappy) path(s) for our API integration, including scenarios such as:

  • OpenAI’s API is temporarily inaccessible or unavailable.
  • A communication issue between your application and OpenAI’s API occurs.
  • OpenAI’s API returns an error code such as a 400 Bad Request (in the case that the request is invalid).

The following video demonstrates a simple method to handle these error scenarios gracefully:

This error handling is relatively straightforward to implement because the Tectalic OpenAI API Client automatically throws an Exception when errors occur. Specifically, a Tectalic\OpenAi\Exception\ClientException is thrown. Consult the error handling documentation for details.

In this case, we add try/catch block to our code, and then return a friendly error message to our user if an error does occur.

The Final Implementation

In case you need it, below is the final implementation, with code additions highlighted in green and code removals highlighted in red.

You can also find the implementation in the develop branch on GitHub.

composer.json:

13 "laravel/tinker": "^2.7",

14 "livewire/livewire": "^2.10"

14 "livewire/livewire": "^2.10",

15 "tectalic/openai": "^1.0.0"

16 },

.env.example

59 

60# OpenAI API Token

61OPENAI_TOKEN=

.env

59 

60# OpenAI API Token

61OPENAI_TOKEN=sk-1234

(where sk-1234 is your actual OpenAI secret API Key).

config/services.php:

24 'openai' => [

25 'token' => env('OPENAI_TOKEN'),

26 ],

app/Providers/AppServiceProvider.php:

18 public function register()

19 {

20 $this->app->singleton(\Tectalic\OpenAi\Client\Client::class, function ($app) {

21 if (\Tectalic\OpenAi\Manager::isGlobal()) {

22 // Tectalic OpenAI REST API Client already built.

23 return \Tectalic\OpenAi\Manager::access();

24 }

25 /**

26 * Build the Tectalic OpenAI REST API Client globally.

28 */

29 $auth = new \Tectalic\OpenAi\Authentication(config('services.openai.token'));

30 $httpClient = new \GuzzleHttp\Client();

31 return \Tectalic\OpenAi\Manager::build($httpClient, $auth);

32 });

33 }

app/Http/Livewire/NameGenerator.php:

297 /**

298 * When the form is submitted.

299 */

300 public function generateNames(): void

300 public function generateNames(\Tectalic\OpenAi\Client $client): void

301 {

302 $validated = $this->validate();

303 

304 $this->clearValidation();

305 

306 $prompt = sprintf(

307 'Give me a business name and tagline for a company in the %s industry with a %s concept',

308 $validated['industry'],

309 $validated['concept'],

310 );

311 

312 $request = $client->completions()->create(

313 new \Tectalic\OpenAi\Models\Completions\CreateRequest([

314 'model' => 'text-davinci-002',

315 'prompt' => $prompt,

316 'max_tokens' => 2048,

317 'n' => 5 // 5 completions

318 ])

319 );

320 

321 try {

322 /** @var \Tectalic\OpenAi\Models\Completions\CreateResponse $result */

323 $result = $request->toModel();

324 // Transform the result, as we only need to use the text from each completion choice.

325 $this->names = \Illuminate\Support\Arr::map($result->choices, function (\Tectalic\OpenAi\Models\Completions\CreateResponseChoicesItem $item) {

326 return $item->text;

327 });

328 } catch (\Tectalic\OpenAi\Exception\ClientException $e) {

329 // Error querying OpenAI.

330 // Clear any existing results and display an error message.

331 $this->reset(['names']);

332 $this->addError('results', __('Results are temporarily unavailable. Please try again later.'));

333 }

334 }

Run Your App

At this point, we will run our app and give it a try in our web browser:

Congratulations – we’re done!

The app should now be fully functional. Take a few minutes to experiment with various industries and concepts, and entertain yourself with the results.

Laravel News Links

Your Mac Has a Hidden White Noise Generator

https://i.kinja-img.com/gawker-media/image/upload/c_fill,f_auto,fl_progressive,g_center,h_675,pg_1,q_80,w_1200/a1c777020d9b1f9dd584d56f5350bba7.jpg

Photo: Gorodenkoff (Shutterstock)

If you want to drown out environmental noise, or you just like having white noise in the background while you work, you should try your Mac’s white noise generator. The feature is actually built into every Mac that runs macOS Ventura, you just need to know where to find it.

How to enable Background Sounds on macOS Ventura

You can find the white noise generator in your Mac’s settings menu. Click the Apple logo in the top-left corner of the screen and select System Settings. Next, select Accessibility in the left sidebar and click Audio in the right pane. Go to the Background Sounds section to enable Background Sounds. Once you’ve done that, you can select from a bunch of different sounds for your Mac. Click the Choose button next to Background Sound and you’ll see the following options:

  • Balanced Noise
  • Bright Noise
  • Dark Noise
  • Ocean
  • Rain
  • Stream

Hit the download button next to the sounds you want to download. That’ll save them to your Mac so you can also play them if you’re offline.

On the previous settings page, there are a couple useful options you should also check out. The first is Background Sounds Volume, which lets you set the volume level for the audio files. Once you’ve picked a comfortable volume, enable Turn off Background Sounds when your Mac is not in use. This setting will stop the sounds when your Mac goes to sleep.

How to generate white noise on older versions of macOS

Unfortunately, Apple’s Background Sounds feature is restricted to the Macs that can run Ventura. If you have an older Mac, you can use other tools to play white noise in the background. Music streaming services usually have a pretty good collection of white noise. Here are some examples on Spotify, Apple Music, and YouTube. Alternatively, you can try white noise apps such as Noizio.

G/O Media may get a commission

Super stylish STEM learning.
These Mann Magnets Gear Toys are a simple and stylish way for kids to learn to problem solve in a STEM setting. With this set, kids can group and design, creating more complex gears as they learn.

 

Lifehacker