Skip to content

Commit 5e118c9

Browse files
committed
style: fix formating
1 parent 4e9e3e5 commit 5e118c9

File tree

1 file changed

+50
-28
lines changed

1 file changed

+50
-28
lines changed

src/services/toolService.ts

Lines changed: 50 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,21 @@ import {
1111
import { aiSearchConnectionString } from "../config/env.js";
1212
import { PromptConfig } from "../types.js";
1313

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;
2225
}
26+
selectedPromptConfig.tools = [codeInterpreterTool.definition];
27+
selectedPromptConfig.toolResources = codeInterpreterTool.resources;
28+
}
2329

2430
if (selectedPromptConfig.tool === "ai-search") {
2531
const azureAISearchTool = await createAISearchTool(client);
@@ -35,33 +41,49 @@ export async function createTools(selectedPromptConfig: PromptConfig, client: AI
3541
}
3642
}
3743

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+
};
4765
}
4866

4967
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+
}
5371

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+
);
5979
}
6080

6181
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+
}
6587
}
6688

6789
export class FunctionToolExecutor {

0 commit comments

Comments
 (0)