@@ -11,15 +11,21 @@ import {
11
11
import { aiSearchConnectionString } from "../config/env.js" ;
12
12
import { PromptConfig } from "../types.js" ;
13
13
14
- export async function createTools ( selectedPromptConfig : PromptConfig , client : AIProjectsClient ) {
15
- if ( selectedPromptConfig . tool === 'code-interpreter' ) {
16
- const { codeInterpreterTool, file } = await getCodeInterpreter ( selectedPromptConfig , client ) ;
17
- if ( file ) {
18
- selectedPromptConfig . fileId = file ?. id ;
19
- }
20
- selectedPromptConfig . tools = [ codeInterpreterTool . definition ] ;
21
- selectedPromptConfig . toolResources = codeInterpreterTool . resources ;
14
+ export async function createTools (
15
+ selectedPromptConfig : PromptConfig ,
16
+ client : AIProjectsClient
17
+ ) {
18
+ if ( selectedPromptConfig . tool === "code-interpreter" ) {
19
+ const { codeInterpreterTool, file } = await getCodeInterpreter (
20
+ selectedPromptConfig ,
21
+ client
22
+ ) ;
23
+ if ( file ) {
24
+ selectedPromptConfig . fileId = file ?. id ;
22
25
}
26
+ selectedPromptConfig . tools = [ codeInterpreterTool . definition ] ;
27
+ selectedPromptConfig . toolResources = codeInterpreterTool . resources ;
28
+ }
23
29
24
30
if ( selectedPromptConfig . tool === "ai-search" ) {
25
31
const azureAISearchTool = await createAISearchTool ( client ) ;
@@ -35,33 +41,49 @@ export async function createTools(selectedPromptConfig: PromptConfig, client: AI
35
41
}
36
42
}
37
43
38
- export async function getCodeInterpreter ( selectedPromptConfig : PromptConfig , client : AIProjectsClient ) {
39
- if ( selectedPromptConfig . filePath ) {
40
- const fileStream = fs . createReadStream ( selectedPromptConfig . filePath ) ;
41
- const file = await client . agents . uploadFile ( fileStream , 'assistants' , { fileName : selectedPromptConfig . filePath } ) ;
42
- console . log ( `Uploaded ${ selectedPromptConfig . filePath } . File ID: ${ file . id } ` ) ;
43
- const codeInterpreterTool = ToolUtility . createCodeInterpreterTool ( [ file . id ] ) ;
44
- return { codeInterpreterTool, file } ;
45
- }
46
- return { codeInterpreterTool : ToolUtility . createCodeInterpreterTool ( [ ] ) , file : null } ;
44
+ export async function getCodeInterpreter (
45
+ selectedPromptConfig : PromptConfig ,
46
+ client : AIProjectsClient
47
+ ) {
48
+ if ( selectedPromptConfig . filePath ) {
49
+ const fileStream = fs . createReadStream ( selectedPromptConfig . filePath ) ;
50
+ const file = await client . agents . uploadFile ( fileStream , "assistants" , {
51
+ fileName : selectedPromptConfig . filePath ,
52
+ } ) ;
53
+ console . log (
54
+ `Uploaded ${ selectedPromptConfig . filePath } . File ID: ${ file . id } `
55
+ ) ;
56
+ const codeInterpreterTool = ToolUtility . createCodeInterpreterTool ( [
57
+ file . id ,
58
+ ] ) ;
59
+ return { codeInterpreterTool, file } ;
60
+ }
61
+ return {
62
+ codeInterpreterTool : ToolUtility . createCodeInterpreterTool ( [ ] ) ,
63
+ file : null ,
64
+ } ;
47
65
}
48
66
49
67
export async function createAISearchTool ( client : AIProjectsClient ) {
50
- if ( ! aiSearchConnectionString ) {
51
- throw new Error ( ' AI Search connection string is required' ) ;
52
- }
68
+ if ( ! aiSearchConnectionString ) {
69
+ throw new Error ( " AI Search connection string is required" ) ;
70
+ }
53
71
54
- const aiSearchConnection = await client . connections . getConnection ( aiSearchConnectionString ) ;
55
- return ToolUtility . createAzureAISearchTool (
56
- aiSearchConnection . id ,
57
- aiSearchConnection . name
58
- ) ;
72
+ const aiSearchConnection = await client . connections . getConnection (
73
+ aiSearchConnectionString
74
+ ) ;
75
+ return ToolUtility . createAzureAISearchTool (
76
+ aiSearchConnection . id ,
77
+ aiSearchConnection . name
78
+ ) ;
59
79
}
60
80
61
81
class FunctionToolFactory {
62
- static getCpuUsage ( ) {
63
- return `CPU Usage: ${ cpus ( ) [ 0 ] . model } ${ Math . floor ( ( cpus ( ) . reduce ( ( acc , core ) => acc + core . speed , 0 ) ) / 1000 ) } %` ;
64
- }
82
+ static getCpuUsage ( ) {
83
+ return `CPU Usage: ${ cpus ( ) [ 0 ] . model } ${ Math . floor (
84
+ cpus ( ) . reduce ( ( acc , core ) => acc + core . speed , 0 ) / 1000
85
+ ) } %`;
86
+ }
65
87
}
66
88
67
89
export class FunctionToolExecutor {
0 commit comments