only_ever_generator 8.4.6 → 8.4.8
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.
- package/dist/bootstrap/app.d.ts +6 -3
- package/dist/bootstrap/app.d.ts.map +1 -1
- package/dist/bootstrap/app.js +11 -17
- package/dist/bootstrap/app.js.map +1 -1
- package/dist/card_gen/generate_cards.d.ts +2 -3
- package/dist/card_gen/generate_cards.d.ts.map +1 -1
- package/dist/card_gen/generate_cards.js +22 -15
- package/dist/card_gen/generate_cards.js.map +1 -1
- package/dist/constants/prompt_data.d.ts +4 -4
- package/dist/constants/prompt_data.js +302 -302
- package/dist/constants/prompts/card_gen_prompt.js +160 -160
- package/dist/constants/prompts/typology_prompt.js +131 -131
- package/dist/constants/source_data.d.ts +171 -171
- package/dist/constants/source_data.js +973 -973
- package/dist/embedding_generation/local_consolidation.js +104 -104
- package/dist/helper/build_concept_facts_schema.d.ts +42 -42
- package/dist/helper/build_concept_facts_schema.js +44 -44
- package/dist/helper/qdrant_db_methods.d.ts.map +1 -1
- package/dist/helper/schema_helper/build_card_schema.d.ts +1 -9
- package/dist/helper/schema_helper/build_card_schema.d.ts.map +1 -1
- package/dist/helper/schema_helper/build_card_schema.js +47 -50
- package/dist/helper/schema_helper/build_card_schema.js.map +1 -1
- package/dist/helper/schema_helper/build_concept_facts_schema.d.ts +1 -1
- package/dist/helper/schema_helper/build_concept_facts_schema.d.ts.map +1 -1
- package/dist/helper/schema_helper/build_concept_facts_schema.js +20 -5
- package/dist/helper/schema_helper/build_concept_facts_schema.js.map +1 -1
- package/dist/helper/schema_helper/build_summary_schema.d.ts +1 -1
- package/dist/helper/schema_helper/build_summary_schema.d.ts.map +1 -1
- package/dist/helper/schema_helper/build_summary_schema.js +18 -7
- package/dist/helper/schema_helper/build_summary_schema.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/parse/response_format_card.d.ts +176 -176
- package/dist/parse/response_format_card.js +371 -371
- package/dist/parse/response_format_typology.d.ts +1 -1
- package/dist/parse/response_format_typology.js +46 -46
- package/dist/services/get_prompts.d.ts +8 -7
- package/dist/services/get_prompts.d.ts.map +1 -1
- package/dist/services/get_prompts.js +69 -21
- package/dist/services/get_prompts.js.map +1 -1
- package/dist/typology_gen/generate_concept_facts.d.ts +2 -3
- package/dist/typology_gen/generate_concept_facts.d.ts.map +1 -1
- package/dist/typology_gen/generate_concept_facts.js +25 -15
- package/dist/typology_gen/generate_concept_facts.js.map +1 -1
- package/dist/typology_gen/generate_typology.d.ts +2 -1
- package/dist/typology_gen/generate_typology.d.ts.map +1 -1
- package/dist/typology_gen/generate_typology.js +24 -13
- package/dist/typology_gen/generate_typology.js.map +1 -1
- package/dist/typology_gen/summarize.d.ts +2 -3
- package/dist/typology_gen/summarize.d.ts.map +1 -1
- package/dist/typology_gen/summarize.js +24 -13
- package/dist/typology_gen/summarize.js.map +1 -1
- package/package.json +39 -38
- package/src/bootstrap/app.ts +418 -416
- package/src/card_gen/generate_cards.ts +347 -345
- package/src/config.ts +11 -11
- package/src/constants/api_constants.ts +7 -7
- package/src/constants/prompts/card_gen_prompt.ts +164 -164
- package/src/constants/prompts/typology_prompt.ts +139 -139
- package/src/embedding_generation/consolidation/global_consolidation.ts +96 -96
- package/src/embedding_generation/consolidation/local_consolidation.ts +141 -141
- package/src/embedding_generation/consolidation/write_consolidated_data.ts +98 -98
- package/src/embedding_generation/generate_embeddings.ts +42 -42
- package/src/embedding_generation/parse_embedding_response.ts +31 -31
- package/src/enums/card_type_enum.ts +6 -6
- package/src/gap_fill/calculate_gap_fill.ts +50 -50
- package/src/helper/get_id_from_title.ts +33 -33
- package/src/helper/mongo_helper.ts +29 -29
- package/src/helper/openai_helper.ts +20 -20
- package/src/helper/qdrant_db_methods.ts +77 -77
- package/src/helper/schema_helper/build_card_schema.ts +74 -98
- package/src/helper/schema_helper/build_classify_summarize_schema.ts +43 -43
- package/src/helper/schema_helper/build_concept_facts_schema.ts +45 -31
- package/src/helper/schema_helper/build_summary_schema.ts +43 -32
- package/src/index.ts +71 -73
- package/src/logger.ts +65 -65
- package/src/parse/parse_card/parse_cloze_card.ts +146 -146
- package/src/parse/parse_card/parse_flash_cards.ts +42 -42
- package/src/parse/parse_card/parse_match_card.ts +104 -104
- package/src/parse/parse_card/parse_mcq_card.ts +114 -114
- package/src/parse/parse_card_response.ts +197 -197
- package/src/parse/parse_source_content.ts +212 -212
- package/src/services/get_prompts.ts +164 -112
- package/src/services/open_ai_service.ts +89 -89
- package/src/services/qdrant_service.ts +10 -10
- package/src/types/base_param_type.ts +13 -13
- package/src/types/mongo_concept_fact_type.ts +12 -12
- package/src/types/parsed_card_type.ts +39 -39
- package/src/types/raw_card_response_types/generated_card_response_type.ts +59 -59
- package/src/types/source_taxonomy_type.ts +24 -24
- package/src/typology-parsed-response.ts +1932 -1932
- package/src/typology_gen/generate_concept_facts.ts +180 -169
- package/src/typology_gen/generate_typology.ts +203 -189
- package/src/typology_gen/summarize.ts +176 -164
- package/src/utils/distributed_quote_restoration.ts +80 -80
- package/src/utils/generate_args.ts +29 -29
- package/src/utils/parse_openai_response.ts +19 -19
- package/src/utils/sanitize_strings.ts +65 -65
- package/tsconfig.json +16 -16
- package/dist/constants/default_generation_variables.d.ts +0 -3
- package/dist/constants/default_generation_variables.d.ts.map +0 -1
- package/dist/constants/default_generation_variables.js +0 -580
- package/dist/constants/default_generation_variables.js.map +0 -1
- package/dist/services/prompts_test.d.ts +0 -10
- package/dist/services/prompts_test.d.ts.map +0 -1
- package/dist/services/prompts_test.js +0 -227
- package/dist/services/prompts_test.js.map +0 -1
- package/dist/types/generation_variables_schema.d.ts +0 -14
- package/dist/types/generation_variables_schema.d.ts.map +0 -1
- package/dist/types/generation_variables_schema.js +0 -3
- package/dist/types/generation_variables_schema.js.map +0 -1
- package/dist/utils/test.d.ts +0 -2
- package/dist/utils/test.d.ts.map +0 -1
- package/dist/utils/test.js +0 -5
- package/dist/utils/test.js.map +0 -1
- package/src/constants/default_generation_variables.ts +0 -624
- package/src/types/generation_variables_schema.ts +0 -16
|
@@ -1,112 +1,164 @@
|
|
|
1
|
-
import { setUpMongoClient, ObjectId } from "../helper/mongo_helper";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
cloze: "
|
|
20
|
-
flash: "
|
|
21
|
-
match: "
|
|
22
|
-
mcq: "
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
).map((e: any) =>
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
)
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
)
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
1
|
+
import { setUpMongoClient, ObjectId } from "../helper/mongo_helper";
|
|
2
|
+
const typologyDocs = {
|
|
3
|
+
role: "676528fc59c0563f42607add",
|
|
4
|
+
input: "6765298059c0563f42607ade",
|
|
5
|
+
steps: "6765298b59c0563f42607adf",
|
|
6
|
+
schema: "6765299559c0563f42607ae0",
|
|
7
|
+
fields: "676529a259c0563f42607ae1",
|
|
8
|
+
concepts: "676529b759c0563f42607ae2",
|
|
9
|
+
facts: "67652b1659c0563f42607aea",
|
|
10
|
+
generate: "676529c259c0563f42607ae3",
|
|
11
|
+
summarize: "676529d259c0563f42607ae4",
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const cardGenDocs = {
|
|
15
|
+
role: "676526c959c0563f42607ad4",
|
|
16
|
+
inputs: "676526c959c0563f42607ad5",
|
|
17
|
+
steps: "676526c959c0563f42607ad6",
|
|
18
|
+
schema: "676526c959c0563f42607ad7",
|
|
19
|
+
cloze: "6765270859c0563f42607ad8",
|
|
20
|
+
flash: "6765274159c0563f42607ad9",
|
|
21
|
+
match: "6765276959c0563f42607adb",
|
|
22
|
+
mcq: "6765275f59c0563f42607ada",
|
|
23
|
+
coverage: "6765277a59c0563f42607adc",
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const videoTypologyDocs = {
|
|
27
|
+
role: "676529e259c0563f42607ae5",
|
|
28
|
+
inputs: "676529f059c0563f42607ae6",
|
|
29
|
+
steps: "6765298b59c0563f42607adf",
|
|
30
|
+
schema: "67652a2559c0563f42607ae7",
|
|
31
|
+
fields: "676529a259c0563f42607ae1",
|
|
32
|
+
concepts: "67652a3459c0563f42607ae8",
|
|
33
|
+
facts: "67652a4459c0563f42607ae9",
|
|
34
|
+
generate: "676529c259c0563f42607ae3",
|
|
35
|
+
summarize: "676529d259c0563f42607ae4",
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const cardGenInstructionsDocs = {
|
|
39
|
+
cloze: "6780d21318f81be17e39f5c1",
|
|
40
|
+
flash: "6780d21318f81be17e39f5d2",
|
|
41
|
+
match: "6780d21318f81be17e39f5d3",
|
|
42
|
+
mcq: "6780d21318f81be17e39f5d4",
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const cardGenExamplesDocs = {
|
|
46
|
+
cloze: "688af4e5299b7c2c08a52fbe",
|
|
47
|
+
flash: "688af4e5299b7c2c08a52fcd",
|
|
48
|
+
match: "688af4e5299b7c2c08a52fce",
|
|
49
|
+
mcq: "688af4e5299b7c2c08a52fde",
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const bloomInstructionsDocs = {
|
|
53
|
+
bloom_1: "6780d21318f81be17e39f5b5",
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export const getPrompts = async (
|
|
57
|
+
sourceType: string,
|
|
58
|
+
cardGenerationType: string[]
|
|
59
|
+
) => {
|
|
60
|
+
// const typologyDocs = JSON.parse(baseConfig.typologyPrompts);
|
|
61
|
+
// const cardGenerationDocs = JSON.parse(baseConfig.cardGenerationPrompts);
|
|
62
|
+
// const videoTypologyDocs = JSON.parse(baseConfig.videoTypologyPrompts);
|
|
63
|
+
const typologyObjectIds = Object.values(typologyDocs).map((e: any) =>
|
|
64
|
+
ObjectId.createFromHexString(e.toString())
|
|
65
|
+
);
|
|
66
|
+
const cardGenObjectIds = Object.values(cardGenDocs).map((e: any) =>
|
|
67
|
+
ObjectId.createFromHexString(e)
|
|
68
|
+
);
|
|
69
|
+
const typologyVideoObjectIds = Object.values(videoTypologyDocs).map(
|
|
70
|
+
(e: any) => ObjectId.createFromHexString(e)
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
// Filter card generation instructions and examples based on cardGenerationType array
|
|
74
|
+
const filteredCardGenInstructions: Record<string, string> = {};
|
|
75
|
+
const filteredCardGenExamples: Record<string, string> = {};
|
|
76
|
+
|
|
77
|
+
cardGenerationType.forEach((type) => {
|
|
78
|
+
if (cardGenInstructionsDocs[type as keyof typeof cardGenInstructionsDocs]) {
|
|
79
|
+
filteredCardGenInstructions[type] =
|
|
80
|
+
cardGenInstructionsDocs[type as keyof typeof cardGenInstructionsDocs];
|
|
81
|
+
}
|
|
82
|
+
if (cardGenExamplesDocs[type as keyof typeof cardGenExamplesDocs]) {
|
|
83
|
+
filteredCardGenExamples[type] =
|
|
84
|
+
cardGenExamplesDocs[type as keyof typeof cardGenExamplesDocs];
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const cardGenInstructionsObjectIds = Object.values(
|
|
89
|
+
filteredCardGenInstructions
|
|
90
|
+
).map((e: any) => ObjectId.createFromHexString(e));
|
|
91
|
+
const cardGenExamplesObjectIds = Object.values(filteredCardGenExamples).map(
|
|
92
|
+
(e: any) => ObjectId.createFromHexString(e)
|
|
93
|
+
);
|
|
94
|
+
const bloomInstructionsObjectIds = Object.values(bloomInstructionsDocs).map(
|
|
95
|
+
(e: any) => ObjectId.createFromHexString(e)
|
|
96
|
+
);
|
|
97
|
+
const typology = await getPromptString(typologyObjectIds);
|
|
98
|
+
const card_generation = await getPromptString(cardGenObjectIds);
|
|
99
|
+
const video_typology = await getPromptString(typologyVideoObjectIds);
|
|
100
|
+
const cardInstructions = await getPromptString(cardGenInstructionsObjectIds);
|
|
101
|
+
const cardExamples = await getPromptString(cardGenExamplesObjectIds);
|
|
102
|
+
const bloomInstructions = await getPromptString(bloomInstructionsObjectIds);
|
|
103
|
+
if (sourceType === "video") {
|
|
104
|
+
return {
|
|
105
|
+
typology: {
|
|
106
|
+
prompt: video_typology,
|
|
107
|
+
ids: Object.values(videoTypologyDocs),
|
|
108
|
+
},
|
|
109
|
+
card_gen: {
|
|
110
|
+
prompt: card_generation,
|
|
111
|
+
ids: Object.values(cardGenDocs),
|
|
112
|
+
},
|
|
113
|
+
card_instructions: cardInstructions,
|
|
114
|
+
card_examples: cardExamples,
|
|
115
|
+
bloom_instructions: bloomInstructions,
|
|
116
|
+
};
|
|
117
|
+
} else {
|
|
118
|
+
return {
|
|
119
|
+
typology: {
|
|
120
|
+
prompt: typology,
|
|
121
|
+
ids: Object.values(typologyDocs),
|
|
122
|
+
},
|
|
123
|
+
card_gen: {
|
|
124
|
+
prompt: card_generation,
|
|
125
|
+
ids: Object.values(cardGenDocs),
|
|
126
|
+
},
|
|
127
|
+
card_instructions: cardInstructions,
|
|
128
|
+
card_examples: cardExamples,
|
|
129
|
+
bloom_instructions: bloomInstructions,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
async function getPromptString(promptIds: ObjectId[]) {
|
|
133
|
+
const database = await setUpMongoClient();
|
|
134
|
+
let result = await database
|
|
135
|
+
.collection("_prompts")
|
|
136
|
+
.aggregate([
|
|
137
|
+
{
|
|
138
|
+
$match: {
|
|
139
|
+
_id: { $in: promptIds },
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
$group: {
|
|
144
|
+
_id: null,
|
|
145
|
+
allContent: { $push: "$prompt" },
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
/// concat each element in above created `allContent temp field`, and update that to "concatenatedContent"(temp field)
|
|
150
|
+
$project: {
|
|
151
|
+
concatenatedContent: {
|
|
152
|
+
$reduce: {
|
|
153
|
+
input: "$allContent",
|
|
154
|
+
initialValue: "",
|
|
155
|
+
in: { $concat: ["$$value", "$$this"] },
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
])
|
|
161
|
+
.toArray();
|
|
162
|
+
return result.length > 0 ? result[0].concatenatedContent : "";
|
|
163
|
+
}
|
|
164
|
+
};
|
|
@@ -1,89 +1,89 @@
|
|
|
1
|
-
import axios from "axios";
|
|
2
|
-
import {
|
|
3
|
-
parseOpenAiFailureResponse,
|
|
4
|
-
parseOpenAiSuccessResponse,
|
|
5
|
-
} from "../utils/parse_openai_response";
|
|
6
|
-
import {
|
|
7
|
-
openAiEmbeddingEndPoint,
|
|
8
|
-
openAiEndPoint,
|
|
9
|
-
} from "../constants/api_constants";
|
|
10
|
-
|
|
11
|
-
export class OpenAiService {
|
|
12
|
-
public api_key: string;
|
|
13
|
-
public model: string;
|
|
14
|
-
|
|
15
|
-
constructor(apiKey: string, model: string) {
|
|
16
|
-
this.api_key = apiKey;
|
|
17
|
-
this.model = model;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
async sendRequest(prompt: string, content: string) {
|
|
21
|
-
try {
|
|
22
|
-
let message = [
|
|
23
|
-
{
|
|
24
|
-
role: "system",
|
|
25
|
-
content: prompt,
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
role: "user",
|
|
29
|
-
content: content,
|
|
30
|
-
},
|
|
31
|
-
];
|
|
32
|
-
const url = openAiEndPoint();
|
|
33
|
-
let response = await axios.post(
|
|
34
|
-
url,
|
|
35
|
-
{
|
|
36
|
-
model: this.model,
|
|
37
|
-
messages: message,
|
|
38
|
-
response_format: { type: "json_object" },
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
headers: {
|
|
42
|
-
Authorization: "Bearer " + this.api_key,
|
|
43
|
-
"Content-Type": ["application/json"],
|
|
44
|
-
},
|
|
45
|
-
}
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
if (response.status == 200) {
|
|
49
|
-
console.log("success");
|
|
50
|
-
return parseOpenAiSuccessResponse(response.data) as any;
|
|
51
|
-
} else {
|
|
52
|
-
console.log("failed");
|
|
53
|
-
return response.statusText as any;
|
|
54
|
-
}
|
|
55
|
-
} catch (err: any) {
|
|
56
|
-
return parseOpenAiFailureResponse(err.response);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
async sendEmbeddingRequest(texts: string[]) {
|
|
61
|
-
try {
|
|
62
|
-
const url = openAiEmbeddingEndPoint();
|
|
63
|
-
let response = await axios.post(
|
|
64
|
-
url,
|
|
65
|
-
{
|
|
66
|
-
model: "text-embedding-3-large",
|
|
67
|
-
input: texts,
|
|
68
|
-
dimensions: 512,
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
headers: {
|
|
72
|
-
Authorization: "Bearer " + this.api_key,
|
|
73
|
-
"Content-Type": ["application/json"],
|
|
74
|
-
},
|
|
75
|
-
}
|
|
76
|
-
);
|
|
77
|
-
return {
|
|
78
|
-
status_code: 200,
|
|
79
|
-
data: response.data,
|
|
80
|
-
};
|
|
81
|
-
} catch (err: any) {
|
|
82
|
-
console.log(err);
|
|
83
|
-
return {
|
|
84
|
-
status_code: err.response.status ?? 500,
|
|
85
|
-
message: err.message,
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import {
|
|
3
|
+
parseOpenAiFailureResponse,
|
|
4
|
+
parseOpenAiSuccessResponse,
|
|
5
|
+
} from "../utils/parse_openai_response";
|
|
6
|
+
import {
|
|
7
|
+
openAiEmbeddingEndPoint,
|
|
8
|
+
openAiEndPoint,
|
|
9
|
+
} from "../constants/api_constants";
|
|
10
|
+
|
|
11
|
+
export class OpenAiService {
|
|
12
|
+
public api_key: string;
|
|
13
|
+
public model: string;
|
|
14
|
+
|
|
15
|
+
constructor(apiKey: string, model: string) {
|
|
16
|
+
this.api_key = apiKey;
|
|
17
|
+
this.model = model;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async sendRequest(prompt: string, content: string) {
|
|
21
|
+
try {
|
|
22
|
+
let message = [
|
|
23
|
+
{
|
|
24
|
+
role: "system",
|
|
25
|
+
content: prompt,
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
role: "user",
|
|
29
|
+
content: content,
|
|
30
|
+
},
|
|
31
|
+
];
|
|
32
|
+
const url = openAiEndPoint();
|
|
33
|
+
let response = await axios.post(
|
|
34
|
+
url,
|
|
35
|
+
{
|
|
36
|
+
model: this.model,
|
|
37
|
+
messages: message,
|
|
38
|
+
response_format: { type: "json_object" },
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
headers: {
|
|
42
|
+
Authorization: "Bearer " + this.api_key,
|
|
43
|
+
"Content-Type": ["application/json"],
|
|
44
|
+
},
|
|
45
|
+
}
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
if (response.status == 200) {
|
|
49
|
+
console.log("success");
|
|
50
|
+
return parseOpenAiSuccessResponse(response.data) as any;
|
|
51
|
+
} else {
|
|
52
|
+
console.log("failed");
|
|
53
|
+
return response.statusText as any;
|
|
54
|
+
}
|
|
55
|
+
} catch (err: any) {
|
|
56
|
+
return parseOpenAiFailureResponse(err.response);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async sendEmbeddingRequest(texts: string[]) {
|
|
61
|
+
try {
|
|
62
|
+
const url = openAiEmbeddingEndPoint();
|
|
63
|
+
let response = await axios.post(
|
|
64
|
+
url,
|
|
65
|
+
{
|
|
66
|
+
model: "text-embedding-3-large",
|
|
67
|
+
input: texts,
|
|
68
|
+
dimensions: 512,
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
headers: {
|
|
72
|
+
Authorization: "Bearer " + this.api_key,
|
|
73
|
+
"Content-Type": ["application/json"],
|
|
74
|
+
},
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
return {
|
|
78
|
+
status_code: 200,
|
|
79
|
+
data: response.data,
|
|
80
|
+
};
|
|
81
|
+
} catch (err: any) {
|
|
82
|
+
console.log(err);
|
|
83
|
+
return {
|
|
84
|
+
status_code: err.response.status ?? 500,
|
|
85
|
+
message: err.message,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { QdrantClient } from "@qdrant/js-client-rest";
|
|
2
|
-
import config from "../config";
|
|
3
|
-
|
|
4
|
-
// or connect to Qdrant Cloud
|
|
5
|
-
const qdrantClient = new QdrantClient({
|
|
6
|
-
url: config.qdrantUrl,
|
|
7
|
-
apiKey: config.qdrantApiKey,
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
export default qdrantClient;
|
|
1
|
+
import { QdrantClient } from "@qdrant/js-client-rest";
|
|
2
|
+
import config from "../config";
|
|
3
|
+
|
|
4
|
+
// or connect to Qdrant Cloud
|
|
5
|
+
const qdrantClient = new QdrantClient({
|
|
6
|
+
url: config.qdrantUrl,
|
|
7
|
+
apiKey: config.qdrantApiKey,
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
export default qdrantClient;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { SourceTaxonomy } from "./source_taxonomy_type";
|
|
2
|
-
|
|
3
|
-
export type BaseParamType = {
|
|
4
|
-
content: {
|
|
5
|
-
source_id: string;
|
|
6
|
-
title: string;
|
|
7
|
-
headings: string[];
|
|
8
|
-
content: any[];
|
|
9
|
-
fields: string[];
|
|
10
|
-
taxonomy?: SourceTaxonomy;
|
|
11
|
-
type: string;
|
|
12
|
-
};
|
|
13
|
-
};
|
|
1
|
+
import { SourceTaxonomy } from "./source_taxonomy_type";
|
|
2
|
+
|
|
3
|
+
export type BaseParamType = {
|
|
4
|
+
content: {
|
|
5
|
+
source_id: string;
|
|
6
|
+
title: string;
|
|
7
|
+
headings: string[];
|
|
8
|
+
content: any[];
|
|
9
|
+
fields: string[];
|
|
10
|
+
taxonomy?: SourceTaxonomy;
|
|
11
|
+
type: string;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export type MongoConceptFactSource = {
|
|
2
|
-
text: string;
|
|
3
|
-
type: "concept" | "fact";
|
|
4
|
-
reference: string;
|
|
5
|
-
id: string;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export type MongoConceptFactCards = {
|
|
9
|
-
text: string;
|
|
10
|
-
type: "concept" | "fact";
|
|
11
|
-
id: string;
|
|
12
|
-
};
|
|
1
|
+
export type MongoConceptFactSource = {
|
|
2
|
+
text: string;
|
|
3
|
+
type: "concept" | "fact";
|
|
4
|
+
reference: string;
|
|
5
|
+
id: string;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type MongoConceptFactCards = {
|
|
9
|
+
text: string;
|
|
10
|
+
type: "concept" | "fact";
|
|
11
|
+
id: string;
|
|
12
|
+
};
|
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
export type ParsedCardType = {
|
|
2
|
-
type: {
|
|
3
|
-
category: string;
|
|
4
|
-
sub_type: string;
|
|
5
|
-
};
|
|
6
|
-
heading: string;
|
|
7
|
-
displayTitle: string;
|
|
8
|
-
content: any;
|
|
9
|
-
explanation?: string;
|
|
10
|
-
bloom_level?: number;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
// {
|
|
14
|
-
// "type": {
|
|
15
|
-
// "category": "learning",
|
|
16
|
-
// "sub_type": "cloze"
|
|
17
|
-
// },
|
|
18
|
-
// "heading": "",
|
|
19
|
-
// "displayTitle": "Ink is a medium that consists of colorants and other {{components}}. ---- components, elements, substances",
|
|
20
|
-
// "content": {
|
|
21
|
-
// "question": "Ink is a medium that consists of colorants and other {{c0:components}}.",
|
|
22
|
-
// "options": [
|
|
23
|
-
// {
|
|
24
|
-
// "option": "components",
|
|
25
|
-
// "cloze": "c0"
|
|
26
|
-
// },
|
|
27
|
-
// {
|
|
28
|
-
// "option": "elements",
|
|
29
|
-
// "cloze": "null"
|
|
30
|
-
// },
|
|
31
|
-
// {
|
|
32
|
-
// "option": "substances",
|
|
33
|
-
// "cloze": "null"
|
|
34
|
-
// }
|
|
35
|
-
// ]
|
|
36
|
-
// },
|
|
37
|
-
// "explanation": "Ink contains various components that include colorants, solvents, and additives which determine its properties.",
|
|
38
|
-
// "bloom_level": 1
|
|
39
|
-
// },
|
|
1
|
+
export type ParsedCardType = {
|
|
2
|
+
type: {
|
|
3
|
+
category: string;
|
|
4
|
+
sub_type: string;
|
|
5
|
+
};
|
|
6
|
+
heading: string;
|
|
7
|
+
displayTitle: string;
|
|
8
|
+
content: any;
|
|
9
|
+
explanation?: string;
|
|
10
|
+
bloom_level?: number;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// {
|
|
14
|
+
// "type": {
|
|
15
|
+
// "category": "learning",
|
|
16
|
+
// "sub_type": "cloze"
|
|
17
|
+
// },
|
|
18
|
+
// "heading": "",
|
|
19
|
+
// "displayTitle": "Ink is a medium that consists of colorants and other {{components}}. ---- components, elements, substances",
|
|
20
|
+
// "content": {
|
|
21
|
+
// "question": "Ink is a medium that consists of colorants and other {{c0:components}}.",
|
|
22
|
+
// "options": [
|
|
23
|
+
// {
|
|
24
|
+
// "option": "components",
|
|
25
|
+
// "cloze": "c0"
|
|
26
|
+
// },
|
|
27
|
+
// {
|
|
28
|
+
// "option": "elements",
|
|
29
|
+
// "cloze": "null"
|
|
30
|
+
// },
|
|
31
|
+
// {
|
|
32
|
+
// "option": "substances",
|
|
33
|
+
// "cloze": "null"
|
|
34
|
+
// }
|
|
35
|
+
// ]
|
|
36
|
+
// },
|
|
37
|
+
// "explanation": "Ink contains various components that include colorants, solvents, and additives which determine its properties.",
|
|
38
|
+
// "bloom_level": 1
|
|
39
|
+
// },
|