Create a bucket in s3 to store deployment artifacts. You can name it "prompt-processor-assets". If you choose a different name, make sure you update the package.json deploy command.
Make sure you use the right IAM role with enough priviledges to deploy this stack
Run "npm run build" This will build all the lambda packages
Run "npm run deploy:dev" or "npm run deploy:prod" This will deploy all the necessary infrastructure
You should set up your openai token in SSM Parameter with name "/openai/apikey" The api gateway token will be stored in a SSM parameter with name "/dev/resources/api/token" or "/prod/resources/api/token" You can choose to replace the default token with a new token.
Get the api endpoint by:
-
Go to API Gateway
-
Click on the api created : dev-prompt-processor-api
-
From the left hand side menu, Click on Stages
-
Select the dev stage dropdown
-
There should be two methods with the same path, for example: a. POST: https://hbibhxq3ha.execute-api.ap-southeast-2.amazonaws.com/dev/gpt/prompt b. GET: https://hbibhxq3ha.execute-api.ap-southeast-2.amazonaws.com/dev/gpt/prompt
-
Use an api testing tool like Postman to send requests
The POST request body:
json``` { "type": "chat", "model": "gpt-3.5-turbo", "prompt": "What is a recipe for a tiramisu?", "systemMsg": "You are the best chef in the world", "randomness": 0.7, "maxToken": 1000 }
Optional fields: systemMsg, randomness, maxToken
The type has to be either chat or completion
Note: Before selecting a model, ensure it is valid by going to openai documentation
Once you receive a response, you can take the id and initiate a GET request:
https://hbibhxq3ha.execute-api.ap-southeast-2.amazonaws.com/dev/gpt/prompt?id=a59cb146-ccc8-4a49-aa7a-d2f11ca64566
This will return all the necessary contents.
## 8. Error handling
In dynamoDB if the processStatus is ERROR, you can check gptResponse for the cause.
You can inspect Cloudwatch logs to drill down on specific errors too.
The queue will retry a payload once before sending it to a Deadletter Queue.