top of page

Actionable Intelligence

Ideas and thoughts to consider

Search

While it wouldn't be right to share the entire solution to the DIY test section, I do think its fair to share some tips to get past recently introduced errors and exceptions.

TLDR:

Problem: Can't deploy SAM after changing the app.py code to the code in the downloaded exercise file

Solution: Change the requirements.txt file by removing "request" and adding urllib3==1.26.15

Reason: If you don't lock in the version of urllib3 to 1.26 it will go up to version 2+ which requires an updated openssl to be compiled into your python environment


Problem: Can't change the template.yaml and get it recognized to be deployed.


Solution: I recommend the following be added to the template so your database will be recognized. Add this to the yaml file just below the "HelloWorldFunction:" declaration




MySimpleTable:

Type: AWS::Serverless::SimpleTable

Properties:

TableName: MyTable

PrimaryKey:

Name: id

Type: String

ProvisionedThroughput:

ReadCapacityUnits: 5

WriteCapacityUnits: 5


Now your deployment will create the database in the cloudformation stack.


Finally, if for some reason your code commit doesn't work, go into CodeCommit itself and add the above code into your template.yaml directly.


Go to CodeCommits -> Developer Tools -> Repositories -> my-app and edit the template.yaml adding this resource in. Save, add your fake name/email and commit


These fixes should get you through it.



16 views0 comments

TLDR:

Problem:

When you try to import openai in AWS Lambda, it errors with ssl needs to be v1.1.1 or import boto3 to retrieve the API key, it errors with can’t import DEFAULT_CIPHER required urllib3 v2.02


FIX:

1. Using AWS Cloud9, create a python 3.7 SAM and upgrade to 3.10 (click here for instructions)

2. Create a python environment with urllib3==1.26 in the python env run “pip3.10 install urllib3==1.26” (not with the quotes)

3. Create an AWS Lambda layer with the python environment (click here)

4. This chatgpt code (click here) will work now (as of May 13, 2023)


Details:

It was a sunny Saturday afternoon that started off with a inspiration let's to setup AWS API to run ChatGPT and replace a function call from Wix backend. A quick test on the local PC showed that by running but no JS function we could set up a listener and then call that listener then that listener would go ahead and call the ChatGPT function. So we knew from documentation that we could do the same using the AWS API gateway, Lambda function etc.


Motivations:

1. Running back end functions on Wix has limitations the main being that you can't use it in other formats like connecting up to telegram or line. By creating the API call on AWS will you be able to use the same API for other user interfaces. We also have more control and be able to take advantage of the much larger infrastructure of AWS.

2. We get more error handling and performance information on the OpenAI api call

3. We can switch to other AIs like BARD or ERNIE when available or compare responses during research

4. We got a solid code repository and version control


At first it was easy.


To setup an API on AWS takes just 3 steps (its dirty and not secure but we can start here just to see if the juice is worth the squeeze)


  1. Open Lambda


Keep Python 3.10 it will come in handy later (I know, I started with 3.8, I never like the newest version of python...)


Keep the default create new role with basic Lambda permissions

Click the create button


We'll test this code first:



Create a new test and run it



Enter EventName, anything you want

Click save



There we go, it works! Now lets connect it to an API Gateway


Back that the top choose "Add Trigger




You can use create a new API

keep the default HTTP API

and Security Open


Click Add


Now we have our API Gateway attached. Let's Test!




Copy this endpoint to a cmd prompt and run "CURL https... "




It works! If you click on the link it will open in the web browser

Or you could use the CURL command in the command prompt


It feels like we are seconds away from moving our javascript wix openai call to python on AWS. Afterall, chatgpt can convert the code for you!


Let's test, can I import the "request" library that I need which is equivalent to the node-fetch library in js.


I won't change anything, except add in the import just to see if I will be able to?

Hahaha! Nope!



Well, surely there is a function amazon provides! How about boto.vendored as per StackExchange (click here)



6 year old issue... ok.


What to do? Maybe use urllib3


Well, that imports!



and its successfully tests


OK! now let's get some data! Long story short, this doesn't work well... because you still need to import openai. As soon as we do that we get another error



Simple, follow these instructions to add openai to a layer (click here) Great walk through of adding python packages. But it still doesn't work because if you use python3.7 to 3.9 the openssl version is 1.0.2 but it now needs to be 1.1.1 so you need to recompile python with the upgraded version of ssl. These instruction here work great (click here)


What doesn't work great is starting up a python3.10 environment in Cloud9!!! It actually errors, so you have to start a 3.7SAM and upgrade to 3.10 (at least 30 mins)


OK, once we add the layer to our function we a almost good to go. Right?


Nope, you don't want to expose your API Key so we'll want some code to retrieve it. Introducing import Boto3 and



To get past this I had to go back to the python3.10 env and pip3.10 install urllib3==1.26 and redploy the updated layer.


That fixed it and we are finally of to the races!


And what did we learn... chatGPT is not replacing programmers anytime soon...




7 views0 comments

In this podcast All-In episode124, hosts Chamath Palihapitiya, Jason Calacanis, David Sacks & David Friedberg discuss the potential and risks of AutoGPT, an autonomous task execution AI. They touch upon the benefits of AI in terms of increased efficiency, but also the potential risks of job displacement and ethical concerns.


The conversation then shifts towards the topic of AI regulation and the need ffor governments to regulate the development and deployment of AI technologies. They discuss the role of government in ensuring that AI is developed and used responsibly, and how AI can be used to address some of the world's biggest challenges.


Overall, the episode emphasizes the need for cautious yet forward-thinking approaches when it comes to the development and regulation of AI.



Art generated by Midjourney for Keith B. Carter

24 views0 comments
1
2
bottom of page