@ainetwork/adk-provider-model-azure 0.1.1 → 0.1.3
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/index.ts +58 -0
- package/package.json +9 -9
package/index.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { BaseModel } from "@ainetwork/adk/modules";
|
|
2
2
|
import { ChatRole, type SessionObject } from "@ainetwork/adk/types/memory";
|
|
3
|
+
import type {
|
|
4
|
+
LLMStream,
|
|
5
|
+
StreamChunk,
|
|
6
|
+
ToolCallDelta,
|
|
7
|
+
} from "@ainetwork/adk/types/stream";
|
|
3
8
|
import type {
|
|
4
9
|
FetchResponse,
|
|
5
10
|
IA2ATool,
|
|
@@ -11,6 +16,7 @@ import { TOOL_PROTOCOL_TYPE } from "@ainetwork/adk/types/tool";
|
|
|
11
16
|
import { AzureOpenAI as AzureOpenAIClient } from "openai";
|
|
12
17
|
import type {
|
|
13
18
|
ChatCompletionMessageParam as CCMessageParam,
|
|
19
|
+
ChatCompletionChunk,
|
|
14
20
|
ChatCompletionMessageToolCall,
|
|
15
21
|
ChatCompletionTool,
|
|
16
22
|
} from "openai/resources";
|
|
@@ -118,6 +124,58 @@ export class AzureOpenAI extends BaseModel<CCMessageParam, ChatCompletionTool> {
|
|
|
118
124
|
return await this.fetch(messages);
|
|
119
125
|
}
|
|
120
126
|
|
|
127
|
+
async fetchStreamWithContextMessage(
|
|
128
|
+
messages: CCMessageParam[],
|
|
129
|
+
functions: ChatCompletionTool[],
|
|
130
|
+
) {
|
|
131
|
+
const stream = await this.client.chat.completions.create({
|
|
132
|
+
model: this.modelName,
|
|
133
|
+
messages,
|
|
134
|
+
tools: functions,
|
|
135
|
+
tool_choice: "auto",
|
|
136
|
+
stream: true,
|
|
137
|
+
});
|
|
138
|
+
return await this.createOpenAIStreamAdapter(stream);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// NOTE(yoojin): Need to switch API Stream type to LLMStream.
|
|
142
|
+
private createOpenAIStreamAdapter(
|
|
143
|
+
openaiStream: AsyncIterable<ChatCompletionChunk>,
|
|
144
|
+
): LLMStream {
|
|
145
|
+
return {
|
|
146
|
+
async *[Symbol.asyncIterator](): AsyncIterator<StreamChunk> {
|
|
147
|
+
for await (const openaiChunk of openaiStream) {
|
|
148
|
+
const choice = openaiChunk.choices[0];
|
|
149
|
+
if (choice) {
|
|
150
|
+
const streamChunk: StreamChunk = {
|
|
151
|
+
delta: {
|
|
152
|
+
role: choice.delta.role,
|
|
153
|
+
content: choice.delta.content || undefined,
|
|
154
|
+
tool_calls: choice.delta.tool_calls?.map(
|
|
155
|
+
(tc) =>
|
|
156
|
+
({
|
|
157
|
+
index: tc.index,
|
|
158
|
+
id: tc.id,
|
|
159
|
+
type: tc.type,
|
|
160
|
+
function: tc.function,
|
|
161
|
+
}) as ToolCallDelta,
|
|
162
|
+
),
|
|
163
|
+
},
|
|
164
|
+
finish_reason: choice.finish_reason as any,
|
|
165
|
+
metadata: {
|
|
166
|
+
provider: "openai",
|
|
167
|
+
model: openaiChunk.model,
|
|
168
|
+
id: openaiChunk.id,
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
yield streamChunk;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
metadata: { provider: "openai" },
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
121
179
|
convertToolsToFunctions(tools: IAgentTool[]): ChatCompletionTool[] {
|
|
122
180
|
const functions: ChatCompletionTool[] = [];
|
|
123
181
|
for (const tool of tools) {
|
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ainetwork/adk-provider-model-azure",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"author": "AI Network (https://ainetwork.ai)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
7
7
|
"node": ">=20"
|
|
8
8
|
},
|
|
9
|
-
"main": "./dist/
|
|
10
|
-
"module": "./dist/
|
|
11
|
-
"types": "./dist/
|
|
9
|
+
"main": "./dist/index.cjs",
|
|
10
|
+
"module": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
12
|
"exports": {
|
|
13
13
|
".": {
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.js",
|
|
16
|
+
"require": "./dist/index.cjs"
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
19
|
"scripts": {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"clean": "rm -rf dist"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@ainetwork/adk": "^0.1.
|
|
24
|
+
"@ainetwork/adk": "^0.1.7",
|
|
25
25
|
"openai": "^5.10.2"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"publishConfig": {
|
|
32
32
|
"access": "public"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "4098aacea7a18099aa020ef5d331cdce0d59c3f3"
|
|
35
35
|
}
|