Skip to content

Commit

Permalink
✨ test for translating json into another language
Browse files Browse the repository at this point in the history
test for translating json into another language

✨ New feature
  • Loading branch information
TimMikeladze committed Dec 14, 2022
0 parents commit 6427813
Show file tree
Hide file tree
Showing 22 changed files with 7,649 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"env": {
"es2021": true,
"node": true,
"jest": true
},
"extends": ["standard", "plugin:typescript-sort-keys/recommended"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 13,
"sourceType": "module"
},
"plugins": ["@typescript-eslint"],
"rules": {
"indent": "off",
"space-before-function-paren": "off"
}
}
2 changes: 2 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ko_fi: linesofcodedev
custom: ['https://www.paypal.me/TimMikeladze']
40 changes: 40 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Main CI Workflow

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
steps:
- uses: actions/checkout@v3
name: Use Node.js ${{ matrix.node-version }}

- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- uses: c-hive/gha-yarn-cache@v2

- name: Install
run: yarn install

- name: Type Check
run: yarn tsc

- name: Lint
run: yarn lint

- name: Test
run: yarn test

- name: Build
run: yarn build
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
dist
.idea
yarn-error.log
coverage
.env
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yarn test && yarn lint-staged
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
save-exact = true
8 changes: 8 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
dist
coverage
yarn.lock
.prettierignore
*.snap
.npmrc
.husky/pre-commit
.gitignore
5 changes: 5 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"semi": false,
"singleQuote": true,
"trailingComma": "none"
}
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Tim Mikeladze

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Empty file added README.md
Empty file.
36 changes: 36 additions & 0 deletions __tests__/AIComplete.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { AIComplete } from '../src'

describe('AIComplete', () => {
it('happy path', async () => {
const translator = new AIComplete({
globby: {
patterns: ['__tests__/happy-path/**/*']
},
openAI: {
config: {
apiKey: process.env.OPENAI_API_KEY
},
createCompletionRequest: {
// controls randomness, as value approaches 0 the output will be more deterministic
temperature: 0
}
}
})

await translator.initialize()

const [result] = await translator.aiCompleteFiles({
input: async ({ args, filePath, fileContent }) => ({
prompt:
'Translate the JSON below into Russian but keep names of all keys and metadata in English.'
}),
output: async ({ choices }) => ({
choice: JSON.parse(choices[0].text)
})
})

expect(result).toMatchSnapshot()

expect(typeof result).toBe('object')
})
})
27 changes: 27 additions & 0 deletions __tests__/__snapshots__/AIComplete.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AIComplete happy path 1`] = `
{
"UserManagement": {
"description": "{{ count }} найдено",
"location": "Местоположение",
"name": "Управление пользователями",
"searchToolbarRenderer": {
"inviteLink": {
"label": "Пригласить ссылку",
"tooltip": "",
},
"locations": {
"label": "Местоположения",
"tooltip": "",
},
"roles": {
"label": "Роли",
"tooltip": "",
},
},
"upload": "Загрузить CSV",
"user": "Пользователь",
},
}
`;
23 changes: 23 additions & 0 deletions __tests__/happy-path/locales/en/common.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"UserManagement": {
"name": "User management",
"description": "{{ count }} found",
"user": "User",
"location": "Location",
"upload": "Upload CSV",
"searchToolbarRenderer": {
"roles": {
"label": "Roles",
"tooltip": ""
},
"locations": {
"label": "Locations",
"tooltip": ""
},
"inviteLink": {
"label": "Invite link",
"tooltip": ""
}
}
}
}
10 changes: 10 additions & 0 deletions commit.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { GitEmoji } from 'commit-it'

export default {
plugins: [
new GitEmoji({
askForShortDescription: false,
commitBodyRequired: false
})
]
}
19 changes: 19 additions & 0 deletions jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"preset": "ts-jest/presets/default-esm",
"testEnvironment": "node",
"testPathIgnorePatterns": [
"<rootDir>/node_modules/",
"__tests__/migrations/"
],
"setupFiles": ["dotenv/config"],
"testMatch": ["**/?(*.)+(spec|test).[jt]s?(x)"],
"transform": {
"^.+\\.tsx?$": [
"ts-jest",
{
"useESM": true
}
]
},
"testTimeout": 30000
}
84 changes: 84 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"name": "ai-complete",
"version": "0.0.0",
"description": "",
"author": "Tim Mikeladze <tim.mikeladze@gmail.com>",
"keywords": [],
"repository": {
"type": "git",
"url": "https://github.com/TimMikeladze/ai-complete.git"
},
"license": "MIT",
"files": [
"./dist"
],
"source": "src/index.ts",
"types": "dist/index.d.ts",
"type": "module",
"exports": {
"require": "./dist/index.cjs",
"default": "./dist/index.modern.js"
},
"main": "./dist/index.cjs",
"module": "./dist/index.module.js",
"unpkg": "./dist/index.umd.js",
"bin": "./dist/cli.module.js",
"scripts": {
"dev": "microbundle watch src/{index,cli}.ts --target node -f modern",
"build": "rm -rf dist && tsc && microbundle src/{index,cli}.ts --target node",
"lint": "eslint --fix {src,__tests__}/**/*.ts && prettier --write .",
"test": "yarn node --experimental-vm-modules $(yarn bin jest) --coverage --passWithNoTests --forceExit",
"prepublishOnly": "yarn lint && yarn test && yarn build",
"release": "release-it",
"commit": "yarn commit-it"
},
"release-it": {
"git": {
"commitMessage": "🔖 | v${version}"
},
"github": {
"release": true
},
"npm": {
"publish": false
}
},
"lint-staged": {
"*.ts": "eslint --fix",
"*": "prettier --write"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"devDependencies": {
"@types/jest": "29.2.4",
"@types/node": "18.11.13",
"@typescript-eslint/eslint-plugin": "5.46.1",
"@typescript-eslint/parser": "5.46.1",
"commit-it": "0.0.7",
"dotenv": "16.0.3",
"eslint": "8.29.0",
"eslint-config-standard": "17.0.0",
"eslint-plugin-import": "2.26.0",
"eslint-plugin-n": "15.6.0",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-promise": "6.1.1",
"eslint-plugin-typescript-sort-keys": "2.1.0",
"husky": "8.0.2",
"jest": "29.3.1",
"lint-staged": "13.1.0",
"microbundle": "0.15.1",
"prettier": "2.8.1",
"release-it": "15.5.1",
"ts-jest": "29.0.3",
"typescript": "4.9.4"
},
"peerDependencies": {},
"dependencies": {
"commander": "9.4.1",
"globby": "13.1.3",
"openai": "3.1.0"
}
}
13 changes: 13 additions & 0 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": ["config:base"],
"timezone": "America/Los_Angeles",
"schedule": ["on the first day of the month"],
"packageRules": [
{
"matchPackagePatterns": ["*"],
"matchUpdateTypes": ["minor", "patch"],
"groupName": "all non-major dependencies",
"groupSlug": "all-minor-patch"
}
]
}

0 comments on commit 6427813

Please sign in to comment.