@reminix/openai 0.0.18 → 0.0.21
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/README.md +100 -27
- package/dist/chat-agent.d.ts +22 -0
- package/dist/chat-agent.d.ts.map +1 -0
- package/dist/chat-agent.js +59 -0
- package/dist/chat-agent.js.map +1 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/message-utils.d.ts +10 -0
- package/dist/message-utils.d.ts.map +1 -0
- package/dist/message-utils.js +17 -0
- package/dist/message-utils.js.map +1 -0
- package/dist/task-agent.d.ts +23 -0
- package/dist/task-agent.d.ts.map +1 -0
- package/dist/task-agent.js +62 -0
- package/dist/task-agent.js.map +1 -0
- package/package.json +3 -3
- package/dist/agent-adapter.d.ts +0 -98
- package/dist/agent-adapter.d.ts.map +0 -1
- package/dist/agent-adapter.js +0 -145
- package/dist/agent-adapter.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @reminix/openai
|
|
2
2
|
|
|
3
|
-
Reminix
|
|
3
|
+
Reminix agents for the [OpenAI API](https://platform.openai.com/docs). Serve OpenAI models as a REST API with chat, task, and thread agents.
|
|
4
4
|
|
|
5
5
|
> **Ready to go live?** [Deploy to Reminix Cloud](https://reminix.com/docs/deployment) for zero-config hosting, or [self-host](https://reminix.com/docs/deployment/self-hosting) on your own infrastructure.
|
|
6
6
|
|
|
@@ -14,60 +14,127 @@ This will also install `@reminix/runtime` as a dependency.
|
|
|
14
14
|
|
|
15
15
|
## Quick Start
|
|
16
16
|
|
|
17
|
+
### Chat Agent
|
|
18
|
+
|
|
19
|
+
The chat agent follows the chat type and supports streaming responses.
|
|
20
|
+
|
|
17
21
|
```typescript
|
|
18
22
|
import OpenAI from 'openai';
|
|
19
|
-
import {
|
|
23
|
+
import { OpenAIChatAgent } from '@reminix/openai';
|
|
24
|
+
import { serve } from '@reminix/runtime';
|
|
20
25
|
|
|
21
26
|
const client = new OpenAI();
|
|
22
|
-
|
|
27
|
+
const agent = new OpenAIChatAgent(client, { name: 'my-chatbot', model: 'gpt-4o' });
|
|
28
|
+
serve({ agents: [agent] });
|
|
23
29
|
```
|
|
24
30
|
|
|
25
|
-
|
|
31
|
+
### Task Agent
|
|
32
|
+
|
|
33
|
+
The task agent follows the task type and returns structured output. Streaming is not supported.
|
|
26
34
|
|
|
27
35
|
```typescript
|
|
28
36
|
import OpenAI from 'openai';
|
|
29
|
-
import {
|
|
37
|
+
import { OpenAITaskAgent } from '@reminix/openai';
|
|
30
38
|
import { serve } from '@reminix/runtime';
|
|
31
39
|
|
|
40
|
+
const summarySchema = {
|
|
41
|
+
type: 'object',
|
|
42
|
+
properties: {
|
|
43
|
+
title: { type: 'string' },
|
|
44
|
+
bulletPoints: { type: 'array', items: { type: 'string' } },
|
|
45
|
+
},
|
|
46
|
+
required: ['title', 'bulletPoints'],
|
|
47
|
+
};
|
|
48
|
+
|
|
32
49
|
const client = new OpenAI();
|
|
33
|
-
const agent =
|
|
34
|
-
serve({ agents: [agent]
|
|
50
|
+
const agent = new OpenAITaskAgent(client, { outputSchema: summarySchema, name: 'summarizer', model: 'gpt-4o' });
|
|
51
|
+
serve({ agents: [agent] });
|
|
35
52
|
```
|
|
36
53
|
|
|
37
|
-
|
|
38
|
-
|
|
54
|
+
### Thread Agent
|
|
55
|
+
|
|
56
|
+
The thread agent follows the thread type and supports tool use over multiple turns. Streaming is not supported.
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
import OpenAI from 'openai';
|
|
60
|
+
import { OpenAIThreadAgent } from '@reminix/openai';
|
|
61
|
+
import { serve } from '@reminix/runtime';
|
|
62
|
+
|
|
63
|
+
const tools = [
|
|
64
|
+
{
|
|
65
|
+
name: 'get_weather',
|
|
66
|
+
description: 'Get the weather for a location',
|
|
67
|
+
parameters: { type: 'object', properties: { location: { type: 'string' } }, required: ['location'] },
|
|
68
|
+
execute: async ({ location }: { location: string }) => `The weather in ${location} is sunny.`,
|
|
69
|
+
},
|
|
70
|
+
];
|
|
71
|
+
|
|
72
|
+
const client = new OpenAI();
|
|
73
|
+
const agent = new OpenAIThreadAgent(client, { tools, name: 'assistant', model: 'gpt-4o', maxTurns: 10 });
|
|
74
|
+
serve({ agents: [agent] });
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Your agents are now available at:
|
|
78
|
+
- `POST /agents/{name}/invoke` - Execute the agent
|
|
39
79
|
|
|
40
80
|
## API Reference
|
|
41
81
|
|
|
42
|
-
### `
|
|
82
|
+
### `new OpenAIChatAgent(client, options?)`
|
|
43
83
|
|
|
44
|
-
|
|
84
|
+
Create an OpenAI chat agent. Follows the chat type and supports streaming.
|
|
45
85
|
|
|
46
86
|
| Parameter | Type | Default | Description |
|
|
47
87
|
|-----------|------|---------|-------------|
|
|
48
88
|
| `client` | `OpenAI` | required | An OpenAI client |
|
|
49
89
|
| `options.name` | `string` | `"openai-agent"` | Name for the agent (used in URL path) |
|
|
50
90
|
| `options.model` | `string` | `"gpt-4o-mini"` | Model to use for completions |
|
|
51
|
-
| `options.
|
|
52
|
-
| `options.
|
|
91
|
+
| `options.description` | `string` | `"openai chat agent"` | Description shown in agent metadata |
|
|
92
|
+
| `options.instructions` | `string` | — | System instructions prepended to messages |
|
|
93
|
+
| `options.tags` | `string[]` | — | Tags for categorizing/filtering agents |
|
|
94
|
+
| `options.metadata` | `Record<string, unknown>` | — | Custom metadata merged into agent info |
|
|
95
|
+
|
|
96
|
+
**Returns:** `OpenAIChatAgent` - A Reminix chat agent instance
|
|
53
97
|
|
|
54
|
-
### `
|
|
98
|
+
### `new OpenAITaskAgent(client, options)`
|
|
55
99
|
|
|
56
|
-
|
|
100
|
+
Create an OpenAI task agent. Follows the task type and returns structured output. Streaming is not supported.
|
|
57
101
|
|
|
58
102
|
| Parameter | Type | Default | Description |
|
|
59
103
|
|-----------|------|---------|-------------|
|
|
60
104
|
| `client` | `OpenAI` | required | An OpenAI client |
|
|
61
|
-
| `options.
|
|
105
|
+
| `options.outputSchema` | `Record<string, unknown>` | required | JSON Schema defining the structured output |
|
|
106
|
+
| `options.name` | `string` | `"openai-task-agent"` | Name for the agent (used in URL path) |
|
|
107
|
+
| `options.model` | `string` | `"gpt-4o-mini"` | Model to use for completions |
|
|
108
|
+
| `options.description` | `string` | `"openai task agent"` | Description shown in agent metadata |
|
|
109
|
+
| `options.instructions` | `string` | — | System instructions prepended to messages |
|
|
110
|
+
| `options.tags` | `string[]` | — | Tags for categorizing/filtering agents |
|
|
111
|
+
| `options.metadata` | `Record<string, unknown>` | — | Custom metadata merged into agent info |
|
|
112
|
+
|
|
113
|
+
**Returns:** `OpenAITaskAgent` - A Reminix task agent instance
|
|
114
|
+
|
|
115
|
+
### `new OpenAIThreadAgent(client, options)`
|
|
116
|
+
|
|
117
|
+
Create an OpenAI thread agent. Follows the thread type and supports tool use over multiple turns. Streaming is not supported.
|
|
118
|
+
|
|
119
|
+
| Parameter | Type | Default | Description |
|
|
120
|
+
|-----------|------|---------|-------------|
|
|
121
|
+
| `client` | `OpenAI` | required | An OpenAI client |
|
|
122
|
+
| `options.tools` | `Tool[]` | required | A list of tool definitions the agent can call |
|
|
123
|
+
| `options.name` | `string` | `"openai-thread-agent"` | Name for the agent (used in URL path) |
|
|
62
124
|
| `options.model` | `string` | `"gpt-4o-mini"` | Model to use for completions |
|
|
125
|
+
| `options.maxTurns` | `number` | `10` | Maximum number of tool-use turns before stopping |
|
|
126
|
+
| `options.description` | `string` | `"openai thread agent"` | Description shown in agent metadata |
|
|
127
|
+
| `options.instructions` | `string` | — | System instructions prepended to messages |
|
|
128
|
+
| `options.tags` | `string[]` | — | Tags for categorizing/filtering agents |
|
|
129
|
+
| `options.metadata` | `Record<string, unknown>` | — | Custom metadata merged into agent info |
|
|
63
130
|
|
|
64
|
-
**Returns:** `
|
|
131
|
+
**Returns:** `OpenAIThreadAgent` - A Reminix thread agent instance
|
|
65
132
|
|
|
66
133
|
### Example with Custom Configuration
|
|
67
134
|
|
|
68
135
|
```typescript
|
|
69
136
|
import OpenAI from 'openai';
|
|
70
|
-
import {
|
|
137
|
+
import { OpenAIChatAgent } from '@reminix/openai';
|
|
71
138
|
import { serve } from '@reminix/runtime';
|
|
72
139
|
|
|
73
140
|
const client = new OpenAI({
|
|
@@ -75,12 +142,12 @@ const client = new OpenAI({
|
|
|
75
142
|
baseURL: 'https://your-proxy.com/v1', // Optional: custom endpoint
|
|
76
143
|
});
|
|
77
144
|
|
|
78
|
-
const agent =
|
|
145
|
+
const agent = new OpenAIChatAgent(client, {
|
|
79
146
|
name: 'gpt4-agent',
|
|
80
147
|
model: 'gpt-4o',
|
|
81
148
|
});
|
|
82
149
|
|
|
83
|
-
serve({ agents: [agent]
|
|
150
|
+
serve({ agents: [agent] });
|
|
84
151
|
```
|
|
85
152
|
|
|
86
153
|
## Endpoint Input/Output Formats
|
|
@@ -92,17 +159,21 @@ Execute the agent with a prompt or messages.
|
|
|
92
159
|
**Request with prompt:**
|
|
93
160
|
```json
|
|
94
161
|
{
|
|
95
|
-
"
|
|
162
|
+
"input": {
|
|
163
|
+
"prompt": "Summarize this text: ..."
|
|
164
|
+
}
|
|
96
165
|
}
|
|
97
166
|
```
|
|
98
167
|
|
|
99
168
|
**Request with messages:**
|
|
100
169
|
```json
|
|
101
170
|
{
|
|
102
|
-
"
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
171
|
+
"input": {
|
|
172
|
+
"messages": [
|
|
173
|
+
{"role": "system", "content": "You are a helpful assistant."},
|
|
174
|
+
{"role": "user", "content": "Hello!"}
|
|
175
|
+
]
|
|
176
|
+
}
|
|
106
177
|
}
|
|
107
178
|
```
|
|
108
179
|
|
|
@@ -115,11 +186,13 @@ Execute the agent with a prompt or messages.
|
|
|
115
186
|
|
|
116
187
|
### Streaming
|
|
117
188
|
|
|
118
|
-
For streaming responses, set `stream: true` in the request:
|
|
189
|
+
For streaming responses, set `stream: true` in the request (chat agent only):
|
|
119
190
|
|
|
120
191
|
```json
|
|
121
192
|
{
|
|
122
|
-
"
|
|
193
|
+
"input": {
|
|
194
|
+
"prompt": "Tell me a story"
|
|
195
|
+
},
|
|
123
196
|
"stream": true
|
|
124
197
|
}
|
|
125
198
|
```
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI chat agent for Reminix Runtime.
|
|
3
|
+
*/
|
|
4
|
+
import type OpenAI from 'openai';
|
|
5
|
+
import { Agent, type AgentRequest, type AgentResponse } from '@reminix/runtime';
|
|
6
|
+
export interface OpenAIChatAgentOptions {
|
|
7
|
+
name?: string;
|
|
8
|
+
model?: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
instructions?: string;
|
|
11
|
+
tags?: string[];
|
|
12
|
+
metadata?: Record<string, unknown>;
|
|
13
|
+
}
|
|
14
|
+
export declare class OpenAIChatAgent extends Agent {
|
|
15
|
+
private client;
|
|
16
|
+
private _model;
|
|
17
|
+
constructor(client: OpenAI, options?: OpenAIChatAgentOptions);
|
|
18
|
+
get model(): string;
|
|
19
|
+
invoke(request: AgentRequest): Promise<AgentResponse>;
|
|
20
|
+
invokeStream(request: AgentRequest): AsyncGenerator<string, void, unknown>;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=chat-agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-agent.d.ts","sourceRoot":"","sources":["../src/chat-agent.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AAEjC,OAAO,EACL,KAAK,EAGL,KAAK,YAAY,EACjB,KAAK,aAAa,EACnB,MAAM,kBAAkB,CAAC;AAI1B,MAAM,WAAW,sBAAsB;IACrC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,qBAAa,eAAgB,SAAQ,KAAK;IACxC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,MAAM,CAAS;gBAEX,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,sBAA2B;IAgBhE,IAAI,KAAK,IAAI,MAAM,CAElB;IAEK,MAAM,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC;IAgBpD,YAAY,CAAC,OAAO,EAAE,YAAY,GAAG,cAAc,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC;CAoBlF"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI chat agent for Reminix Runtime.
|
|
3
|
+
*/
|
|
4
|
+
import { Agent, AGENT_TYPES, buildMessagesFromInput, } from '@reminix/runtime';
|
|
5
|
+
import { toOpenAIMessage } from './message-utils.js';
|
|
6
|
+
export class OpenAIChatAgent extends Agent {
|
|
7
|
+
client;
|
|
8
|
+
_model;
|
|
9
|
+
constructor(client, options = {}) {
|
|
10
|
+
super(options.name ?? 'openai-agent', {
|
|
11
|
+
description: options.description ?? 'openai chat agent',
|
|
12
|
+
streaming: true,
|
|
13
|
+
inputSchema: AGENT_TYPES['chat'].inputSchema,
|
|
14
|
+
outputSchema: AGENT_TYPES['chat'].outputSchema,
|
|
15
|
+
type: 'chat',
|
|
16
|
+
framework: 'openai',
|
|
17
|
+
instructions: options.instructions,
|
|
18
|
+
tags: options.tags,
|
|
19
|
+
metadata: options.metadata,
|
|
20
|
+
});
|
|
21
|
+
this.client = client;
|
|
22
|
+
this._model = options.model ?? 'gpt-4o-mini';
|
|
23
|
+
}
|
|
24
|
+
get model() {
|
|
25
|
+
return this._model;
|
|
26
|
+
}
|
|
27
|
+
async invoke(request) {
|
|
28
|
+
const messages = buildMessagesFromInput(request);
|
|
29
|
+
const openaiMessages = messages.map((m) => toOpenAIMessage(m));
|
|
30
|
+
if (this.instructions) {
|
|
31
|
+
openaiMessages.unshift({ role: 'system', content: this.instructions });
|
|
32
|
+
}
|
|
33
|
+
const response = await this.client.chat.completions.create({
|
|
34
|
+
model: this._model,
|
|
35
|
+
messages: openaiMessages,
|
|
36
|
+
});
|
|
37
|
+
const output = response.choices[0]?.message?.content ?? '';
|
|
38
|
+
return { output };
|
|
39
|
+
}
|
|
40
|
+
async *invokeStream(request) {
|
|
41
|
+
const messages = buildMessagesFromInput(request);
|
|
42
|
+
const openaiMessages = messages.map((m) => toOpenAIMessage(m));
|
|
43
|
+
if (this.instructions) {
|
|
44
|
+
openaiMessages.unshift({ role: 'system', content: this.instructions });
|
|
45
|
+
}
|
|
46
|
+
const stream = await this.client.chat.completions.create({
|
|
47
|
+
model: this._model,
|
|
48
|
+
messages: openaiMessages,
|
|
49
|
+
stream: true,
|
|
50
|
+
});
|
|
51
|
+
for await (const chunk of stream) {
|
|
52
|
+
const content = chunk.choices[0]?.delta?.content;
|
|
53
|
+
if (content) {
|
|
54
|
+
yield content;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=chat-agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-agent.js","sourceRoot":"","sources":["../src/chat-agent.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EACL,KAAK,EACL,WAAW,EACX,sBAAsB,GAGvB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAWrD,MAAM,OAAO,eAAgB,SAAQ,KAAK;IAChC,MAAM,CAAS;IACf,MAAM,CAAS;IAEvB,YAAY,MAAc,EAAE,UAAkC,EAAE;QAC9D,KAAK,CAAC,OAAO,CAAC,IAAI,I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AAM,EAAE,CAAC;IACpB,CAAC;IAED,KAAK,CAAC,CAAC,YAAY,CAAC,OAAqB;QACvC,MAAM,QAAQ,GAAG,sBAAsB,CAAC,OAAO,CAAC,CAAC;QACjD,MAAM,cAAc,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/D,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACtB,cAAc,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,CAAC,YAAY,EAAE,CAAC,CAAC;QACzE,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC;YACvD,KAAK,EAAE,IAAI,CAAC,MAAM;YAClB,QAAQ,EAAE,cAAc;YACxB,MAAM,EAAE,IAAI;SACb,CAAC,CAAC;QAEH,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YACjC,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC;YACjD,IAAI,OAAO,EAAE,CAAC;gBACZ,MAAM,OAAO,CAAC;YAChB,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export type {
|
|
1
|
+
export { OpenAIChatAgent } from './chat-agent.js';
|
|
2
|
+
export type { OpenAIChatAgentOptions } from './chat-agent.js';
|
|
3
|
+
export { OpenAITaskAgent } from './task-agent.js';
|
|
4
|
+
export type { OpenAITaskAgentOptions } from './task-agent.js';
|
|
5
|
+
export { toOpenAIMessage } from './message-utils.js';
|
|
3
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,YAAY,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,YAAY,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { OpenAIChatAgent } from './chat-agent.js';
|
|
2
|
+
export { OpenAITaskAgent } from './task-agent.js';
|
|
3
|
+
export { toOpenAIMessage } from './message-utils.js';
|
|
2
4
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Message conversion utilities between Reminix and OpenAI formats.
|
|
3
|
+
*/
|
|
4
|
+
import type OpenAI from 'openai';
|
|
5
|
+
import { type Message } from '@reminix/runtime';
|
|
6
|
+
/**
|
|
7
|
+
* Convert a Reminix message to an OpenAI chat completion message.
|
|
8
|
+
*/
|
|
9
|
+
export declare function toOpenAIMessage(message: Message): OpenAI.Chat.ChatCompletionMessageParam;
|
|
10
|
+
//# sourceMappingURL=message-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-utils.d.ts","sourceRoot":"","sources":["../src/message-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AAEjC,OAAO,EAAwB,KAAK,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAEtE;;GAEG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,0BAA0B,CAQxF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Message conversion utilities between Reminix and OpenAI formats.
|
|
3
|
+
*/
|
|
4
|
+
import { messageContentToText } from '@reminix/runtime';
|
|
5
|
+
/**
|
|
6
|
+
* Convert a Reminix message to an OpenAI chat completion message.
|
|
7
|
+
*/
|
|
8
|
+
export function toOpenAIMessage(message) {
|
|
9
|
+
if (message.role !== 'user' && message.role !== 'assistant' && message.role !== 'system')
|
|
10
|
+
return { role: 'user', content: messageContentToText(message.content) };
|
|
11
|
+
const result = {
|
|
12
|
+
role: message.role,
|
|
13
|
+
content: messageContentToText(message.content) || '',
|
|
14
|
+
};
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=message-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-utils.js","sourceRoot":"","sources":["../src/message-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EAAE,oBAAoB,EAAgB,MAAM,kBAAkB,CAAC;AAEtE;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,OAAgB;IAC9C,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,IAAI,OAAO,CAAC,IAAI,KAAK,WAAW,IAAI,OAAO,CAAC,IAAI,KAAK,QAAQ;QACtF,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,oBAAoB,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;IAC1E,MAAM,MAAM,GAA2C;QACrD,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,OAAO,EAAE,oBAAoB,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE;KACrD,CAAC;IACF,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI task agent for Reminix Runtime.
|
|
3
|
+
*/
|
|
4
|
+
import type OpenAI from 'openai';
|
|
5
|
+
import { Agent, type AgentRequest, type AgentResponse } from '@reminix/runtime';
|
|
6
|
+
export interface OpenAITaskAgentOptions {
|
|
7
|
+
outputSchema: Record<string, unknown>;
|
|
8
|
+
name?: string;
|
|
9
|
+
model?: string;
|
|
10
|
+
description?: string;
|
|
11
|
+
instructions?: string;
|
|
12
|
+
tags?: string[];
|
|
13
|
+
metadata?: Record<string, unknown>;
|
|
14
|
+
}
|
|
15
|
+
export declare class OpenAITaskAgent extends Agent {
|
|
16
|
+
private client;
|
|
17
|
+
private _userOutputSchema;
|
|
18
|
+
private _model;
|
|
19
|
+
constructor(client: OpenAI, options: OpenAITaskAgentOptions);
|
|
20
|
+
get model(): string;
|
|
21
|
+
invoke(request: AgentRequest): Promise<AgentResponse>;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=task-agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task-agent.d.ts","sourceRoot":"","sources":["../src/task-agent.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AAEjC,OAAO,EAAE,KAAK,EAAe,KAAK,YAAY,EAAE,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAE7F,MAAM,WAAW,sBAAsB;IACrC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,qBAAa,eAAgB,SAAQ,KAAK;IACxC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,iBAAiB,CAA0B;IACnD,OAAO,CAAC,MAAM,CAAS;gBAEX,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,sBAAsB;IAiB3D,IAAI,KAAK,IAAI,MAAM,CAElB;IAEK,MAAM,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC;CAoC5D"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI task agent for Reminix Runtime.
|
|
3
|
+
*/
|
|
4
|
+
import { Agent, AGENT_TYPES } from '@reminix/runtime';
|
|
5
|
+
export class OpenAITaskAgent extends Agent {
|
|
6
|
+
client;
|
|
7
|
+
_userOutputSchema;
|
|
8
|
+
_model;
|
|
9
|
+
constructor(client, options) {
|
|
10
|
+
super(options.name ?? 'openai-task-agent', {
|
|
11
|
+
description: options.description ?? 'openai task agent',
|
|
12
|
+
streaming: false,
|
|
13
|
+
inputSchema: AGENT_TYPES['task'].inputSchema,
|
|
14
|
+
outputSchema: AGENT_TYPES['task'].outputSchema,
|
|
15
|
+
type: 'task',
|
|
16
|
+
framework: 'openai',
|
|
17
|
+
instructions: options.instructions,
|
|
18
|
+
tags: options.tags,
|
|
19
|
+
metadata: options.metadata,
|
|
20
|
+
});
|
|
21
|
+
this.client = client;
|
|
22
|
+
this._userOutputSchema = options.outputSchema;
|
|
23
|
+
this._model = options.model ?? 'gpt-4o-mini';
|
|
24
|
+
}
|
|
25
|
+
get model() {
|
|
26
|
+
return this._model;
|
|
27
|
+
}
|
|
28
|
+
async invoke(request) {
|
|
29
|
+
const task = request.input.task;
|
|
30
|
+
// Include any additional context from input
|
|
31
|
+
const extra = {};
|
|
32
|
+
for (const [key, value] of Object.entries(request.input)) {
|
|
33
|
+
if (key !== 'task')
|
|
34
|
+
extra[key] = value;
|
|
35
|
+
}
|
|
36
|
+
let prompt = task;
|
|
37
|
+
if (Object.keys(extra).length > 0) {
|
|
38
|
+
prompt += `\n\nContext:\n${JSON.stringify(extra, null, 2)}`;
|
|
39
|
+
}
|
|
40
|
+
const messages = [
|
|
41
|
+
{ role: 'user', content: prompt },
|
|
42
|
+
];
|
|
43
|
+
if (this.instructions) {
|
|
44
|
+
messages.unshift({ role: 'system', content: this.instructions });
|
|
45
|
+
}
|
|
46
|
+
const response = await this.client.chat.completions.create({
|
|
47
|
+
model: this._model,
|
|
48
|
+
messages,
|
|
49
|
+
response_format: {
|
|
50
|
+
type: 'json_schema',
|
|
51
|
+
json_schema: {
|
|
52
|
+
name: 'task_result',
|
|
53
|
+
schema: this._userOutputSchema,
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
const content = response.choices[0]?.message?.content ?? '{}';
|
|
58
|
+
const output = JSON.parse(content);
|
|
59
|
+
return { output };
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=task-agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task-agent.js","sourceRoot":"","sources":["../src/task-agent.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EAAE,KAAK,EAAE,WAAW,EAAyC,MAAM,kBAAkB,CAAC;AAY7F,MAAM,OAAO,eAAgB,SAAQ,KAAK;IAChC,MAAM,CAAS;IACf,iBAAiB,CAA0B;IAC3C,MAAM,CAAS;IAEvB,YAAY,MAAc,EAAE,OAA+B;QACzD,KAAK,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,CAAC;QAED,MAAM,QAAQ,GAA6C;YACzD,EAAE,IAAI,EAAE,MAAe,EAAE,OAAO,EAAE,MAAM,EAAE;SAC3C,CAAC;QACF,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACtB,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,QAAiB,EAAE,OAAO,EAAE,IAAI,CAAC,YAAY,EAAE,CAAC,CAAC;QAC5E,CAAC;QAED,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC;YACzD,KAAK,EAAE,IAAI,CAAC,MAAM;YAClB,QAAQ;YACR,eAAe,EAAE;gBACf,IAAI,EAAE,aAAa;gBACnB,WAAW,EAAE;oBACX,IAAI,EAAE,aAAa;oBACnB,MAAM,EAAE,IAAI,CAAC,iBAAiB;iBAC/B;aAC2D;SAC/D,CAAC,CAAC;QAEH,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,IAAI,IAAI,CAAC;QAC9D,MAAM,MAAM,GAAY,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC5C,OAAO,EAAE,MAAM,EAAE,CAAC;IACpB,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reminix/openai",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "Reminix
|
|
3
|
+
"version": "0.0.21",
|
|
4
|
+
"description": "Reminix agents for OpenAI - serve AI agents as REST APIs",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Reminix Team",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"LICENSE"
|
|
46
46
|
],
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@reminix/runtime": "^0.0.
|
|
48
|
+
"@reminix/runtime": "^0.0.21"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"openai": ">=6.16.0"
|
package/dist/agent-adapter.d.ts
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OpenAI adapter for Reminix Runtime.
|
|
3
|
-
*/
|
|
4
|
-
import type OpenAI from 'openai';
|
|
5
|
-
import { AgentAdapter, type ServeOptions, type AgentInvokeRequest, type AgentInvokeResponse } from '@reminix/runtime';
|
|
6
|
-
/**
|
|
7
|
-
* Options for wrapping an OpenAI client.
|
|
8
|
-
*/
|
|
9
|
-
export interface OpenAIAgentAdapterOptions {
|
|
10
|
-
name?: string;
|
|
11
|
-
model?: string;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Adapter for OpenAI chat completions.
|
|
15
|
-
*/
|
|
16
|
-
export declare class OpenAIAgentAdapter extends AgentAdapter {
|
|
17
|
-
static adapterName: string;
|
|
18
|
-
private client;
|
|
19
|
-
private _name;
|
|
20
|
-
private _model;
|
|
21
|
-
/**
|
|
22
|
-
* Initialize the adapter.
|
|
23
|
-
*
|
|
24
|
-
* @param client - An OpenAI client.
|
|
25
|
-
* @param options - Adapter options.
|
|
26
|
-
*/
|
|
27
|
-
constructor(client: OpenAI, options?: OpenAIAgentAdapterOptions);
|
|
28
|
-
get name(): string;
|
|
29
|
-
get model(): string;
|
|
30
|
-
/**
|
|
31
|
-
* Convert a Reminix message to OpenAI format.
|
|
32
|
-
*/
|
|
33
|
-
private toOpenAIMessage;
|
|
34
|
-
/**
|
|
35
|
-
* Build OpenAI messages from invoke request input.
|
|
36
|
-
*/
|
|
37
|
-
private buildOpenAIMessages;
|
|
38
|
-
/**
|
|
39
|
-
* Handle an invoke request.
|
|
40
|
-
*
|
|
41
|
-
* For both task-oriented and chat-style operations. Expects input with 'messages' key
|
|
42
|
-
* or a 'prompt' key for simple text generation.
|
|
43
|
-
*
|
|
44
|
-
* @param request - The invoke request with input data.
|
|
45
|
-
* @returns The invoke response with the output.
|
|
46
|
-
*/
|
|
47
|
-
invoke(request: AgentInvokeRequest): Promise<AgentInvokeResponse>;
|
|
48
|
-
/**
|
|
49
|
-
* Handle a streaming invoke request.
|
|
50
|
-
*
|
|
51
|
-
* @param request - The invoke request with input data.
|
|
52
|
-
* @yields JSON-encoded chunks from the stream.
|
|
53
|
-
*/
|
|
54
|
-
invokeStream(request: AgentInvokeRequest): AsyncGenerator<string, void, unknown>;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Wrap an OpenAI client for use with Reminix Runtime.
|
|
58
|
-
*
|
|
59
|
-
* @param client - An OpenAI client.
|
|
60
|
-
* @param options - Adapter options.
|
|
61
|
-
* @returns An OpenAIAgentAdapter instance.
|
|
62
|
-
*
|
|
63
|
-
* @example
|
|
64
|
-
* ```typescript
|
|
65
|
-
* import OpenAI from 'openai';
|
|
66
|
-
* import { wrap } from '@reminix/openai';
|
|
67
|
-
* import { serve } from '@reminix/runtime';
|
|
68
|
-
*
|
|
69
|
-
* const client = new OpenAI();
|
|
70
|
-
* const agent = wrapAgent(client, { name: 'my-agent', model: 'gpt-4o' });
|
|
71
|
-
* serve({ agents: [agent], port: 8080 });
|
|
72
|
-
* ```
|
|
73
|
-
*/
|
|
74
|
-
export declare function wrapAgent(client: OpenAI, options?: OpenAIAgentAdapterOptions): OpenAIAgentAdapter;
|
|
75
|
-
/**
|
|
76
|
-
* Options for wrapping and serving an OpenAI client.
|
|
77
|
-
*/
|
|
78
|
-
export interface WrapAndServeOptions extends OpenAIAgentAdapterOptions, ServeOptions {
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Wrap an OpenAI client and serve it immediately.
|
|
82
|
-
*
|
|
83
|
-
* This is a convenience function that combines `wrapAgent` and `serve` for single-agent setups.
|
|
84
|
-
*
|
|
85
|
-
* @param client - An OpenAI client.
|
|
86
|
-
* @param options - Combined adapter and server options.
|
|
87
|
-
*
|
|
88
|
-
* @example
|
|
89
|
-
* ```typescript
|
|
90
|
-
* import OpenAI from 'openai';
|
|
91
|
-
* import { serveAgent } from '@reminix/openai';
|
|
92
|
-
*
|
|
93
|
-
* const client = new OpenAI();
|
|
94
|
-
* serveAgent(client, { name: 'my-agent', model: 'gpt-4o', port: 8080 });
|
|
95
|
-
* ```
|
|
96
|
-
*/
|
|
97
|
-
export declare function serveAgent(client: OpenAI, options?: WrapAndServeOptions): void;
|
|
98
|
-
//# sourceMappingURL=agent-adapter.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"agent-adapter.d.ts","sourceRoot":"","sources":["../src/agent-adapter.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AAEjC,OAAO,EACL,YAAY,EAGZ,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EAEzB,MAAM,kBAAkB,CAAC;AAE1B;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,YAAY;IAClD,MAAM,CAAC,WAAW,SAAY;IAE9B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,MAAM,CAAS;IAEvB;;;;;OAKG;gBACS,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,yBAA8B;IAOnE,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,KAAK,IAAI,MAAM,CAElB;IAED;;OAEG;IACH,OAAO,CAAC,eAAe;IAWvB;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAe3B;;;;;;;;OAQG;IACG,MAAM,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAevE;;;;;OAKG;IACI,YAAY,CAAC,OAAO,EAAE,kBAAkB,GAAG,cAAc,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC;CAiBxF;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,SAAS,CACvB,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,yBAA8B,GACtC,kBAAkB,CAEpB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAoB,SAAQ,yBAAyB,EAAE,YAAY;CAAG;AAEvF;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAwB,GAAG,IAAI,CAIlF"}
|
package/dist/agent-adapter.js
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OpenAI adapter for Reminix Runtime.
|
|
3
|
-
*/
|
|
4
|
-
import { AgentAdapter, serve, messageContentToText, } from '@reminix/runtime';
|
|
5
|
-
/**
|
|
6
|
-
* Adapter for OpenAI chat completions.
|
|
7
|
-
*/
|
|
8
|
-
export class OpenAIAgentAdapter extends AgentAdapter {
|
|
9
|
-
static adapterName = 'openai';
|
|
10
|
-
client;
|
|
11
|
-
_name;
|
|
12
|
-
_model;
|
|
13
|
-
/**
|
|
14
|
-
* Initialize the adapter.
|
|
15
|
-
*
|
|
16
|
-
* @param client - An OpenAI client.
|
|
17
|
-
* @param options - Adapter options.
|
|
18
|
-
*/
|
|
19
|
-
constructor(client, options = {}) {
|
|
20
|
-
super();
|
|
21
|
-
this.client = client;
|
|
22
|
-
this._name = options.name ?? 'openai-agent';
|
|
23
|
-
this._model = options.model ?? 'gpt-4o-mini';
|
|
24
|
-
}
|
|
25
|
-
get name() {
|
|
26
|
-
return this._name;
|
|
27
|
-
}
|
|
28
|
-
get model() {
|
|
29
|
-
return this._model;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Convert a Reminix message to OpenAI format.
|
|
33
|
-
*/
|
|
34
|
-
toOpenAIMessage(message) {
|
|
35
|
-
const role = message.role === 'developer' ? 'system' : message.role;
|
|
36
|
-
if (role !== 'user' && role !== 'assistant' && role !== 'system')
|
|
37
|
-
return { role: 'user', content: messageContentToText(message.content) };
|
|
38
|
-
const result = {
|
|
39
|
-
role,
|
|
40
|
-
content: messageContentToText(message.content) || '',
|
|
41
|
-
};
|
|
42
|
-
return result;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Build OpenAI messages from invoke request input.
|
|
46
|
-
*/
|
|
47
|
-
buildOpenAIMessages(request) {
|
|
48
|
-
const input = request.input;
|
|
49
|
-
if ('messages' in input) {
|
|
50
|
-
const messages = input.messages;
|
|
51
|
-
return messages.map((m) => this.toOpenAIMessage(m));
|
|
52
|
-
}
|
|
53
|
-
else if ('prompt' in input) {
|
|
54
|
-
return [{ role: 'user', content: String(input.prompt) }];
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
return [{ role: 'user', content: JSON.stringify(input) }];
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Handle an invoke request.
|
|
62
|
-
*
|
|
63
|
-
* For both task-oriented and chat-style operations. Expects input with 'messages' key
|
|
64
|
-
* or a 'prompt' key for simple text generation.
|
|
65
|
-
*
|
|
66
|
-
* @param request - The invoke request with input data.
|
|
67
|
-
* @returns The invoke response with the output.
|
|
68
|
-
*/
|
|
69
|
-
async invoke(request) {
|
|
70
|
-
const messages = this.buildOpenAIMessages(request);
|
|
71
|
-
// Call OpenAI API
|
|
72
|
-
const response = await this.client.chat.completions.create({
|
|
73
|
-
model: this._model,
|
|
74
|
-
messages,
|
|
75
|
-
});
|
|
76
|
-
// Extract content from response
|
|
77
|
-
const output = response.choices[0]?.message?.content ?? '';
|
|
78
|
-
return { output };
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Handle a streaming invoke request.
|
|
82
|
-
*
|
|
83
|
-
* @param request - The invoke request with input data.
|
|
84
|
-
* @yields JSON-encoded chunks from the stream.
|
|
85
|
-
*/
|
|
86
|
-
async *invokeStream(request) {
|
|
87
|
-
const messages = this.buildOpenAIMessages(request);
|
|
88
|
-
// Stream from OpenAI API
|
|
89
|
-
const stream = await this.client.chat.completions.create({
|
|
90
|
-
model: this._model,
|
|
91
|
-
messages,
|
|
92
|
-
stream: true,
|
|
93
|
-
});
|
|
94
|
-
for await (const chunk of stream) {
|
|
95
|
-
const content = chunk.choices[0]?.delta?.content;
|
|
96
|
-
if (content) {
|
|
97
|
-
yield JSON.stringify({ chunk: content });
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Wrap an OpenAI client for use with Reminix Runtime.
|
|
104
|
-
*
|
|
105
|
-
* @param client - An OpenAI client.
|
|
106
|
-
* @param options - Adapter options.
|
|
107
|
-
* @returns An OpenAIAgentAdapter instance.
|
|
108
|
-
*
|
|
109
|
-
* @example
|
|
110
|
-
* ```typescript
|
|
111
|
-
* import OpenAI from 'openai';
|
|
112
|
-
* import { wrap } from '@reminix/openai';
|
|
113
|
-
* import { serve } from '@reminix/runtime';
|
|
114
|
-
*
|
|
115
|
-
* const client = new OpenAI();
|
|
116
|
-
* const agent = wrapAgent(client, { name: 'my-agent', model: 'gpt-4o' });
|
|
117
|
-
* serve({ agents: [agent], port: 8080 });
|
|
118
|
-
* ```
|
|
119
|
-
*/
|
|
120
|
-
export function wrapAgent(client, options = {}) {
|
|
121
|
-
return new OpenAIAgentAdapter(client, options);
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Wrap an OpenAI client and serve it immediately.
|
|
125
|
-
*
|
|
126
|
-
* This is a convenience function that combines `wrapAgent` and `serve` for single-agent setups.
|
|
127
|
-
*
|
|
128
|
-
* @param client - An OpenAI client.
|
|
129
|
-
* @param options - Combined adapter and server options.
|
|
130
|
-
*
|
|
131
|
-
* @example
|
|
132
|
-
* ```typescript
|
|
133
|
-
* import OpenAI from 'openai';
|
|
134
|
-
* import { serveAgent } from '@reminix/openai';
|
|
135
|
-
*
|
|
136
|
-
* const client = new OpenAI();
|
|
137
|
-
* serveAgent(client, { name: 'my-agent', model: 'gpt-4o', port: 8080 });
|
|
138
|
-
* ```
|
|
139
|
-
*/
|
|
140
|
-
export function serveAgent(client, options = {}) {
|
|
141
|
-
const { port, hostname, ...adapterOptions } = options;
|
|
142
|
-
const agent = wrapAgent(client, adapterOptions);
|
|
143
|
-
serve({ agents: [agent], port, hostname });
|
|
144
|
-
}
|
|
145
|
-
//# sourceMappingURL=agent-adapter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"agent-adapter.js","sourceRoot":"","sources":["../src/agent-adapter.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EACL,YAAY,EACZ,KAAK,EACL,oBAAoB,GAKrB,MAAM,kBAAkB,CAAC;AAU1B;;GAEG;AACH,MAAM,OAAO,kBAAmB,SAAQ,YAAY;IAClD,MAAM,CAAC,WAAW,GAAG,QAAQ,CAAC;IAEtB,MAAM,CAAS;IACf,KAAK,CAAS;IACd,MAAM,CAAS;IAEvB;;;;;OAKG;IACH,YAAY,MAAc,EAAE,UAAqC,EAAE;QACjE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,IAAI,IAAI,cAAc,CAAC;QAC5C,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,KAAK,IAAI,aAAa,CAAC;IAC/C,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;OAEG;IACK,eAAe,CAAC,OAAgB;QACtC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC;QACpE,IAAI,IAAI,KAAK,MAAM,IAA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