Skip to content

Commit cb64910

Browse files
committed
fix(ai): only import types from openai
1 parent 37a925c commit cb64910

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

packages/ai/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@pipedream/ai",
33
"type": "module",
4-
"version": "0.0.2",
4+
"version": "0.0.3",
55
"description": "Pipedream AI",
66
"main": "./dist/index.js",
77
"types": "./dist/index.d.ts",

packages/ai/src/tool-sets/openai.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
import OpenAI from "openai/index.mjs";
2-
import { ChatCompletionTool } from "openai/resources/chat/completions";
1+
import { type OpenAI } from "openai";
2+
import {
3+
type ChatCompletionTool,
4+
type ChatCompletionToolMessageParam,
5+
} from "openai/resources/chat/completions";
36
import { zodToJsonSchema } from "zod-to-json-schema";
47
import { CoreTools } from "./core";
58

@@ -26,7 +29,9 @@ export class OpenAiTools {
2629
});
2730
}
2831

29-
async handleCompletion(completion: OpenAI.Chat.Completions.ChatCompletion) {
32+
async handleCompletion(
33+
completion: OpenAI.Chat.Completions.ChatCompletion,
34+
): Promise<ChatCompletionToolMessageParam[] | undefined> {
3035
const toolCalls = completion.choices[0].message.tool_calls;
3136
if (!toolCalls) {
3237
return;
@@ -43,7 +48,12 @@ export class OpenAiTools {
4348
const parsedArgs = tool.schema.parse(args);
4449

4550
const result = await tool.execute(parsedArgs);
46-
return result;
51+
const toolResult: ChatCompletionToolMessageParam = {
52+
role: "tool",
53+
tool_call_id: toolCall.id,
54+
content: JSON.stringify(result, null, 2),
55+
};
56+
return toolResult;
4757
}),
4858
);
4959
return results;

0 commit comments

Comments
 (0)