ai-compare-candidates 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/.editorconfig +51 -0
  2. package/.vscode/settings.json +3 -0
  3. package/.yarnrc.yml +16 -0
  4. package/LICENSE +6 -0
  5. package/README.md +77 -0
  6. package/dist/index.cjs +24 -0
  7. package/dist/index.cjs.map +1 -0
  8. package/dist/index.d.cts +134 -0
  9. package/dist/index.d.cts.map +1 -0
  10. package/dist/index.d.mts +134 -0
  11. package/dist/index.d.mts.map +1 -0
  12. package/dist/index.mjs +24 -0
  13. package/dist/index.mjs.map +1 -0
  14. package/example/.editorconfig +51 -0
  15. package/example/.vscode/extensions.json +13 -0
  16. package/example/.vscode/settings.json +5 -0
  17. package/example/README.md +21 -0
  18. package/example/index.html +21 -0
  19. package/example/package.json +37 -0
  20. package/example/postcss.config.js +29 -0
  21. package/example/public/favicon.ico +0 -0
  22. package/example/public/icons/favicon-128x128.png +0 -0
  23. package/example/public/icons/favicon-16x16.png +0 -0
  24. package/example/public/icons/favicon-32x32.png +0 -0
  25. package/example/public/icons/favicon-96x96.png +0 -0
  26. package/example/quasar.config.ts +222 -0
  27. package/example/src/App.vue +5 -0
  28. package/example/src/boot/electronHuggingFaceFix.ts +8 -0
  29. package/example/src/boot/icons.ts +20 -0
  30. package/example/src/css/app.scss +1 -0
  31. package/example/src/css/quasar.variables.scss +25 -0
  32. package/example/src/env.d.ts +7 -0
  33. package/example/src/layouts/app.vue +147 -0
  34. package/example/src/router/index.ts +37 -0
  35. package/example/src/router/routes.ts +8 -0
  36. package/example/src/stores/index.ts +32 -0
  37. package/example/src/stores/store.ts +19 -0
  38. package/example/tsconfig.json +3 -0
  39. package/package.json +55 -0
  40. package/src/index.ts +478 -0
  41. package/tsconfig.json +12 -0
  42. package/tsconfig.node.json +12 -0
  43. package/tsconfig.tsbuildinfo +1 -0
  44. package/tsdown.config.ts +12 -0
@@ -0,0 +1,147 @@
1
+ <template>
2
+ <q-layout view="lHh Lpr lFf">
3
+ <q-header elevated>
4
+ <q-toolbar>
5
+ <q-toolbar-title>
6
+ AI Compare Candidates Example
7
+ </q-toolbar-title>
8
+ </q-toolbar>
9
+ </q-header>
10
+ <q-page-container>
11
+ <q-page>
12
+ <q-virtual-scroll :items="candidates">
13
+ <template #default="{item,index}:{item:Candidate,index:number}">
14
+ <q-item>
15
+ <q-item-section side>
16
+ <q-item-label>{{index+1}}.</q-item-label>
17
+ </q-item-section>
18
+ <q-item-section>
19
+ <q-input label="Name" v-model="item.name"/>
20
+ </q-item-section>
21
+ <q-item-section side>
22
+ <q-btn no-caps icon="fas fa-trash-can" label="Remove Candidate" @click="removeCandidate(index)"/>
23
+ </q-item-section>
24
+ </q-item>
25
+ </template>
26
+ </q-virtual-scroll>
27
+ <q-list>
28
+ <q-item>
29
+ <q-item-section>
30
+ <q-input autogrow label="Artificial Intelligence Problem Description Prompt" v-model="problemDescription"/>
31
+ </q-item-section>
32
+ </q-item>
33
+ <q-item>
34
+ <q-item-section>
35
+ <q-input label="Candidates for Initial Selection" type="number" v-model.number="candidatesForInitialSelection"/>
36
+ </q-item-section>
37
+ </q-item>
38
+ <q-item>
39
+ <q-item-section>
40
+ <q-input label="Candidates for Final Selection" type="number" v-model.number="candidatesForFinalSelection"/>
41
+ </q-item-section>
42
+ </q-item>
43
+ <q-item>
44
+ <q-item-section>
45
+ <q-btn no-caps icon="fas fa-plus" label="Add Candidate" @click="addCandidate"/>
46
+ </q-item-section>
47
+ <q-item-section>
48
+ <q-btn no-caps icon="fas fa-brain" label="Artificial Intelligence" @click="artificialIntelligence"/>
49
+ </q-item-section>
50
+ </q-item>
51
+ <q-item>
52
+ <q-item-section>
53
+ <q-item-label>Rationale:</q-item-label>
54
+ <q-item-label>{{outcome.rationale}}</q-item-label>
55
+ </q-item-section>
56
+ </q-item>
57
+ </q-list>
58
+ <q-virtual-scroll :items="outcome.selectedCandidates">
59
+ <template #before>
60
+ <q-item>
61
+ <q-item-section>
62
+ <q-item-label>Selected Candidates:</q-item-label>
63
+ </q-item-section>
64
+ </q-item>
65
+ </template>
66
+ <template #default="{item,index}:{item:Candidate,index:number}">
67
+ <q-item>
68
+ <q-item-section side>
69
+ <q-item-label>{{index+1}}.</q-item-label>
70
+ </q-item-section>
71
+ <q-item-section>
72
+ <q-item-label>{{item.name}}</q-item-label>
73
+ </q-item-section>
74
+ </q-item>
75
+ </template>
76
+ </q-virtual-scroll>
77
+ </q-page>
78
+ </q-page-container>
79
+ </q-layout>
80
+ </template>
81
+
82
+ <script setup lang="ts">
83
+ import{
84
+ nextTick,
85
+ ref,
86
+ watch
87
+ }from 'vue';
88
+ import{
89
+ Dialog,
90
+ Loading
91
+ }from 'quasar';
92
+ import jsan from 'jsan';
93
+ import lodash from 'lodash';
94
+ import useStore from '../stores/store';
95
+ import type AICompareCandidates from 'ai-compare-candidates';
96
+
97
+ interface Candidate{
98
+ name:string;
99
+ }
100
+
101
+ const store=useStore();
102
+
103
+ const candidates=ref<Candidate[]>([{name:'Testing 1'},{name:'Testing 2'}]);
104
+ const problemDescription=ref('Pick the best name');
105
+ const candidatesForInitialSelection=ref(2);
106
+ const candidatesForFinalSelection=ref(1);
107
+ const outcome=ref<AICompareCandidates.CompareCandidatesReturn<Candidate>>({
108
+ selectedCandidates:[],
109
+ rationale:''
110
+ });
111
+
112
+ watch(candidatesForInitialSelection,value=>nextTick(()=>candidatesForInitialSelection.value=lodash.clamp(value,Math.max(candidatesForFinalSelection.value,1),candidates.value.length)));
113
+ watch(candidatesForFinalSelection,value=>nextTick(()=>candidatesForFinalSelection.value=lodash.clamp(value,1,Math.min(candidatesForInitialSelection.value,candidates.value.length))));
114
+
115
+ function removeCandidate(index:number){
116
+ if(candidates.value.length<=2){
117
+ Dialog.create({message:'There must be at least 2 candidates to compare'});
118
+ return;
119
+ }
120
+ candidates.value.splice(index,1);
121
+ }
122
+
123
+ function addCandidate(){
124
+ candidates.value.push({name:''});
125
+ }
126
+
127
+ function errorMessage(error:any){
128
+ return typeof error?.response?.data==='string'?error.response.data:error?.response?.data?jsan.stringify(error.response.data):typeof error?.message==='string'?error.message:error?.message?jsan.stringify(error.message):typeof error==='string'?error:jsan.stringify(error);
129
+ }
130
+
131
+ async function artificialIntelligence(){
132
+ try{
133
+ Loading.show();
134
+ outcome.value=(await store.aiCompareCandidates.compareCandidates({
135
+ candidates:candidates.value,
136
+ problemDescription:problemDescription.value,
137
+ candidatesForInitialSelection:candidatesForInitialSelection.value,
138
+ candidatesForFinalSelection:candidatesForFinalSelection.value
139
+ })) as AICompareCandidates.CompareCandidatesReturn<Candidate>;
140
+ }catch(error){
141
+ console.log(error);
142
+ Dialog.create({message:errorMessage(error)});
143
+ }finally{
144
+ Loading.hide();
145
+ }
146
+ }
147
+ </script>
@@ -0,0 +1,37 @@
1
+ import {defineRouter} from '#q-app/wrappers';
2
+ import{
3
+ createMemoryHistory,
4
+ createRouter,
5
+ createWebHashHistory,
6
+ createWebHistory,
7
+ }from 'vue-router';
8
+ import routes from './routes';
9
+
10
+ /*
11
+ * If not building with SSR mode, you can
12
+ * directly export the Router instantiation;
13
+ *
14
+ * The function below can be async too; either use
15
+ * async/await or return a Promise which resolves
16
+ * with the Router instance.
17
+ */
18
+
19
+ export default defineRouter(function(/* { store, ssrContext } */){
20
+ const createHistory=process.env.SERVER||process.env.VUE_ROUTER_MODE==='abstract'?
21
+ createMemoryHistory:
22
+ (process.env.VUE_ROUTER_MODE==='history'?createWebHistory:createWebHashHistory);
23
+
24
+ const Router=createRouter({
25
+ scrollBehavior:()=>({
26
+ left:0,
27
+ top:0
28
+ }),
29
+ routes,
30
+ // Leave this as is and make changes in quasar.conf.js instead!
31
+ // quasar.conf.js -> build -> vueRouterMode
32
+ // quasar.conf.js -> build -> publicPath
33
+ history:createHistory(process.env.VUE_ROUTER_BASE),
34
+ });
35
+
36
+ return Router;
37
+ });
@@ -0,0 +1,8 @@
1
+ import type {RouteRecordRaw} from 'vue-router';
2
+
3
+ const routes:RouteRecordRaw[]=[{
4
+ path:'/:catchAll(.*)*',
5
+ component:()=>import('layouts/app.vue')
6
+ }];
7
+
8
+ export default routes;
@@ -0,0 +1,32 @@
1
+ import { defineStore } from '#q-app/wrappers'
2
+ import { createPinia } from 'pinia'
3
+
4
+ /*
5
+ * When adding new properties to stores, you should also
6
+ * extend the `PiniaCustomProperties` interface.
7
+ * @see https://pinia.vuejs.org/core-concepts/plugins.html#typing-new-store-properties
8
+ */
9
+ declare module 'pinia' {
10
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type
11
+ export interface PiniaCustomProperties {
12
+ // add your custom properties here, if any
13
+ }
14
+ }
15
+
16
+ /*
17
+ * If not building with SSR mode, you can
18
+ * directly export the Store instantiation;
19
+ *
20
+ * The function below can be async too; either use
21
+ * async/await or return a Promise which resolves
22
+ * with the Store instance.
23
+ */
24
+
25
+ export default defineStore((/* { ssrContext } */) => {
26
+ const pinia = createPinia()
27
+
28
+ // You can add Pinia plugins here
29
+ // pinia.use(SomePiniaPlugin)
30
+
31
+ return pinia
32
+ })
@@ -0,0 +1,19 @@
1
+ import{
2
+ defineStore,
3
+ acceptHMRUpdate
4
+ }from 'pinia';
5
+ import {shallowRef} from 'vue';
6
+ import AICompareCandidates from 'ai-compare-candidates';
7
+
8
+ export const useStore=defineStore('store',()=>{
9
+ const aiCompareCandidates=shallowRef(new AICompareCandidates());
10
+ return{
11
+ aiCompareCandidates
12
+ };
13
+ });
14
+
15
+ export default useStore;
16
+
17
+ if(import.meta.hot){
18
+ import.meta.hot.accept(acceptHMRUpdate(useStore, import.meta.hot));
19
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "extends": "./.quasar/tsconfig.json"
3
+ }
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "ai-compare-candidates",
3
+ "version": "0.0.1",
4
+ "description": "Compare and rank multiple candidate objects using artificial intelligence retrieval augmented generation, providing the rationale",
5
+ "main": "dist/index.mjs",
6
+ "scripts": {
7
+ "build": "tsc --noEmit && tsdown --config tsdown.config.ts"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/customautosys/ai-compare-candidates.git"
12
+ },
13
+ "keywords": [
14
+ "artificial",
15
+ "intelligence",
16
+ "candidates",
17
+ "compare",
18
+ "retrieval",
19
+ "augmented",
20
+ "generation"
21
+ ],
22
+ "author": "Wilson Foo Yu Kang",
23
+ "license": "CC-BY-NC-SA-4.0",
24
+ "bugs": {
25
+ "url": "https://github.com/customautosys/ai-compare-candidates/issues"
26
+ },
27
+ "homepage": "https://github.com/customautosys/ai-compare-candidates#readme",
28
+ "packageManager": "yarn@4.12.0",
29
+ "dependencies": {
30
+ "@huggingface/transformers": "^3.8.1",
31
+ "@langchain/classic": "^1.0.6",
32
+ "@langchain/core": "^1.1.5",
33
+ "jsan": "^3.1.14",
34
+ "lodash": "^4.17.21"
35
+ },
36
+ "devDependencies": {
37
+ "@types/jsan": "^3",
38
+ "@types/lodash": "^4",
39
+ "tsdown": "^0.17.3",
40
+ "typescript": "^5.9.3"
41
+ },
42
+ "workspaces": [
43
+ "example"
44
+ ],
45
+ "exports": {
46
+ "import": {
47
+ "types": "./dist/index.d.mts",
48
+ "default": "./dist/index.mjs"
49
+ },
50
+ "require": {
51
+ "types": "./dist/index.d.cts",
52
+ "default": "./dist/index.cjs"
53
+ }
54
+ }
55
+ }