@christianriedl/utils 1.0.118 → 1.0.120
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/iOpenAI.d.ts +36 -8
- package/package.json +1 -1
- package/src/components/OpenAI.vue +9 -7
package/dist/iOpenAI.d.ts
CHANGED
|
@@ -1,14 +1,42 @@
|
|
|
1
1
|
import { InjectionKey } from 'vue';
|
|
2
|
-
import { ISpeechService } from './iAudio';
|
|
3
2
|
import { ILogger } from './iLogger';
|
|
3
|
+
import { Dictionary } from './types';
|
|
4
4
|
export declare const getOpenAISymbol: InjectionKey<() => IOpenAIService>;
|
|
5
|
-
export interface
|
|
6
|
-
|
|
5
|
+
export interface IResponseResult {
|
|
6
|
+
text?: string;
|
|
7
|
+
error?: string;
|
|
8
|
+
json?: any;
|
|
9
|
+
usage?: {
|
|
10
|
+
input_tokens: number;
|
|
11
|
+
output_tokens: number;
|
|
12
|
+
};
|
|
13
|
+
top_p?: number;
|
|
14
|
+
temperature?: number;
|
|
7
15
|
}
|
|
8
|
-
export interface
|
|
16
|
+
export interface ISchema {
|
|
17
|
+
name: string;
|
|
18
|
+
schema?: Dictionary<unknown>;
|
|
19
|
+
}
|
|
20
|
+
export interface IOpenAIService {
|
|
9
21
|
log: ILogger;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
22
|
+
response(prompt: string, tools?: string[], imageUrl?: string, json?: ISchema): Promise<IResponseResult>;
|
|
23
|
+
clearContext(): void;
|
|
24
|
+
}
|
|
25
|
+
export interface IOpenAIServiceWithTools extends IOpenAIService {
|
|
26
|
+
addMcpTool(label: string, url: string, desc: string, allowedTools?: string[]): void;
|
|
27
|
+
addFileSearchTool(label: string, vectorStore: string): boolean;
|
|
28
|
+
addWebSearchTool(label: string, country?: string, city?: string, region?: string): void;
|
|
29
|
+
}
|
|
30
|
+
export interface IVectorStore {
|
|
31
|
+
id: string;
|
|
32
|
+
name: string;
|
|
33
|
+
files: Dictionary<string>;
|
|
34
|
+
}
|
|
35
|
+
export interface IOpenAIServiceWithVectorStore extends IOpenAIServiceWithTools {
|
|
36
|
+
vectorStore?: Dictionary<IVectorStore>;
|
|
37
|
+
initializeVectorStore(): Promise<boolean>;
|
|
38
|
+
addFile(fileUrl: string, vectorStoreId: string, wait?: boolean): Promise<boolean>;
|
|
39
|
+
deleteFile(fileId: string): Promise<boolean>;
|
|
40
|
+
deleteVectorStore(vectorStoreId: string): Promise<boolean>;
|
|
41
|
+
getFileId(fileUrl: string): string | undefined;
|
|
14
42
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { inject, ref, toRef, computed, onUnmounted } from 'vue';
|
|
3
|
-
import { appStateSymbol, appConfigSymbol,
|
|
3
|
+
import { appStateSymbol, appConfigSymbol, ESize } from '@christianriedl/utils';
|
|
4
|
+
import { getOpenAISymbol, IOpenAIService, IResponseResult } from '@christianriedl/utils';
|
|
4
5
|
import Microphone from '@christianriedl/utils/src/components/Microphone.vue';
|
|
5
6
|
import Camera from '@christianriedl/utils/src/components/Camera.vue';
|
|
6
7
|
|
|
@@ -21,6 +22,7 @@
|
|
|
21
22
|
const camera = ref<InstanceType<typeof Camera>>();
|
|
22
23
|
|
|
23
24
|
onUnmounted(() => {
|
|
25
|
+
openAI.clearContext();
|
|
24
26
|
if (camera.value)
|
|
25
27
|
camera.value.stop();
|
|
26
28
|
});
|
|
@@ -29,7 +31,7 @@
|
|
|
29
31
|
replyLines.value = ["WAITING ..."];
|
|
30
32
|
files.value = [];
|
|
31
33
|
isUpload.value = false;
|
|
32
|
-
let answer:
|
|
34
|
+
let answer: IResponseResult;
|
|
33
35
|
if (camera.value) {
|
|
34
36
|
dataUrl.value = await camera.value.snapshot() as string;
|
|
35
37
|
camera.value.stop();
|
|
@@ -37,7 +39,7 @@
|
|
|
37
39
|
isCamera.value = false;
|
|
38
40
|
}
|
|
39
41
|
if (dataUrl.value) {
|
|
40
|
-
answer = await openAI.
|
|
42
|
+
answer = await openAI.response(question.value, undefined, dataUrl.value);
|
|
41
43
|
dataUrl.value = "";
|
|
42
44
|
}
|
|
43
45
|
else {
|
|
@@ -45,12 +47,12 @@
|
|
|
45
47
|
answer = await openAI.response(question.value, props.tools);
|
|
46
48
|
}
|
|
47
49
|
else {
|
|
48
|
-
answer = await openAI.
|
|
50
|
+
answer = await openAI.response(question.value);
|
|
49
51
|
}
|
|
50
52
|
}
|
|
51
|
-
if (answer && answer.
|
|
52
|
-
emits('result', answer.
|
|
53
|
-
replyLines.value = answer.
|
|
53
|
+
if (answer && answer.text) {
|
|
54
|
+
emits('result', answer.text);
|
|
55
|
+
replyLines.value = answer.text.split('\n');
|
|
54
56
|
}
|
|
55
57
|
else {
|
|
56
58
|
emits('result', "KEINE KORREKTE ANTWORT");
|