https://github.com/dulajkavinda/sentiment-analysis
Calculating the sentiment of a given conversation real-time with ChatGPT API, AWS Lamdba with Serverless and NodeJS
https://github.com/dulajkavinda/sentiment-analysis
chatgpt lambda-functions openai-api serverless-framework typescript
Last synced: 6 months ago
JSON representation
Calculating the sentiment of a given conversation real-time with ChatGPT API, AWS Lamdba with Serverless and NodeJS
- Host: GitHub
- URL: https://github.com/dulajkavinda/sentiment-analysis
- Owner: dulajkavinda
- Created: 2023-05-03T11:52:46.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-05-03T13:14:29.000Z (over 2 years ago)
- Last Synced: 2025-03-27T08:53:35.119Z (6 months ago)
- Topics: chatgpt, lambda-functions, openai-api, serverless-framework, typescript
- Language: TypeScript
- Homepage: https://sentiment-analysis-chatgpt.vercel.app/
- Size: 187 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Serverless Lambda Function for Sentiment Analysis using ChatGPT API and MongoDB
This repository contains a serverless Lambda function that performs sentiment analysis using the ChatGPT API and stores the results in a MongoDB database. The function is built using the Serverless Framework and can be deployed to any compatible serverless platform, such as AWS Lambda.
![]()
## Functionality
The Lambda function takes a text input as a parameter and uses the ChatGPT API to perform sentiment analysis on the text. It then stores the analyzed text along with its sentiment score in a MongoDB database for further analysis and retrieval. The sentiment score indicates the sentiment of the text, ranging from negative to positive.### OpenAI configuration
```
openai.createCompletion({
model: "text-davinci-003",
prompt,
temperature: 0.7,
max_tokens: 256,
top_p: 1,
frequency_penalty: 0,
presence_penalty: 0,
});
```### Request Body
```
{
"headers": {
"Content-Type": "application/json"
},
"message": "htis is cool",
"type": "CUSTOMER",
"context": 3
}```
### Response
```
{
"messages": {
"sentiment": "Positive",
"score": 10,
"avgCustomerSentiment": 4.75,
"customerSentimentScores": [
{
"score": 5,
"sentiment": "Neutral"
},
{
"score": 10,
"sentiment": "Positive"
},
]
}
}
```