ai.matey.wrapper 0.2.0
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/LICENSE +21 -0
- package/dist/cjs/anthropic-sdk.js +203 -0
- package/dist/cjs/anthropic-sdk.js.map +1 -0
- package/dist/cjs/anymethod.js +167 -0
- package/dist/cjs/anymethod.js.map +1 -0
- package/dist/cjs/chat.js +513 -0
- package/dist/cjs/chat.js.map +1 -0
- package/dist/cjs/chrome-ai-legacy.js +168 -0
- package/dist/cjs/chrome-ai-legacy.js.map +1 -0
- package/dist/cjs/chrome-ai.js +156 -0
- package/dist/cjs/chrome-ai.js.map +1 -0
- package/dist/cjs/index.js +58 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/ir-index.js +52 -0
- package/dist/cjs/ir-index.js.map +1 -0
- package/dist/cjs/openai-sdk.js +221 -0
- package/dist/cjs/openai-sdk.js.map +1 -0
- package/dist/cjs/stream-utils.js +21 -0
- package/dist/cjs/stream-utils.js.map +1 -0
- package/dist/cjs/types.js +10 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/esm/anthropic-sdk.js +196 -0
- package/dist/esm/anthropic-sdk.js.map +1 -0
- package/dist/esm/anymethod.js +161 -0
- package/dist/esm/anymethod.js.map +1 -0
- package/dist/esm/chat.js +508 -0
- package/dist/esm/chat.js.map +1 -0
- package/dist/esm/chrome-ai-legacy.js +163 -0
- package/dist/esm/chrome-ai-legacy.js.map +1 -0
- package/dist/esm/chrome-ai.js +152 -0
- package/dist/esm/chrome-ai.js.map +1 -0
- package/dist/esm/index.js +22 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/ir-index.js +41 -0
- package/dist/esm/ir-index.js.map +1 -0
- package/dist/esm/openai-sdk.js +213 -0
- package/dist/esm/openai-sdk.js.map +1 -0
- package/dist/esm/stream-utils.js +14 -0
- package/dist/esm/stream-utils.js.map +1 -0
- package/dist/esm/types.js +9 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/types/anthropic-sdk.d.ts +154 -0
- package/dist/types/anthropic-sdk.d.ts.map +1 -0
- package/dist/types/anymethod.d.ts +45 -0
- package/dist/types/anymethod.d.ts.map +1 -0
- package/dist/types/chat.d.ts +144 -0
- package/dist/types/chat.d.ts.map +1 -0
- package/dist/types/chrome-ai-legacy.d.ts +44 -0
- package/dist/types/chrome-ai-legacy.d.ts.map +1 -0
- package/dist/types/chrome-ai.d.ts +38 -0
- package/dist/types/chrome-ai.d.ts.map +1 -0
- package/dist/types/index.d.ts +20 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/ir-index.d.ts +41 -0
- package/dist/types/ir-index.d.ts.map +1 -0
- package/dist/types/openai-sdk.d.ts +183 -0
- package/dist/types/openai-sdk.d.ts.map +1 -0
- package/dist/types/stream-utils.d.ts +9 -0
- package/dist/types/stream-utils.d.ts.map +1 -0
- package/dist/types/types.d.ts +232 -0
- package/dist/types/types.d.ts.map +1 -0
- package/package.json +132 -0
- package/readme.md +92 -0
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Headless Chat Client Types
|
|
3
|
+
*
|
|
4
|
+
* Type definitions for the framework-agnostic chat client.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import type { IRMessage, IRChatResponse, IRStreamChunk, IRUsage, IRParameters, IRTool } from 'ai.matey.types';
|
|
9
|
+
/**
|
|
10
|
+
* Configuration options for creating a chat instance.
|
|
11
|
+
*/
|
|
12
|
+
export interface ChatConfig {
|
|
13
|
+
/**
|
|
14
|
+
* The Bridge or BackendAdapter to use for requests.
|
|
15
|
+
* Can be either a Bridge instance or a raw BackendAdapter.
|
|
16
|
+
*/
|
|
17
|
+
readonly backend: ChatBackend;
|
|
18
|
+
/**
|
|
19
|
+
* System prompt to prepend to all conversations.
|
|
20
|
+
* Can be a string or a function that returns a string (for dynamic prompts).
|
|
21
|
+
*/
|
|
22
|
+
readonly systemPrompt?: string | (() => string | Promise<string>);
|
|
23
|
+
/**
|
|
24
|
+
* Maximum number of messages to keep in history.
|
|
25
|
+
* Older messages are dropped when limit is exceeded.
|
|
26
|
+
* @default 100
|
|
27
|
+
*/
|
|
28
|
+
readonly historyLimit?: number;
|
|
29
|
+
/**
|
|
30
|
+
* Default parameters for all requests.
|
|
31
|
+
* Can be overridden per-request.
|
|
32
|
+
*/
|
|
33
|
+
readonly defaultParameters?: IRParameters;
|
|
34
|
+
/**
|
|
35
|
+
* Available tools for the conversation.
|
|
36
|
+
*/
|
|
37
|
+
readonly tools?: readonly IRTool[];
|
|
38
|
+
/**
|
|
39
|
+
* Called when a tool needs to be executed.
|
|
40
|
+
* If not provided, tool calls will be included in responses but not executed.
|
|
41
|
+
*/
|
|
42
|
+
readonly onToolCall?: ToolCallHandler;
|
|
43
|
+
/**
|
|
44
|
+
* Auto-execute tool calls and continue the conversation.
|
|
45
|
+
* Requires onToolCall to be set.
|
|
46
|
+
* @default false
|
|
47
|
+
*/
|
|
48
|
+
readonly autoExecuteTools?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Maximum number of consecutive tool call rounds.
|
|
51
|
+
* Prevents infinite loops when autoExecuteTools is enabled.
|
|
52
|
+
* @default 10
|
|
53
|
+
*/
|
|
54
|
+
readonly maxToolRounds?: number;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Backend interface - either a Bridge or BackendAdapter.
|
|
58
|
+
* Both have execute() and executeStream() methods.
|
|
59
|
+
*/
|
|
60
|
+
export interface ChatBackend {
|
|
61
|
+
execute(request: import('ai.matey.types').IRChatRequest, signal?: AbortSignal): Promise<IRChatResponse>;
|
|
62
|
+
executeStream?(request: import('ai.matey.types').IRChatRequest, signal?: AbortSignal): AsyncGenerator<IRStreamChunk, void, undefined>;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Handler for tool calls.
|
|
66
|
+
*/
|
|
67
|
+
export type ToolCallHandler = (toolName: string, toolInput: Record<string, unknown>, toolId: string) => Promise<string | {
|
|
68
|
+
content: string;
|
|
69
|
+
isError?: boolean;
|
|
70
|
+
}>;
|
|
71
|
+
/**
|
|
72
|
+
* Options for a single chat request.
|
|
73
|
+
*/
|
|
74
|
+
export interface SendOptions {
|
|
75
|
+
/**
|
|
76
|
+
* Override default parameters for this request.
|
|
77
|
+
*/
|
|
78
|
+
readonly parameters?: IRParameters;
|
|
79
|
+
/**
|
|
80
|
+
* AbortSignal to cancel the request.
|
|
81
|
+
*/
|
|
82
|
+
readonly signal?: AbortSignal;
|
|
83
|
+
/**
|
|
84
|
+
* Custom metadata to include in the request.
|
|
85
|
+
*/
|
|
86
|
+
readonly metadata?: Record<string, unknown>;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Options for streaming requests.
|
|
90
|
+
*/
|
|
91
|
+
export interface StreamOptions extends SendOptions {
|
|
92
|
+
/**
|
|
93
|
+
* Called for each content chunk.
|
|
94
|
+
*/
|
|
95
|
+
readonly onChunk?: (chunk: StreamChunkEvent) => void;
|
|
96
|
+
/**
|
|
97
|
+
* Called when streaming starts.
|
|
98
|
+
*/
|
|
99
|
+
readonly onStart?: (metadata: {
|
|
100
|
+
requestId: string;
|
|
101
|
+
}) => void;
|
|
102
|
+
/**
|
|
103
|
+
* Called when streaming completes.
|
|
104
|
+
*/
|
|
105
|
+
readonly onDone?: (response: ChatResponse) => void;
|
|
106
|
+
/**
|
|
107
|
+
* Called on error.
|
|
108
|
+
*/
|
|
109
|
+
readonly onError?: (error: Error) => void;
|
|
110
|
+
/**
|
|
111
|
+
* Called for tool use chunks.
|
|
112
|
+
*/
|
|
113
|
+
readonly onToolUse?: (tool: {
|
|
114
|
+
id: string;
|
|
115
|
+
name: string;
|
|
116
|
+
input: string;
|
|
117
|
+
}) => void;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Simplified chat response.
|
|
121
|
+
*/
|
|
122
|
+
export interface ChatResponse {
|
|
123
|
+
/**
|
|
124
|
+
* The assistant's response content as a string.
|
|
125
|
+
*/
|
|
126
|
+
readonly content: string;
|
|
127
|
+
/**
|
|
128
|
+
* The full message object.
|
|
129
|
+
*/
|
|
130
|
+
readonly message: IRMessage;
|
|
131
|
+
/**
|
|
132
|
+
* Why generation stopped.
|
|
133
|
+
*/
|
|
134
|
+
readonly finishReason: IRChatResponse['finishReason'];
|
|
135
|
+
/**
|
|
136
|
+
* Token usage for this response.
|
|
137
|
+
*/
|
|
138
|
+
readonly usage?: IRUsage;
|
|
139
|
+
/**
|
|
140
|
+
* Tool calls in the response, if any.
|
|
141
|
+
*/
|
|
142
|
+
readonly toolCalls?: readonly ToolCall[];
|
|
143
|
+
/**
|
|
144
|
+
* Request ID for correlation.
|
|
145
|
+
*/
|
|
146
|
+
readonly requestId: string;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Tool call extracted from response.
|
|
150
|
+
*/
|
|
151
|
+
export interface ToolCall {
|
|
152
|
+
readonly id: string;
|
|
153
|
+
readonly name: string;
|
|
154
|
+
readonly input: Record<string, unknown>;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Stream chunk event for callbacks.
|
|
158
|
+
*/
|
|
159
|
+
export interface StreamChunkEvent {
|
|
160
|
+
/**
|
|
161
|
+
* The delta content (new text only).
|
|
162
|
+
*/
|
|
163
|
+
readonly delta: string;
|
|
164
|
+
/**
|
|
165
|
+
* Accumulated content so far.
|
|
166
|
+
*/
|
|
167
|
+
readonly accumulated: string;
|
|
168
|
+
/**
|
|
169
|
+
* Chunk sequence number.
|
|
170
|
+
*/
|
|
171
|
+
readonly sequence: number;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Conversation state snapshot.
|
|
175
|
+
*/
|
|
176
|
+
export interface ConversationState {
|
|
177
|
+
/**
|
|
178
|
+
* All messages in the conversation.
|
|
179
|
+
*/
|
|
180
|
+
readonly messages: readonly IRMessage[];
|
|
181
|
+
/**
|
|
182
|
+
* Whether a request is currently in progress.
|
|
183
|
+
*/
|
|
184
|
+
readonly isLoading: boolean;
|
|
185
|
+
/**
|
|
186
|
+
* Current error, if any.
|
|
187
|
+
*/
|
|
188
|
+
readonly error: Error | null;
|
|
189
|
+
/**
|
|
190
|
+
* Cumulative token usage across the conversation.
|
|
191
|
+
*/
|
|
192
|
+
readonly totalUsage: {
|
|
193
|
+
readonly promptTokens: number;
|
|
194
|
+
readonly completionTokens: number;
|
|
195
|
+
readonly totalTokens: number;
|
|
196
|
+
};
|
|
197
|
+
/**
|
|
198
|
+
* Number of requests made.
|
|
199
|
+
*/
|
|
200
|
+
readonly requestCount: number;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Event types emitted by the chat instance.
|
|
204
|
+
*/
|
|
205
|
+
export type ChatEventType = 'message' | 'stream-start' | 'stream-chunk' | 'stream-done' | 'error' | 'state-change';
|
|
206
|
+
/**
|
|
207
|
+
* Event listener callback.
|
|
208
|
+
*/
|
|
209
|
+
export type ChatEventListener<T = unknown> = (event: T) => void;
|
|
210
|
+
/**
|
|
211
|
+
* Event data for each event type.
|
|
212
|
+
*/
|
|
213
|
+
export interface ChatEvents {
|
|
214
|
+
message: {
|
|
215
|
+
message: IRMessage;
|
|
216
|
+
response: ChatResponse;
|
|
217
|
+
};
|
|
218
|
+
'stream-start': {
|
|
219
|
+
requestId: string;
|
|
220
|
+
};
|
|
221
|
+
'stream-chunk': StreamChunkEvent;
|
|
222
|
+
'stream-done': {
|
|
223
|
+
response: ChatResponse;
|
|
224
|
+
};
|
|
225
|
+
error: {
|
|
226
|
+
error: Error;
|
|
227
|
+
};
|
|
228
|
+
'state-change': {
|
|
229
|
+
state: ConversationState;
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAA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AAO,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;AAEhE;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE;QAAE,OAAO,EAAE,SAAS,CAAC;QAAC,QAAQ,EAAE,YAAY,CAAA;KAAE,CAAC;IACxD,cAAc,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IACtC,cAAc,EAAE,gBAAgB,CAAC;IACjC,aAAa,EAAE;QAAE,QAAQ,EAAE,YAAY,CAAA;KAAE,CAAC;IAC1C,KAAK,EAAE;QAAE,KAAK,EAAE,KAAK,CAAA;KAAE,CAAC;IACxB,cAAc,EAAE;QAAE,KAAK,EAAE,iBAAiB,CAAA;KAAE,CAAC;CAC9C"}
|
package/package.json
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ai.matey.wrapper",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "SDK wrappers for AI Matey - Use familiar SDK patterns with any provider",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/cjs/index.js",
|
|
7
|
+
"module": "./dist/esm/index.js",
|
|
8
|
+
"types": "./dist/types/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/types/index.d.ts",
|
|
13
|
+
"default": "./dist/esm/index.js"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/types/index.d.ts",
|
|
17
|
+
"default": "./dist/cjs/index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"./openai": {
|
|
21
|
+
"import": {
|
|
22
|
+
"types": "./dist/types/openai-sdk.d.ts",
|
|
23
|
+
"default": "./dist/esm/openai-sdk.js"
|
|
24
|
+
},
|
|
25
|
+
"require": {
|
|
26
|
+
"types": "./dist/types/openai-sdk.d.ts",
|
|
27
|
+
"default": "./dist/cjs/openai-sdk.js"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"./anthropic": {
|
|
31
|
+
"import": {
|
|
32
|
+
"types": "./dist/types/anthropic-sdk.d.ts",
|
|
33
|
+
"default": "./dist/esm/anthropic-sdk.js"
|
|
34
|
+
},
|
|
35
|
+
"require": {
|
|
36
|
+
"types": "./dist/types/anthropic-sdk.d.ts",
|
|
37
|
+
"default": "./dist/cjs/anthropic-sdk.js"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"./ir": {
|
|
41
|
+
"import": {
|
|
42
|
+
"types": "./dist/types/ir-index.d.ts",
|
|
43
|
+
"default": "./dist/esm/ir-index.js"
|
|
44
|
+
},
|
|
45
|
+
"require": {
|
|
46
|
+
"types": "./dist/types/ir-index.d.ts",
|
|
47
|
+
"default": "./dist/cjs/ir-index.js"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"./chrome-ai": {
|
|
51
|
+
"import": {
|
|
52
|
+
"types": "./dist/types/chrome-ai.d.ts",
|
|
53
|
+
"default": "./dist/esm/chrome-ai.js"
|
|
54
|
+
},
|
|
55
|
+
"require": {
|
|
56
|
+
"types": "./dist/types/chrome-ai.d.ts",
|
|
57
|
+
"default": "./dist/cjs/chrome-ai.js"
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"./chat": {
|
|
61
|
+
"import": {
|
|
62
|
+
"types": "./dist/types/chat.d.ts",
|
|
63
|
+
"default": "./dist/esm/chat.js"
|
|
64
|
+
},
|
|
65
|
+
"require": {
|
|
66
|
+
"types": "./dist/types/chat.d.ts",
|
|
67
|
+
"default": "./dist/cjs/chat.js"
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
"./anymethod": {
|
|
71
|
+
"import": {
|
|
72
|
+
"types": "./dist/types/anymethod.d.ts",
|
|
73
|
+
"default": "./dist/esm/anymethod.js"
|
|
74
|
+
},
|
|
75
|
+
"require": {
|
|
76
|
+
"types": "./dist/types/anymethod.d.ts",
|
|
77
|
+
"default": "./dist/cjs/anymethod.js"
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
"files": [
|
|
82
|
+
"dist",
|
|
83
|
+
"readme.md",
|
|
84
|
+
"CHANGELOG.md",
|
|
85
|
+
"LICENSE"
|
|
86
|
+
],
|
|
87
|
+
"scripts": {
|
|
88
|
+
"build": "npm run build:esm && npm run build:cjs && npm run build:types",
|
|
89
|
+
"build:esm": "tsc -p tsconfig.esm.json",
|
|
90
|
+
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
91
|
+
"build:types": "tsc -p tsconfig.types.json",
|
|
92
|
+
"clean": "rm -rf dist",
|
|
93
|
+
"typecheck": "tsc --noEmit",
|
|
94
|
+
"lint": "eslint src --ext .ts",
|
|
95
|
+
"lint:fix": "eslint src --ext .ts --fix",
|
|
96
|
+
"test": "vitest run",
|
|
97
|
+
"test:watch": "vitest"
|
|
98
|
+
},
|
|
99
|
+
"dependencies": {
|
|
100
|
+
"ai.matey.types": "*",
|
|
101
|
+
"ai.matey.utils": "*",
|
|
102
|
+
"ai.matey.frontend": "*"
|
|
103
|
+
},
|
|
104
|
+
"devDependencies": {
|
|
105
|
+
"ai.matey.testing": "*",
|
|
106
|
+
"typescript": "^5.9.3",
|
|
107
|
+
"vitest": "^3.2.4"
|
|
108
|
+
},
|
|
109
|
+
"keywords": [
|
|
110
|
+
"ai",
|
|
111
|
+
"llm",
|
|
112
|
+
"wrapper",
|
|
113
|
+
"openai",
|
|
114
|
+
"anthropic",
|
|
115
|
+
"sdk",
|
|
116
|
+
"ai-matey"
|
|
117
|
+
],
|
|
118
|
+
"author": "AI Matey",
|
|
119
|
+
"license": "MIT",
|
|
120
|
+
"homepage": "https://github.com/johnhenry/ai.matey#readme",
|
|
121
|
+
"bugs": {
|
|
122
|
+
"url": "https://github.com/johnhenry/ai.matey/issues"
|
|
123
|
+
},
|
|
124
|
+
"repository": {
|
|
125
|
+
"type": "git",
|
|
126
|
+
"url": "git+https://github.com/johnhenry/ai.matey.git",
|
|
127
|
+
"directory": "packages/wrapper"
|
|
128
|
+
},
|
|
129
|
+
"engines": {
|
|
130
|
+
"node": ">=18.0.0"
|
|
131
|
+
}
|
|
132
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# ai.matey.wrapper
|
|
2
|
+
|
|
3
|
+
SDK wrappers and utilities for AI Matey - Universal AI Adapter System.
|
|
4
|
+
|
|
5
|
+
Part of the [ai.matey](https://github.com/johnhenry/ai.matey) monorepo.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install ai.matey.wrapper
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Overview
|
|
14
|
+
|
|
15
|
+
This package provides SDK-compatible wrappers that let you use familiar SDK patterns (like OpenAI's or Anthropic's) with any AI Matey backend. It also includes IR-native chat utilities for direct usage.
|
|
16
|
+
|
|
17
|
+
## Included Components
|
|
18
|
+
|
|
19
|
+
### SDK Wrappers
|
|
20
|
+
- **OpenAI SDK Wrapper** - Use OpenAI SDK patterns with any backend
|
|
21
|
+
- **Anthropic SDK Wrapper** - Use Anthropic SDK patterns with any backend
|
|
22
|
+
- **Chrome AI Wrapper** - Simplified Chrome AI interface
|
|
23
|
+
- **AnyMethod Wrapper** - Flexible method-based wrapper
|
|
24
|
+
|
|
25
|
+
### IR Utilities
|
|
26
|
+
- **Chat** - High-level chat interface with conversation management
|
|
27
|
+
- **Stream Utilities** - Stream processing helpers
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
### OpenAI SDK Wrapper
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { OpenAI } from 'ai.matey.wrapper';
|
|
35
|
+
|
|
36
|
+
const client = new OpenAI({ backend: yourBackend });
|
|
37
|
+
|
|
38
|
+
const response = await client.chat.completions.create({
|
|
39
|
+
model: 'gpt-4',
|
|
40
|
+
messages: [{ role: 'user', content: 'Hello!' }],
|
|
41
|
+
});
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Anthropic SDK Wrapper
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
import { Anthropic } from 'ai.matey.wrapper';
|
|
48
|
+
|
|
49
|
+
const client = new Anthropic({ backend: yourBackend });
|
|
50
|
+
|
|
51
|
+
const response = await client.messages.create({
|
|
52
|
+
model: 'claude-3-opus',
|
|
53
|
+
messages: [{ role: 'user', content: 'Hello!' }],
|
|
54
|
+
max_tokens: 1024,
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### IR Chat Interface
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
import { Chat, createChat } from 'ai.matey.wrapper';
|
|
62
|
+
|
|
63
|
+
const chat = createChat({ backend: yourBackend });
|
|
64
|
+
|
|
65
|
+
// Send a message
|
|
66
|
+
const response = await chat.send('Hello!');
|
|
67
|
+
|
|
68
|
+
// Stream a response
|
|
69
|
+
for await (const chunk of chat.stream('Tell me a story')) {
|
|
70
|
+
process.stdout.write(chunk.delta);
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Stream Utilities
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
import { collectStream, streamToText } from 'ai.matey.wrapper';
|
|
78
|
+
|
|
79
|
+
// Collect all chunks from a stream
|
|
80
|
+
const collected = await collectStream(stream);
|
|
81
|
+
|
|
82
|
+
// Convert stream to text
|
|
83
|
+
const text = await streamToText(stream);
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## API Reference
|
|
87
|
+
|
|
88
|
+
See the TypeScript definitions for detailed API documentation.
|
|
89
|
+
|
|
90
|
+
## License
|
|
91
|
+
|
|
92
|
+
MIT - see [LICENSE](./LICENSE) for details.
|