@ha-bits/bit-intersect 0.1.0

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 (58) hide show
  1. package/README.md +41 -0
  2. package/dist/index.d.ts +12 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +72 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/lib/actions/ask-assistant.d.ts +6 -0
  7. package/dist/lib/actions/ask-assistant.d.ts.map +1 -0
  8. package/dist/lib/actions/ask-assistant.js +121 -0
  9. package/dist/lib/actions/ask-assistant.js.map +1 -0
  10. package/dist/lib/actions/create-canvas.d.ts +6 -0
  11. package/dist/lib/actions/create-canvas.d.ts.map +1 -0
  12. package/dist/lib/actions/create-canvas.js +127 -0
  13. package/dist/lib/actions/create-canvas.js.map +1 -0
  14. package/dist/lib/actions/create-video.d.ts +6 -0
  15. package/dist/lib/actions/create-video.d.ts.map +1 -0
  16. package/dist/lib/actions/create-video.js +46 -0
  17. package/dist/lib/actions/create-video.js.map +1 -0
  18. package/dist/lib/actions/extract-structure-data.action.d.ts +6 -0
  19. package/dist/lib/actions/extract-structure-data.action.d.ts.map +1 -0
  20. package/dist/lib/actions/extract-structure-data.action.js +151 -0
  21. package/dist/lib/actions/extract-structure-data.action.js.map +1 -0
  22. package/dist/lib/actions/generate-image.d.ts +6 -0
  23. package/dist/lib/actions/generate-image.d.ts.map +1 -0
  24. package/dist/lib/actions/generate-image.js +140 -0
  25. package/dist/lib/actions/generate-image.js.map +1 -0
  26. package/dist/lib/actions/index.d.ts +16 -0
  27. package/dist/lib/actions/index.d.ts.map +1 -0
  28. package/dist/lib/actions/index.js +30 -0
  29. package/dist/lib/actions/index.js.map +1 -0
  30. package/dist/lib/actions/send-prompt.d.ts +6 -0
  31. package/dist/lib/actions/send-prompt.d.ts.map +1 -0
  32. package/dist/lib/actions/send-prompt.js +187 -0
  33. package/dist/lib/actions/send-prompt.js.map +1 -0
  34. package/dist/lib/actions/text-to-speech.d.ts +6 -0
  35. package/dist/lib/actions/text-to-speech.d.ts.map +1 -0
  36. package/dist/lib/actions/text-to-speech.js +111 -0
  37. package/dist/lib/actions/text-to-speech.js.map +1 -0
  38. package/dist/lib/actions/text-to-voice.d.ts +6 -0
  39. package/dist/lib/actions/text-to-voice.d.ts.map +1 -0
  40. package/dist/lib/actions/text-to-voice.js +124 -0
  41. package/dist/lib/actions/text-to-voice.js.map +1 -0
  42. package/dist/lib/actions/transcriptions.d.ts +6 -0
  43. package/dist/lib/actions/transcriptions.d.ts.map +1 -0
  44. package/dist/lib/actions/transcriptions.js +74 -0
  45. package/dist/lib/actions/transcriptions.js.map +1 -0
  46. package/dist/lib/actions/translation.d.ts +6 -0
  47. package/dist/lib/actions/translation.d.ts.map +1 -0
  48. package/dist/lib/actions/translation.js +59 -0
  49. package/dist/lib/actions/translation.js.map +1 -0
  50. package/dist/lib/actions/vision-prompt.d.ts +6 -0
  51. package/dist/lib/actions/vision-prompt.d.ts.map +1 -0
  52. package/dist/lib/actions/vision-prompt.js +147 -0
  53. package/dist/lib/actions/vision-prompt.js.map +1 -0
  54. package/dist/lib/common/common.d.ts +49 -0
  55. package/dist/lib/common/common.d.ts.map +1 -0
  56. package/dist/lib/common/common.js +295 -0
  57. package/dist/lib/common/common.js.map +1 -0
  58. package/package.json +53 -0
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ /**
3
+ * Text to Voice Action
4
+ * Convert text to voice using AI voice synthesis
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.textToVoice = void 0;
8
+ const cortex_1 = require("@ha-bits/cortex");
9
+ const common_1 = require("../common/common");
10
+ const common_2 = require("../common/common");
11
+ exports.textToVoice = (0, cortex_1.createAction)({
12
+ auth: common_1.intersectAuth,
13
+ name: 'text_to_voice',
14
+ displayName: 'Text to Voice',
15
+ description: 'Convert text to voice using AI voice synthesis',
16
+ props: {
17
+ voice: cortex_1.Property.Dropdown({
18
+ auth: common_1.intersectAuth,
19
+ displayName: 'Voice',
20
+ description: 'Select the voice to use for speech synthesis.',
21
+ required: true,
22
+ refreshers: [],
23
+ options: async ({ auth }) => {
24
+ if (!auth) {
25
+ return {
26
+ disabled: true,
27
+ placeholder: 'Enter your credentials first',
28
+ options: [],
29
+ };
30
+ }
31
+ try {
32
+ const authValue = auth;
33
+ const voicesUrl = (0, common_2.getCanvasApiUrl)(authValue.host, 'voices');
34
+ const response = await cortex_1.httpClient.sendRequest({
35
+ method: cortex_1.HttpMethod.GET,
36
+ url: voicesUrl,
37
+ headers: {
38
+ Authorization: `Bearer ${authValue.apiKey}`,
39
+ },
40
+ });
41
+ return {
42
+ disabled: false,
43
+ options: response.body.voices.map((voice) => ({
44
+ label: voice.name,
45
+ value: voice.id,
46
+ })),
47
+ };
48
+ }
49
+ catch (error) {
50
+ return {
51
+ disabled: true,
52
+ options: [],
53
+ placeholder: "Couldn't load voices, check your credentials",
54
+ };
55
+ }
56
+ },
57
+ }),
58
+ text: cortex_1.Property.LongText({
59
+ displayName: 'Text',
60
+ description: 'The text you want to convert to voice.',
61
+ required: true,
62
+ }),
63
+ speed: cortex_1.Property.Number({
64
+ displayName: 'Speed',
65
+ description: 'Speed of the voice. Left is slower, right is faster. Range: 0 to 1.',
66
+ required: false,
67
+ defaultValue: 0.5,
68
+ }),
69
+ stability: cortex_1.Property.Number({
70
+ displayName: 'Stability',
71
+ description: 'Voice stability. Range: 0 to 1.',
72
+ required: false,
73
+ defaultValue: 0.5,
74
+ }),
75
+ similarity: cortex_1.Property.Number({
76
+ displayName: 'Similarity',
77
+ description: 'Voice similarity boost. Range: 0 to 1.',
78
+ required: false,
79
+ defaultValue: 0.75,
80
+ }),
81
+ styleExaggeration: cortex_1.Property.Number({
82
+ displayName: 'Style Exaggeration',
83
+ description: 'Style exaggeration amount. Range: 0 to 1.',
84
+ required: false,
85
+ defaultValue: 1,
86
+ }),
87
+ },
88
+ async run({ auth, propsValue, files }) {
89
+ const { voice, text, speed, stability, similarity, styleExaggeration } = propsValue;
90
+ const authValue = auth;
91
+ const canvasApiUrl = (0, common_2.getCanvasApiUrl)(authValue.host, 'text-to-voice');
92
+ try {
93
+ const response = await cortex_1.httpClient.sendRequest({
94
+ method: cortex_1.HttpMethod.POST,
95
+ url: canvasApiUrl,
96
+ headers: {
97
+ 'Content-Type': 'application/json',
98
+ Authorization: `Bearer ${authValue.apiKey}`,
99
+ },
100
+ body: {
101
+ voice,
102
+ text,
103
+ speed: speed ?? 0.5,
104
+ stability: stability ?? 0.5,
105
+ similarity: similarity ?? 0.75,
106
+ styleExaggeration: styleExaggeration ?? 1,
107
+ },
108
+ });
109
+ // If the response contains audio data, save it as a file
110
+ if (response.body && response.body.audio) {
111
+ const audioBuffer = Buffer.from(response.body.audio, 'base64');
112
+ return files.write({
113
+ fileName: `voice_${Date.now()}.mp3`,
114
+ data: audioBuffer,
115
+ });
116
+ }
117
+ return response.body;
118
+ }
119
+ catch (e) {
120
+ throw new Error(`Error converting text to voice:\n${e}`);
121
+ }
122
+ },
123
+ });
124
+ //# sourceMappingURL=text-to-voice.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text-to-voice.js","sourceRoot":"","sources":["../../../src/lib/actions/text-to-voice.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,4CAKyB;AACzB,6CAAiD;AACjD,6CAAuE;AAE1D,QAAA,WAAW,GAAG,IAAA,qBAAY,EAAC;IACtC,IAAI,EAAE,sBAAa;IACnB,IAAI,EAAE,eAAe;IACrB,WAAW,EAAE,eAAe;IAC5B,WAAW,EAAE,gDAAgD;IAC7D,KAAK,EAAE;QACL,KAAK,EAAE,iBAAQ,CAAC,QAAQ,CAAC;YACvB,IAAI,EAAE,sBAAa;YACnB,WAAW,EAAE,OAAO;YACpB,WAAW,EAAE,+CAA+C;YAC5D,QAAQ,EAAE,IAAI;YACd,UAAU,EAAE,EAAE;YACd,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE;gBAC1B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CAAC;YAEH,yDAAyD;YACzD,IAAI,QAAQ,CAAC,IAAI,IAAI,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;gBACzC,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;gBAC/D,OAAO,KAAK,CAAC,KAAK,CAAC;oBACjB,QAAQ,EAAE,SAAS,IAAI,CAAC,GAAG,EAAE,MAAM;oBACnC,IAAI,EAAE,WAAW;iBAClB,CAAC,CAAC;YACL,CAAC;YAED,OAAO,QAAQ,CAAC,IAAI,CAAC;QACvB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,EAAE,CAAC,CAAC;QAC3D,CAAC;IACH,CAAC;CACF,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Transcribe Action
3
+ * Transcribe audio to text using whisper-1 model
4
+ */
5
+ export declare const transcribeAction: any;
6
+ //# sourceMappingURL=transcriptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transcriptions.d.ts","sourceRoot":"","sources":["../../../src/lib/actions/transcriptions.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAaH,eAAO,MAAM,gBAAgB,KA2D3B,CAAC"}
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ /**
3
+ * Transcribe Action
4
+ * Transcribe audio to text using whisper-1 model
5
+ */
6
+ var __importDefault = (this && this.__importDefault) || function (mod) {
7
+ return (mod && mod.__esModule) ? mod : { "default": mod };
8
+ };
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.transcribeAction = void 0;
11
+ const cortex_1 = require("@ha-bits/cortex");
12
+ const common_1 = require("../common/common");
13
+ const form_data_1 = __importDefault(require("form-data"));
14
+ const mime_types_1 = __importDefault(require("mime-types"));
15
+ const common_2 = require("../common/common");
16
+ exports.transcribeAction = (0, cortex_1.createAction)({
17
+ name: 'transcribe',
18
+ displayName: 'Transcribe Audio',
19
+ description: 'Transcribe audio to text using whisper-1 model',
20
+ auth: common_1.intersectAuth,
21
+ props: {
22
+ audio: cortex_1.Property.File({
23
+ displayName: 'Audio',
24
+ required: true,
25
+ description: 'Audio file to transcribe',
26
+ }),
27
+ language: cortex_1.Property.StaticDropdown({
28
+ displayName: 'Language of the Audio',
29
+ description: 'Language of the audio file the default is en (English).',
30
+ required: false,
31
+ options: {
32
+ options: common_2.Languages,
33
+ },
34
+ defaultValue: 'en',
35
+ }),
36
+ },
37
+ run: async (context) => {
38
+ const fileData = context.propsValue.audio;
39
+ const mimeType = mime_types_1.default.lookup(fileData.extension ? fileData.extension : '');
40
+ let language = context.propsValue.language;
41
+ // if language is not in languages list, default to english
42
+ if (!common_2.Languages.some((l) => l.value === language)) {
43
+ language = 'en';
44
+ }
45
+ const form = new form_data_1.default();
46
+ form.append('file', fileData.data, {
47
+ filename: fileData.filename,
48
+ contentType: mimeType,
49
+ });
50
+ form.append('model', 'whisper-1');
51
+ form.append('language', language);
52
+ const authValue = context.auth;
53
+ const baseUrl = (0, common_2.getIntersectBaseUrl)(authValue.host);
54
+ const headers = {
55
+ Authorization: `Bearer ${authValue.apiKey}`,
56
+ };
57
+ try {
58
+ const response = await cortex_1.httpClient.sendRequest({
59
+ method: cortex_1.HttpMethod.POST,
60
+ url: `${baseUrl}/audio/transcriptions`,
61
+ body: form,
62
+ headers: {
63
+ ...form.getHeaders(),
64
+ ...headers,
65
+ },
66
+ });
67
+ return response.body;
68
+ }
69
+ catch (e) {
70
+ throw new Error(`Error while execution:\n${e}`);
71
+ }
72
+ },
73
+ });
74
+ //# sourceMappingURL=transcriptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transcriptions.js","sourceRoot":"","sources":["../../../src/lib/actions/transcriptions.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAEH,4CAKyB;AACzB,6CAAiD;AACjD,0DAAiC;AACjC,4DAA8B;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,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QAClC,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;QAElC,MAAM,SAAS,GAAG,OAAO,CAAC,IAAqC,CAAC;QAChE,MAAM,OAAO,GAAG,IAAA,4BAAmB,EAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QACpD,MAAM,OAAO,GAAG;YACd,aAAa,EAAE,UAAU,SAAS,CAAC,MAAM,EAAE;SAC5C,CAAC;QAEF,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,mBAAU,CAAC,WAAW,CAAC;gBAC5C,MAAM,EAAE,mBAAU,CAAC,IAAI;gBACvB,GAAG,EAAE,GAAG,OAAO,uBAAuB;gBACtC,IAAI,EAAE,IAAI;gBACV,OAAO,EAAE;oBACP,GAAG,IAAI,CAAC,UAAU,EAAE;oBACpB,GAAG,OAAO;iBACX;aACF,CAAC,CAAC;YACH,OAAO,QAAQ,CAAC,IAAI,CAAC;QACvB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,EAAE,CAAC,CAAC;QAClD,CAAC;IACH,CAAC;CACF,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Translation Action
3
+ * Translate audio to text using whisper-1 model
4
+ */
5
+ export declare const translateAction: any;
6
+ //# sourceMappingURL=translation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"translation.d.ts","sourceRoot":"","sources":["../../../src/lib/actions/translation.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAaH,eAAO,MAAM,eAAe,KA2C1B,CAAC"}
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ /**
3
+ * Translation Action
4
+ * Translate audio to text using whisper-1 model
5
+ */
6
+ var __importDefault = (this && this.__importDefault) || function (mod) {
7
+ return (mod && mod.__esModule) ? mod : { "default": mod };
8
+ };
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.translateAction = void 0;
11
+ const cortex_1 = require("@ha-bits/cortex");
12
+ const common_1 = require("../common/common");
13
+ const form_data_1 = __importDefault(require("form-data"));
14
+ const mime_types_1 = __importDefault(require("mime-types"));
15
+ const common_2 = require("../common/common");
16
+ exports.translateAction = (0, cortex_1.createAction)({
17
+ name: 'translate',
18
+ displayName: 'Translate Audio',
19
+ description: 'Translate audio to text using whisper-1 model',
20
+ auth: common_1.intersectAuth,
21
+ props: {
22
+ audio: cortex_1.Property.File({
23
+ displayName: 'Audio',
24
+ required: true,
25
+ description: 'Audio file to translate',
26
+ }),
27
+ },
28
+ run: async (context) => {
29
+ const fileData = context.propsValue.audio;
30
+ const mimeType = mime_types_1.default.lookup(fileData.extension ? fileData.extension : '');
31
+ const form = new form_data_1.default();
32
+ form.append('file', fileData.data, {
33
+ filename: fileData.filename,
34
+ contentType: mimeType,
35
+ });
36
+ form.append('model', 'whisper-1');
37
+ const authValue = context.auth;
38
+ const baseUrl = (0, common_2.getIntersectBaseUrl)(authValue.host);
39
+ const headers = {
40
+ Authorization: `Bearer ${authValue.apiKey}`,
41
+ };
42
+ try {
43
+ const response = await cortex_1.httpClient.sendRequest({
44
+ method: cortex_1.HttpMethod.POST,
45
+ url: `${baseUrl}/audio/translations`,
46
+ body: form,
47
+ headers: {
48
+ ...form.getHeaders(),
49
+ ...headers,
50
+ },
51
+ });
52
+ return response.body;
53
+ }
54
+ catch (e) {
55
+ throw new Error(`Error while execution:\n${e}`);
56
+ }
57
+ },
58
+ });
59
+ //# sourceMappingURL=translation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"translation.js","sourceRoot":"","sources":["../../../src/lib/actions/translation.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAEH,4CAKyB;AACzB,6CAAiD;AACjD,0DAAiC;AACjC,4DAA8B;AAC9B,6CAA2E;AAE9D,QAAA,eAAe,GAAG,IAAA,qBAAY,EAAC;IAC1C,IAAI,EAAE,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CAAC;YACH,OAAO,QAAQ,CAAC,IAAI,CAAC;QACvB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,EAAE,CAAC,CAAC;QAClD,CAAC;IACH,CAAC;CACF,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Vision Prompt Action
3
+ * Ask GPT a question about an image
4
+ */
5
+ export declare const visionPrompt: any;
6
+ //# sourceMappingURL=vision-prompt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vision-prompt.d.ts","sourceRoot":"","sources":["../../../src/lib/actions/vision-prompt.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAUH,eAAO,MAAM,YAAY,KAiJvB,CAAC"}
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+ /**
3
+ * Vision Prompt Action
4
+ * Ask GPT a question about an image
5
+ */
6
+ var __importDefault = (this && this.__importDefault) || function (mod) {
7
+ return (mod && mod.__esModule) ? mod : { "default": mod };
8
+ };
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.visionPrompt = void 0;
11
+ const cortex_1 = require("@ha-bits/cortex");
12
+ const openai_1 = __importDefault(require("openai"));
13
+ const common_1 = require("../common/common");
14
+ const common_2 = require("../common/common");
15
+ exports.visionPrompt = (0, cortex_1.createAction)({
16
+ auth: common_1.intersectAuth,
17
+ name: 'vision_prompt',
18
+ displayName: 'Vision Prompt',
19
+ description: 'Ask GPT a question about an image',
20
+ props: {
21
+ image: cortex_1.Property.File({
22
+ displayName: 'Image',
23
+ description: "The image URL or file you want GPT's vision to read.",
24
+ required: true,
25
+ }),
26
+ prompt: cortex_1.Property.LongText({
27
+ displayName: 'Question',
28
+ description: 'What do you want ChatGPT to tell you about the image?',
29
+ required: true,
30
+ }),
31
+ detail: cortex_1.Property.StaticDropdown({
32
+ displayName: 'Detail',
33
+ required: false,
34
+ description: 'Control how the model processes the image and generates textual understanding.',
35
+ defaultValue: 'auto',
36
+ options: {
37
+ options: [
38
+ {
39
+ label: 'low',
40
+ value: 'low',
41
+ },
42
+ {
43
+ label: 'high',
44
+ value: 'high',
45
+ },
46
+ {
47
+ label: 'auto',
48
+ value: 'auto',
49
+ },
50
+ ],
51
+ },
52
+ }),
53
+ temperature: cortex_1.Property.Number({
54
+ displayName: 'Temperature',
55
+ required: false,
56
+ description: 'Controls randomness: Lowering results in less random completions. As the temperature approaches zero, the model will become deterministic and repetitive.',
57
+ defaultValue: 0.9,
58
+ }),
59
+ maxTokens: cortex_1.Property.Number({
60
+ displayName: 'Maximum Tokens',
61
+ required: false,
62
+ description: "The maximum number of tokens to generate. Requests can use up to 2,048 or 4,096 tokens shared between prompt and completion, don't set the value to maximum and leave some tokens for the input. The exact limit varies by model. (One token is roughly 4 characters for normal English text)",
63
+ defaultValue: 2048,
64
+ }),
65
+ topP: cortex_1.Property.Number({
66
+ displayName: 'Top P',
67
+ required: false,
68
+ description: 'An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.',
69
+ defaultValue: 1,
70
+ }),
71
+ frequencyPenalty: cortex_1.Property.Number({
72
+ displayName: 'Frequency penalty',
73
+ required: false,
74
+ description: "Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.",
75
+ defaultValue: 0,
76
+ }),
77
+ presencePenalty: cortex_1.Property.Number({
78
+ displayName: 'Presence penalty',
79
+ required: false,
80
+ description: "Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the mode's likelihood to talk about new topics.",
81
+ defaultValue: 0.6,
82
+ }),
83
+ roles: cortex_1.Property.Json({
84
+ displayName: 'Roles',
85
+ required: false,
86
+ description: 'Array of roles to specify more accurate response',
87
+ defaultValue: [
88
+ { role: 'system', content: 'You are a helpful assistant.' },
89
+ ],
90
+ }),
91
+ },
92
+ async run({ auth, propsValue }) {
93
+ // Inline validation to avoid Zod version mismatch
94
+ const { temperature } = propsValue;
95
+ if (temperature !== undefined && temperature !== null) {
96
+ if (typeof temperature !== 'number' || temperature < 0 || temperature > 1) {
97
+ throw new Error('Temperature must be a number between 0 and 1');
98
+ }
99
+ }
100
+ const authValue = auth;
101
+ const openai = new openai_1.default({
102
+ apiKey: authValue.apiKey,
103
+ baseURL: (0, common_2.getIntersectBaseUrl)(authValue.host),
104
+ });
105
+ const { maxTokens, topP, frequencyPenalty, presencePenalty } = propsValue;
106
+ const rolesArray = propsValue.roles ? propsValue.roles : [];
107
+ const roles = rolesArray.map((item) => {
108
+ const rolesEnum = ['system', 'user', 'assistant'];
109
+ if (!rolesEnum.includes(item.role)) {
110
+ throw new Error('The only available roles are: [system, user, assistant]');
111
+ }
112
+ return {
113
+ role: item.role,
114
+ content: item.content,
115
+ };
116
+ });
117
+ const imageData = propsValue.image;
118
+ const completion = await openai.chat.completions.create({
119
+ model: 'gpt-4o',
120
+ messages: [
121
+ ...roles,
122
+ {
123
+ role: 'user',
124
+ content: [
125
+ {
126
+ type: 'text',
127
+ text: propsValue['prompt'],
128
+ },
129
+ {
130
+ type: 'image_url',
131
+ image_url: {
132
+ url: `data:image/${imageData.extension};base64,${imageData.base64}`,
133
+ },
134
+ },
135
+ ],
136
+ },
137
+ ],
138
+ temperature: temperature,
139
+ max_tokens: maxTokens,
140
+ top_p: topP,
141
+ frequency_penalty: frequencyPenalty,
142
+ presence_penalty: presencePenalty,
143
+ });
144
+ return completion.choices[0].message.content;
145
+ },
146
+ });
147
+ //# sourceMappingURL=vision-prompt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vision-prompt.js","sourceRoot":"","sources":["../../../src/lib/actions/vision-prompt.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAEH,4CAGyB;AACzB,oDAA4B;AAC5B,6CAAiD;AACjD,6CAA2E;AAE9D,QAAA,YAAY,GAAG,IAAA,qBAAY,EAAC;IACvC,IAAI,EAAE,sBAAa;I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* This module provides shared utilities, authentication, and constants
5
+ * for the Intersect AI bit module.
6
+ */
7
+ /**
8
+ * Type for Intersect authentication
9
+ */
10
+ export interface IntersectAuthValue {
11
+ host: string;
12
+ apiKey: string;
13
+ }
14
+ /**
15
+ * Get the canvas API URL for a specific path
16
+ */
17
+ export declare const getCanvasApiUrl: (host: string, path: string) => string;
18
+ /**
19
+ * Parse the intersect tenant input and return the full API base URL.
20
+ * Accepts:
21
+ * - Full URL: https://tenant.intersect.site
22
+ * - Domain: tenant.intersect.site
23
+ * - Just tenant name: tenant
24
+ * - localhost
25
+ */
26
+ export declare const getIntersectBaseUrl: (host: string) => string;
27
+ /**
28
+ * Intersect authentication configuration
29
+ * Defined here to avoid circular dependencies
30
+ */
31
+ export declare const intersectAuth: any;
32
+ export declare const openaiAuth: any;
33
+ export declare const baseUrl = "https://api.openai.com/v1";
34
+ export declare const Languages: {
35
+ value: string;
36
+ label: string;
37
+ }[];
38
+ export declare const billingIssueMessage = "Error Occurred: 429 \n\n1. Ensure that billing is enabled on your OpenAI platform. \n\n2. Generate a new API key. \n\n3. Attempt the process again. \n\nFor guidance, visit: https://beta.openai.com/account/billing";
39
+ export declare const unauthorizedMessage = "Error Occurred: 401 \n\nEnsure that your API key is valid. \n";
40
+ export declare const sleep: (ms: number) => Promise<unknown>;
41
+ export declare const streamToBuffer: (stream: any) => Promise<unknown>;
42
+ export declare const calculateTokensFromString: (string: string, model: string) => number;
43
+ export declare const calculateMessagesTokenSize: (messages: any[], model: string) => Promise<number>;
44
+ export declare const reduceContextSize: (messages: any[], model: string, maxTokens: number) => Promise<any[]>;
45
+ export declare const exceedsHistoryLimit: (tokenLength: number, model: string, maxTokens: number) => boolean;
46
+ export declare const tokenLimit = 32000;
47
+ export declare const modelTokenLimit: (model: string) => 128000 | 8192 | 32768 | 16385 | 4096 | 8001 | 400000 | 2048;
48
+ export declare const notLLMs: string[];
49
+ //# sourceMappingURL=common.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":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