From 0874530968d29b707262ede54f973aeff8e36867 Mon Sep 17 00:00:00 2001 From: "Mike P. Sinn" Date: Fri, 28 Jul 2023 00:37:21 -0500 Subject: [PATCH] Text 2 Measurements docs and GitHub action --- .github/workflows/publish-libraries.yml | 33 +++++++ .gitignore | 4 +- libs/text-2-measurements/README.md | 57 ++++++++++++ package.json | 3 +- tsconfig.base.json | 1 + yarn.lock | 115 +++++++++++++++++++++++- 6 files changed, 208 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/publish-libraries.yml create mode 100644 libs/text-2-measurements/README.md diff --git a/.github/workflows/publish-libraries.yml b/.github/workflows/publish-libraries.yml new file mode 100644 index 000000000..f2738433b --- /dev/null +++ b/.github/workflows/publish-libraries.yml @@ -0,0 +1,33 @@ +name: Publish to npm + +on: + push: + tags: + - '*' + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Use Node.js + uses: actions/setup-node@v2 + with: + node-version: 14 + registry-url: 'https://registry.npmjs.org' + + - name: Install dependencies + run: npm install + + - name: Build + run: npx nx build text-2-measurements + + - name: Test + run: npx nx test text-2-measurements + + - name: Publish + run: npx nx npm publish text-2-measurements + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.gitignore b/.gitignore index 515574cc6..6c765653a 100644 --- a/.gitignore +++ b/.gitignore @@ -42,9 +42,9 @@ Thumbs.db # Next.js .next .idea/ -/.env +.env # Ignore Smart Connections folder because embeddings file is large and updated frequently .smart-connections -/.obsidian/ \ No newline at end of file +/.obsidian/ diff --git a/libs/text-2-measurements/README.md b/libs/text-2-measurements/README.md new file mode 100644 index 000000000..3fa0bfe41 --- /dev/null +++ b/libs/text-2-measurements/README.md @@ -0,0 +1,57 @@ +# Text2Measurements - Diet, Treatment, and Symptom Tracking with NLP + +This library provides a way to convert natural language inputs into structured data about diet, treatment, and symptom tracking. It parses the user input, and can handle a wide range of inputs related to what the user ate, what treatments they took, and how severe their symptoms were. + +## Features + +- Converts complex linguistic inputs into a structured JSON format. +- Handles a variety of measurement units and variable categories. +- Can handle a wide range of diet, treatment, and symptom tracking statements. + +## Installation + +Clone this repository and navigate to the project root. Install the dependencies with npm: + +```bash +yarn install +``` + +## Usage + +### Processing a Single Statement + +```typescript +import { processStatement } from './text-2-measurements'; +const result = await processStatement("I ate a bowl of oatmeal for breakfast."); +``` + +### Processing Multiple Statements + +```typescript +import { processStatements } from './text-2-measurements'; +const results = await processStatements([ + "I ate a bowl of oatmeal for breakfast.", + "Took 500mg of Paracetamol at 10 AM.", + "Experienced a headache around midday, severity was 3 out of 5." +]); +``` + +## Testing + +To run the tests, execute: + +```bash +npm run test +``` + +## Contributing + +Contributions are welcome. Please open an issue or submit a pull request. + +## License + +This project is licensed under the MIT License. + +## Contact + +Please open an issue in this repository if you have any questions or need further guidance. diff --git a/package.json b/package.json index 15ea01377..0f6bdcd2a 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "regenerator-runtime": "0.13.7", "rimraf": "^3.0.2", "tslib": "^2.3.0", + "typechat": "^0.0.10", "underscore.string": "^3.3.6" }, "devDependencies": { @@ -75,6 +76,7 @@ "fast-glob": "^3.2.12", "jest": "29.4.3", "jest-environment-jsdom": "29.4.3", + "jest-environment-node": "^29.4.1", "jsonc-eslint-parser": "^2.1.0", "nx": "15.9.2", "openai": "^3.2.1", @@ -85,4 +87,3 @@ "typescript": "5.1.6" } } - diff --git a/tsconfig.base.json b/tsconfig.base.json index 5a3588e26..bc590a917 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -32,6 +32,7 @@ ], "@curedao/sdk-typescript-node": ["libs/sdk-typescript-node/src/index.ts"], "@curedao/test-helpers": ["libs/test-helpers/src/index.ts"], + "@curedao/text-2-measurements": ["libs/text-2-measurements/src/index.ts"], "@curedao/url-helper": ["libs/url-helper/src/index.ts"] } }, diff --git a/yarn.lock b/yarn.lock index 9246aaafe..9561837e3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2558,6 +2558,16 @@ "@types/node" "*" jest-mock "^29.5.0" +"@jest/environment@^29.6.1": + version "29.6.1" + resolved "https://registry.yarnpkg.com/@jest/environment/-/environment-29.6.1.tgz#ee358fff2f68168394b4a50f18c68278a21fe82f" + integrity sha512-RMMXx4ws+Gbvw3DfLSuo2cfQlK7IwGbpuEWXCqyYDcqYTI+9Ju3a5hDnXaxjNsa6uKh9PQF2v+qg+RLe63tz5A== + dependencies: + "@jest/fake-timers" "^29.6.1" + "@jest/types" "^29.6.1" + "@types/node" "*" + jest-mock "^29.6.1" + "@jest/expect-utils@^28.1.3": version "28.1.3" resolved "https://registry.yarnpkg.com/@jest/expect-utils/-/expect-utils-28.1.3.tgz#58561ce5db7cd253a7edddbc051fb39dda50f525" @@ -2612,6 +2622,18 @@ jest-mock "^29.5.0" jest-util "^29.5.0" +"@jest/fake-timers@^29.6.1": + version "29.6.1" + resolved "https://registry.yarnpkg.com/@jest/fake-timers/-/fake-timers-29.6.1.tgz#c773efddbc61e1d2efcccac008139f621de57c69" + integrity sha512-RdgHgbXyosCDMVYmj7lLpUwXA4c69vcNzhrt69dJJdf8azUrpRh3ckFCaTPNjsEeRi27Cig0oKDGxy5j7hOgHg== + dependencies: + "@jest/types" "^29.6.1" + "@sinonjs/fake-timers" "^10.0.2" + "@types/node" "*" + jest-message-util "^29.6.1" + jest-mock "^29.6.1" + jest-util "^29.6.1" + "@jest/globals@^28.1.3": version "28.1.3" resolved "https://registry.yarnpkg.com/@jest/globals/-/globals-28.1.3.tgz#a601d78ddc5fdef542728309894895b4a42dc333" @@ -2706,6 +2728,13 @@ dependencies: "@sinclair/typebox" "^0.25.16" +"@jest/schemas@^29.6.0": + version "29.6.0" + resolved "https://registry.yarnpkg.com/@jest/schemas/-/schemas-29.6.0.tgz#0f4cb2c8e3dca80c135507ba5635a4fd755b0040" + integrity sha512-rxLjXyJBTL4LQeJW3aKo0M/+GkCOXsO+8i9Iu7eDb6KwtP65ayoDsitrdPBtujxQ88k4wI2FNYfa6TOGwSn6cQ== + dependencies: + "@sinclair/typebox" "^0.27.8" + "@jest/source-map@^28.1.2": version "28.1.2" resolved "https://registry.yarnpkg.com/@jest/source-map/-/source-map-28.1.2.tgz#7fe832b172b497d6663cdff6c13b0a920e139e24" @@ -2840,6 +2869,18 @@ "@types/yargs" "^17.0.8" chalk "^4.0.0" +"@jest/types@^29.6.1": + version "29.6.1" + resolved "https://registry.yarnpkg.com/@jest/types/-/types-29.6.1.tgz#ae79080278acff0a6af5eb49d063385aaa897bf2" + integrity sha512-tPKQNMPuXgvdOn2/Lg9HNfUvjYVGolt04Hp03f5hAk878uwOLikN+JzeLY0HcVgKgFl9Hs3EIqpu3WX27XNhnw== + dependencies: + "@jest/schemas" "^29.6.0" + "@types/istanbul-lib-coverage" "^2.0.0" + "@types/istanbul-reports" "^3.0.0" + "@types/node" "*" + "@types/yargs" "^17.0.8" + chalk "^4.0.0" + "@jridgewell/gen-mapping@^0.3.0", "@jridgewell/gen-mapping@^0.3.2": version "0.3.3" resolved "https://registry.yarnpkg.com/@jridgewell/gen-mapping/-/gen-mapping-0.3.3.tgz#7e02e6eb5df901aaedb08514203b096614024098" @@ -4205,6 +4246,11 @@ resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.25.24.tgz#8c7688559979f7079aacaf31aa881c3aa410b718" integrity sha512-XJfwUVUKDHF5ugKwIcxEgc9k8b7HbznCp6eUfWgu710hMPNIO4aw4/zB5RogDQz8nd6gyCDpU9O/m6qYEWY6yQ== +"@sinclair/typebox@^0.27.8": + version "0.27.8" + resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.27.8.tgz#6667fac16c436b5434a387a34dedb013198f6e6e" + integrity sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA== + "@sindresorhus/is@^4.0.0": version "4.6.0" resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-4.6.0.tgz#3c7c9c46e678feefe7a2e5bb609d3dbd665ffb3f" @@ -6217,7 +6263,7 @@ axios@0.21.1: dependencies: follow-redirects "^1.10.0" -axios@1.4.0, axios@^1.0.0, axios@^1.3.4: +axios@1.4.0, axios@^1.0.0, axios@^1.3.4, axios@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/axios/-/axios-1.4.0.tgz#38a7bf1224cd308de271146038b551d725f0be1f" integrity sha512-S4XCWMEmzvo64T9GfvQDOXgYRDJ/wsSZc7Jvdgx5u1sd0JwsuPLqb3SYmusag+edF6ziyMensPVqLTSc1PiSEA== @@ -11226,6 +11272,18 @@ jest-environment-node@^28.1.1, jest-environment-node@^28.1.3: jest-mock "^28.1.3" jest-util "^28.1.3" +jest-environment-node@^29.4.1: + version "29.6.1" + resolved "https://registry.yarnpkg.com/jest-environment-node/-/jest-environment-node-29.6.1.tgz#08a122dece39e58bc388da815a2166c58b4abec6" + integrity sha512-ZNIfAiE+foBog24W+2caIldl4Irh8Lx1PUhg/GZ0odM1d/h2qORAsejiFc7zb+SEmYPn1yDZzEDSU5PmDkmVLQ== + dependencies: + "@jest/environment" "^29.6.1" + "@jest/fake-timers" "^29.6.1" + "@jest/types" "^29.6.1" + "@types/node" "*" + jest-mock "^29.6.1" + jest-util "^29.6.1" + jest-environment-node@^29.5.0: version "29.5.0" resolved "https://registry.yarnpkg.com/jest-environment-node/-/jest-environment-node-29.5.0.tgz#f17219d0f0cc0e68e0727c58b792c040e332c967" @@ -11352,6 +11410,21 @@ jest-message-util@^29.5.0: slash "^3.0.0" stack-utils "^2.0.3" +jest-message-util@^29.6.1: + version "29.6.1" + resolved "https://registry.yarnpkg.com/jest-message-util/-/jest-message-util-29.6.1.tgz#d0b21d87f117e1b9e165e24f245befd2ff34ff8d" + integrity sha512-KoAW2zAmNSd3Gk88uJ56qXUWbFk787QKmjjJVOjtGFmmGSZgDBrlIL4AfQw1xyMYPNVD7dNInfIbur9B2rd/wQ== + dependencies: + "@babel/code-frame" "^7.12.13" + "@jest/types" "^29.6.1" + "@types/stack-utils" "^2.0.0" + chalk "^4.0.0" + graceful-fs "^4.2.9" + micromatch "^4.0.4" + pretty-format "^29.6.1" + slash "^3.0.0" + stack-utils "^2.0.3" + jest-mock@^28.1.3: version "28.1.3" resolved "https://registry.yarnpkg.com/jest-mock/-/jest-mock-28.1.3.tgz#d4e9b1fc838bea595c77ab73672ebf513ab249da" @@ -11369,6 +11442,15 @@ jest-mock@^29.4.3, jest-mock@^29.5.0: "@types/node" "*" jest-util "^29.5.0" +jest-mock@^29.6.1: + version "29.6.1" + resolved "https://registry.yarnpkg.com/jest-mock/-/jest-mock-29.6.1.tgz#049ee26aea8cbf54c764af649070910607316517" + integrity sha512-brovyV9HBkjXAEdRooaTQK42n8usKoSRR3gihzUpYeV/vwqgSoNfrksO7UfSACnPmxasO/8TmHM3w9Hp3G1dgw== + dependencies: + "@jest/types" "^29.6.1" + "@types/node" "*" + jest-util "^29.6.1" + jest-pnp-resolver@^1.2.2: version "1.2.3" resolved "https://registry.yarnpkg.com/jest-pnp-resolver/-/jest-pnp-resolver-1.2.3.tgz#930b1546164d4ad5937d5540e711d4d38d4cad2e" @@ -11641,6 +11723,18 @@ jest-util@^29.0.0, jest-util@^29.4.3, jest-util@^29.5.0: graceful-fs "^4.2.9" picomatch "^2.2.3" +jest-util@^29.6.1: + version "29.6.1" + resolved "https://registry.yarnpkg.com/jest-util/-/jest-util-29.6.1.tgz#c9e29a87a6edbf1e39e6dee2b4689b8a146679cb" + integrity sha512-NRFCcjc+/uO3ijUVyNOQJluf8PtGCe/W6cix36+M3cTFgiYqFOOW5MgN4JOOcvbUhcKTYVd1CvHz/LWi8d16Mg== + dependencies: + "@jest/types" "^29.6.1" + "@types/node" "*" + chalk "^4.0.0" + ci-info "^3.2.0" + graceful-fs "^4.2.9" + picomatch "^2.2.3" + jest-validate@^28.1.1, jest-validate@^28.1.3: version "28.1.3" resolved "https://registry.yarnpkg.com/jest-validate/-/jest-validate-28.1.3.tgz#e322267fd5e7c64cea4629612c357bbda96229df" @@ -14258,6 +14352,15 @@ pretty-format@^29.0.0, pretty-format@^29.5.0: ansi-styles "^5.0.0" react-is "^18.0.0" +pretty-format@^29.6.1: + version "29.6.1" + resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-29.6.1.tgz#ec838c288850b7c4f9090b867c2d4f4edbfb0f3e" + integrity sha512-7jRj+yXO0W7e4/tSJKoR7HRIHLPPjtNaUGG2xxKQnGvPNRkgWcQ0AZX6P4KBRJN4FcTBWb3sa7DVUJmocYuoog== + dependencies: + "@jest/schemas" "^29.6.0" + ansi-styles "^5.0.0" + react-is "^18.0.0" + pretty-time@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/pretty-time/-/pretty-time-1.1.0.tgz#ffb7429afabb8535c346a34e41873adf3d74dd0e" @@ -16549,6 +16652,14 @@ type-is@^1.6.14, type-is@^1.6.16, type-is@~1.6.18: media-typer "0.3.0" mime-types "~2.1.24" +typechat@^0.0.10: + version "0.0.10" + resolved "https://registry.yarnpkg.com/typechat/-/typechat-0.0.10.tgz#cb3c302cc218f078999c34eaf22aa6300dfb767b" + integrity sha512-iF/wLLaZWt4Q9WO8stpq3NKilAa4b8hnCD16EirdhaxzAYk80MCb1wnW1il7GhkMNJuhJUD38dxs8q4A/EdxJw== + dependencies: + axios "^1.4.0" + typescript "^5.1.3" + typed-array-length@^1.0.4: version "1.0.4" resolved "https://registry.yarnpkg.com/typed-array-length/-/typed-array-length-1.0.4.tgz#89d83785e5c4098bec72e08b319651f0eac9c1bb" @@ -16580,7 +16691,7 @@ typescript@5.1.3: resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.1.3.tgz#8d84219244a6b40b6fb2b33cc1c062f715b9e826" integrity sha512-XH627E9vkeqhlZFQuL+UsyAXEnibT0kWR2FWONlr4sTjvxyJYnyefgrkyECLzM5NenmKzRAy2rR/OlYLA1HkZw== -typescript@5.1.6: +typescript@5.1.6, typescript@^5.1.3: version "5.1.6" resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.1.6.tgz#02f8ac202b6dad2c0dd5e0913745b47a37998274" integrity sha512-zaWCozRZ6DLEWAWFrVDz1H6FVXzUSfTy5FUMWsQlU8Ym5JP9eO4xkTIROFCQvhQf61z6O/G6ugw3SgAnvvm+HA==