-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #162 from mikepsinn/develop
Text2Measurements library, app, tests, etc.
- Loading branch information
Showing
23 changed files
with
3,304 additions
and
246 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: Text2Measurements tests | ||
|
||
on: | ||
push: | ||
paths: | ||
- 'libs/text-2-measurements/**' | ||
pull_request: | ||
paths: | ||
- 'libs/text-2-measurements/**' | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Use Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: '14' | ||
|
||
- name: Install Dependencies | ||
run: | | ||
cd libs/text-2-measurements | ||
npm ci | ||
- name: Run Tests | ||
run: | | ||
cd libs/text-2-measurements | ||
npm test |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const { processStatement } = require('./src/lib/statement-2-measurements'); | ||
|
||
async function parseStatement() { | ||
const statement = "I have been feeling very tired and fatigued today. I have been having trouble concentrating and I have been feeling very down. I took a cold shower for 5 minutes and I took a 20 minute nap. I also took magnesium 200mg, Omega3 one capsule 500mg"; | ||
const localDateTime = "2021-01-01T20:00:00"; // Example date and time | ||
const result = await processStatement(statement, localDateTime); | ||
console.log(result); | ||
} | ||
|
||
parseStatement(); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Form Page</title> | ||
<link rel="stylesheet" href="styles.css"> | ||
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet"> | ||
<link href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/themes/prism-tomorrow.min.css" rel="stylesheet" /> | ||
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" /> | ||
</head> | ||
<body> | ||
|
||
<div> | ||
<a href="/settings">Settings</a> | ||
<form id="myForm" action="/parse" method="POST"> | ||
<label for="statement">What were your symptoms, foods, and treatments today?</label><br> | ||
<textarea id="statement" name="statement" rows="4" cols="50"></textarea><br> | ||
<input type="submit" value="Submit"> | ||
</form> | ||
<div id="loader" style="display: none;">Loading...</div> | ||
<div class="card mt-3"> | ||
<div class="card-body"> | ||
<pre id="response" class="language-json"><code></code></pre> | ||
</div> | ||
</div> | ||
</div> | ||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> | ||
<script src="script.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/prism.min.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/components/prism-json.min.js"></script> | ||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
$(document).ready(function() { | ||
$('#myForm').on('submit', function(e) { | ||
e.preventDefault(); | ||
$('#loader').show(); | ||
$.ajax({ | ||
url: $(this).attr('action'), | ||
type: $(this).attr('method'), | ||
data: $(this).serialize(), | ||
success: function(data) { | ||
$('#loader').hide(); | ||
var jsonData = JSON.parse(data); // Parse the response string into a JSON object | ||
$('#response code').text(JSON.stringify(jsonData, null, 2)); // Pretty-print the JSON object | ||
Prism.highlightAll(); | ||
$('.card').addClass('has-content'); // Add class to show the response box | ||
}, | ||
error: function() { | ||
$('#loader').hide(); | ||
$('#response').html('An error occurred.'); | ||
$('.card').addClass('has-content'); // Add class to show the response box | ||
} | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
body { | ||
font-family: 'Roboto', sans-serif; | ||
background-color: #f4f4f4; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 100vh; | ||
margin: 0; | ||
padding: 0; | ||
box-sizing: border-box; | ||
} | ||
|
||
form { | ||
width: 300px; | ||
padding: 20px; | ||
background-color: #fff; | ||
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1); | ||
} | ||
|
||
label, textarea, input[type="submit"] { | ||
display: block; | ||
margin-bottom: 10px; | ||
} | ||
|
||
textarea { | ||
width: 100%; | ||
height: 100px; | ||
padding: 10px; | ||
box-sizing: border-box; | ||
} | ||
|
||
input[type="submit"] { | ||
background-color: #007BFF; | ||
color: #fff; | ||
border: none; | ||
padding: 10px; | ||
cursor: pointer; | ||
transition: background-color 0.3s ease; | ||
} | ||
|
||
input[type="submit"]:hover { | ||
background-color: #0056b3; | ||
} | ||
|
||
a { | ||
display: block; | ||
text-align: center; | ||
margin-top: 20px; | ||
color: #007BFF; | ||
text-decoration: none; | ||
} | ||
|
||
.card { | ||
display: none; | ||
} | ||
|
||
.card.has-content { | ||
display: block; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
const express = require('express'); | ||
const bodyParser = require('body-parser'); | ||
const os = require('os'); | ||
const { processStatement } = require('./src/lib/statement-2-measurements'); | ||
const session = require('express-session'); | ||
const app = express(); | ||
const dotenv = require('dotenv'); | ||
// Load environment variables from .env file | ||
dotenv.config(); | ||
|
||
app.use(bodyParser.urlencoded({ extended: false })); | ||
app.use(bodyParser.json()); | ||
|
||
const path = require('path'); | ||
|
||
// ... | ||
|
||
// Serve static files from the 'public' directory | ||
app.use(express.static(path.join(__dirname, 'public'))); | ||
|
||
app.get('/', (req, res) => { | ||
res.sendFile(path.join(__dirname, 'public', 'index.html')); | ||
}); | ||
|
||
app.use(session({ | ||
secret: process.env.SESSION_SECRET, | ||
resave: false, | ||
saveUninitialized: true, | ||
})); | ||
|
||
// Route to render the form | ||
app.get('/settings', (req, res) => { | ||
res.send(` | ||
<form action="/settings" method="POST"> | ||
<label for="api_key">OpenAI API Key:</label><br> | ||
<input type="text" id="api_key" name="api_key"><br> | ||
<label for="model">OpenAI Model:</label><br> | ||
<select id="model" name="model"> | ||
<option value="gpt-3.5-turbo">gpt-3.5-turbo</option> | ||
<option value="gpt-4">gpt-4</option> | ||
<option value="gpt-4-0125-preview">gpt-4-0125-preview</option> | ||
</select><br> | ||
<input type="submit" value="Submit"> | ||
</form> | ||
`); | ||
}); | ||
|
||
// Form submission handler | ||
app.post('/settings', (req, res) => { | ||
// Store user's input in the session | ||
req.session.OPENAI_API_KEY = req.body.api_key; | ||
req.session.OPENAI_MODEL = req.body.model; | ||
res.redirect('/'); | ||
}); | ||
|
||
// Use OPENAI_API_KEY and OPENAI_MODEL in your OpenAI API calls | ||
|
||
app.post('/parse', async (req, res) => { | ||
const statement = req.body.statement; | ||
// Before calling the OpenAI API | ||
const OPENAI_API_KEY = req.session.OPENAI_API_KEY || process.env.OPENAI_API_KEY; | ||
const OPENAI_MODEL = req.session.OPENAI_MODEL || process.env.OPENAI_MODEL; | ||
const apiKey = req.headers['t2m-api-key']; // Assuming the API key is sent in the headers | ||
|
||
// Check if T2M_API_KEY is set and matches the one in the request | ||
if (process.env.T2M_API_KEY && process.env.T2M_API_KEY !== apiKey) { | ||
return res.status(400).send('Invalid T2M_API_KEY'); | ||
} | ||
const result = await processStatement(statement); | ||
res.send(result); // Pretty print the response | ||
}); | ||
|
||
app.listen(process.env.PORT || 3000, () => { | ||
console.log(`Server is running at http://${os.hostname()}:${process.env.PORT || 3000}`); | ||
}); | ||
|
||
app.use((req, res, next) => { | ||
console.log(`Request URL: ${req.protocol}://${req.get('host')}${req.originalUrl}`); | ||
next(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -177,3 +177,4 @@ function textToMeasurements(question, answer, categories, units) { | |
module.exports = { | ||
textToMeasurements | ||
}; | ||
|
Oops, something went wrong.