@christianriedl/utils 1.0.136 → 1.0.138

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 CHANGED
@@ -2,8 +2,30 @@ import { InjectionKey } from 'vue';
2
2
  import { ILogger } from './iLogger';
3
3
  import { Dictionary } from './types';
4
4
  export declare const getOpenAISymbol: InjectionKey<() => IOpenAIService>;
5
+ export interface IResultAnnotation {
6
+ file_id?: string;
7
+ filename?: string;
8
+ url?: string;
9
+ index?: number;
10
+ type: 'file_citation' | 'url_citation';
11
+ }
12
+ export interface IResultContent {
13
+ annotations?: IResultAnnotation[];
14
+ text: string;
15
+ type: 'output_text';
16
+ }
17
+ export interface IResultOutput {
18
+ id: string;
19
+ queries?: string[];
20
+ results?: any[];
21
+ role?: 'assistant';
22
+ status?: 'in_progress' | 'completed' | 'incomplete';
23
+ type: 'message' | 'file_search_call' | 'mcp_call' | 'function_call';
24
+ content?: IResultContent[];
25
+ }
5
26
  export interface IResponseResult {
6
27
  id?: string;
28
+ output?: IResultOutput[];
7
29
  text?: string;
8
30
  error?: string;
9
31
  json?: any;
@@ -32,7 +54,7 @@ export interface IMcpTool extends ITool {
32
54
  export interface IFileSearchTool extends ITool {
33
55
  type: 'file_search';
34
56
  vector_store_ids: string[];
35
- filters?: any;
57
+ filters?: IComparisonFilter | ICompoundFilter;
36
58
  max_num_results?: number;
37
59
  }
38
60
  export interface IWebSearchLocation {
@@ -53,6 +75,15 @@ export interface IFunctionTool extends ITool {
53
75
  strict: boolean | null;
54
76
  description?: string | null;
55
77
  }
78
+ export interface IComparisonFilter {
79
+ key: string;
80
+ type: 'eq' | 'ne' | 'gt' | 'gte' | 'lt' | 'lte';
81
+ value: string | number | boolean;
82
+ }
83
+ export interface ICompoundFilter {
84
+ filters: IComparisonFilter[] | unknown;
85
+ type: 'and' | 'or';
86
+ }
56
87
  export interface IOpenAIOptions {
57
88
  model: string;
58
89
  instructions?: string | null;
@@ -68,7 +99,7 @@ export interface IOpenAIService {
68
99
  options: IOpenAIOptions;
69
100
  modelNames: string[];
70
101
  initialize(): Promise<boolean>;
71
- response(prompt: string | string[], tools?: string[], imageUrl?: string, json?: ISchema): Promise<IResponseResult>;
102
+ response(prompt: string | string[], tools?: string[], imageUrl?: string, json?: ISchema, fileSearchFilter?: ICompoundFilter | IComparisonFilter): Promise<IResponseResult>;
72
103
  clearContext(): void;
73
104
  getModels(): Promise<string[]>;
74
105
  }
@@ -86,6 +117,17 @@ export interface IVectorStore {
86
117
  name: string;
87
118
  files: Dictionary<string>;
88
119
  }
120
+ export interface IVectorSearchContent {
121
+ type: 'text';
122
+ text: string;
123
+ }
124
+ export interface IVectorSearchResult {
125
+ attributes: Dictionary<string | number | boolean> | null;
126
+ content: IVectorSearchContent[];
127
+ file_id: string;
128
+ filename: string;
129
+ score: number;
130
+ }
89
131
  export interface IOpenAIServiceWithVectorStore extends IOpenAIServiceWithTools {
90
132
  vectorStore?: Dictionary<IVectorStore>;
91
133
  initializeVectorStore(): Promise<boolean>;
@@ -94,6 +136,7 @@ export interface IOpenAIServiceWithVectorStore extends IOpenAIServiceWithTools {
94
136
  addFile(fileUrl: string | File, vectorStoreName: string, wait?: boolean): Promise<boolean>;
95
137
  deleteFile(fileId: string): Promise<boolean>;
96
138
  deleteVectorStore(vectorStoreId: string): Promise<boolean>;
139
+ searchVectoreStore(vectorStoreName: string, query: string | string[], rewriteQuery?: boolean, maxNumResults?: number, filters?: ICompoundFilter | IComparisonFilter): Promise<IVectorSearchResult[]>;
97
140
  getFileId(fileUrl: string): string | undefined;
98
141
  }
99
142
  export interface IOpenAIAppConfig {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@christianriedl/utils",
3
- "version": "1.0.136",
3
+ "version": "1.0.138",
4
4
  "description": "Interfaces, local storage, service worker, configuration, application state",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -24,9 +24,10 @@
24
24
  const isUpload = ref(false);
25
25
  const showConfig = ref(false);
26
26
  const files = ref<File[]>([]);
27
- const dataUrl = ref("");
27
+ const imageUrl = ref("");
28
28
  const camera = ref<InstanceType<typeof Camera>>();
29
29
  const htmlText = ref('');
30
+ const tools = ref(props.tools);
30
31
 
31
32
  onUnmounted(() => {
32
33
  openAI.clearContext();
@@ -35,23 +36,23 @@
35
36
  });
36
37
 
37
38
  async function onComplete() {
38
- replyLines.value = ["WAITING ..."];
39
+ htmlText.value = "<h4>WAITING ...</h4>";
39
40
  files.value = [];
40
41
  isUpload.value = false;
41
42
  let answer: IResponseResult;
42
43
  if (camera.value) {
43
- dataUrl.value = await camera.value.snapshot() as string;
44
+ imageUrl.value = await camera.value.snapshot() as string;
44
45
  camera.value.stop();
45
46
  camera.value = undefined;
46
47
  isCamera.value = false;
47
48
  }
48
- if (dataUrl.value) {
49
- answer = await openAI.response(question.value, undefined, dataUrl.value);
50
- dataUrl.value = "";
49
+ if (imageUrl.value) {
50
+ answer = await openAI.response(question.value, undefined, imageUrl.value);
51
+ imageUrl.value = "";
51
52
  }
52
53
  else {
53
- if (props.tools !== undefined) {
54
- answer = await openAI.response(question.value, props.tools);
54
+ if (tools.value !== undefined) {
55
+ answer = await openAI.response(question.value, tools.value);
55
56
  }
56
57
  else {
57
58
  answer = await openAI.response(question.value);
@@ -67,7 +68,6 @@
67
68
  }
68
69
  }
69
70
  if (openAI.options.outputFormat == 'html') {
70
-
71
71
  const tempDiv = document.createElement('div');
72
72
  if (answer.text.startsWith('```html\n')) {
73
73
  if (answer.text.endsWith('\n```')) {
@@ -91,10 +91,9 @@
91
91
  }
92
92
  }
93
93
  else {
94
- htmlText.value = '';
95
94
  const text = "KEINE KORREKTE ANTWORT : " + answer.error;
96
95
  emits('result', text);
97
- replyLines.value = [text];
96
+ htmlText.value = `<h4>${text}</h4>`;
98
97
  }
99
98
  }
100
99
  async function onResult(result: SpeechRecognitionResult) {
@@ -121,13 +120,14 @@
121
120
  const reader = new FileReader();
122
121
  reader.addEventListener("load", async () => {
123
122
  // convert image file to base64 string
124
- dataUrl.value = reader.result as string;
123
+ imageUrl.value = reader.result as string;
125
124
  }, false,);
126
125
  reader.readAsDataURL(files.value[0]);
127
126
  }
128
127
  }
129
- function onUse(tools: string[], persist: boolean) {
130
- emits('use', tools, persist);
128
+ function onUse(usetools: string[], persist: boolean) {
129
+ tools.value = usetools;
130
+ emits('use', usetools, persist);
131
131
  }
132
132
  // Move to some library
133
133
  async function markdownToHtml(markdownText: string): Promise<string> {
@@ -189,7 +189,7 @@
189
189
  </v-file-input>
190
190
  </v-col>
191
191
  <v-col cols="6">
192
- <img width="100%" :src="dataUrl">
192
+ <img width="100%" :src="imageUrl">
193
193
  </v-col>
194
194
  </v-row>
195
195
  <v-row v-if="htmlText" dense >
@@ -201,7 +201,7 @@
201
201
  <v-col cols="12">{{line}}</v-col>
202
202
  </v-row>
203
203
  <v-dialog v-model="showConfig" :fullscreen="isMobile">
204
- <OpenAIConfig :tools="props.tools" :ismobile="isMobile" @use="onUse" @back="showConfig=false"></OpenAIConfig>
204
+ <OpenAIConfig :tools="tools" :ismobile="isMobile" @use="onUse" @back="showConfig=false"></OpenAIConfig>
205
205
  </v-dialog>
206
206
  </v-container>
207
207
  </template>
@@ -1,7 +1,7 @@
1
1
  <script setup lang="ts">
2
2
  import { inject, ref, reactive } from 'vue';
3
3
  import { appConfigSymbol, AppConfig, Dictionary } from '@christianriedl/utils';
4
- import { getOpenAISymbol, IOpenAIServiceWithVectorStore, IOpenAIAppConfig, IOpenAIOptions, ITool } from '@christianriedl/utils';
4
+ import { getOpenAISymbol, IOpenAIServiceWithVectorStore, IOpenAIAppConfig, IOpenAIOptions, ITool, IMcpTool, IFileSearchTool } from '@christianriedl/utils';
5
5
 
6
6
  interface IFunction {
7
7
  name: string;
@@ -88,6 +88,7 @@
88
88
  if (toolsChanged.value) {
89
89
  for (const key in fileSearch) {
90
90
  const vsNames = fileSearch[key];
91
+ tools[key].vector_store_ids.splice(0, tools[key].vector_store_ids.length);
91
92
  for (let i = 0; i < vsNames.length; i++) {
92
93
  tools[key].vector_store_ids[i] = openAI.vectorStore![vsNames[i]].id;
93
94
  }
@@ -119,6 +120,29 @@
119
120
  emits('use', useTools, persist);
120
121
  useChanged.value = false;
121
122
  }
123
+ function onAddMcp() {
124
+ const name = window.prompt('Enter MCP name:');
125
+ if (name && name.length > 0) {
126
+ if (tools[name]) {
127
+ alert('Tool with this name already exists, please choose another name !');
128
+ return;
129
+ }
130
+ const mcpTool: IMcpTool = { type: 'mcp', server_label: name, server_url: '<set url>', require_approval: 'never' };
131
+ tools[name] = mcpTool;
132
+ }
133
+ }
134
+ function onAddSearch() {
135
+ const name = window.prompt('Enter File search name:');
136
+ if (name && name.length > 0) {
137
+ if (tools[name]) {
138
+ alert('Tool with this name already exists, please choose another name !');
139
+ return;
140
+ }
141
+ const searchTool: IFileSearchTool = { type: 'file_search', vector_store_ids: [] };
142
+ tools[name] = searchTool;
143
+ fileSearch[name] = [];
144
+ }
145
+ }
122
146
  function vectorStoreSelected() {
123
147
  selectedVectorStoreFile.value = '';
124
148
  const vs = openAI.vectorStore![selectedVectorStoreName.value];
@@ -302,6 +326,16 @@
302
326
  <v-icon icon="$save"></v-icon>
303
327
  </v-btn>
304
328
  </v-col>
329
+ <v-col cols="2">
330
+ <v-btn class="bg-office" @click="onAddMcp">ADD MCP
331
+ <v-icon icon="$plus"></v-icon>
332
+ </v-btn>
333
+ </v-col>
334
+ <v-col cols="2">
335
+ <v-btn class="bg-office" @click="onAddSearch">ADD SEARCH
336
+ <v-icon icon="$plus"></v-icon>
337
+ </v-btn>
338
+ </v-col>
305
339
  </v-row>
306
340
  <template v-if="!props.ismobile && openAI.vectorStore">
307
341
  <v-divider></v-divider>