@reminix/openai 0.0.7 → 0.0.8
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 +15 -31
- package/dist/agent-adapter.d.ts +12 -24
- package/dist/agent-adapter.d.ts.map +1 -1
- package/dist/agent-adapter.js +19 -72
- package/dist/agent-adapter.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -35,8 +35,7 @@ serve({ agents: [agent], port: 8080 });
|
|
|
35
35
|
```
|
|
36
36
|
|
|
37
37
|
Your agent is now available at:
|
|
38
|
-
- `POST /agents/my-chatbot/
|
|
39
|
-
- `POST /agents/my-chatbot/chat` - Conversational chat
|
|
38
|
+
- `POST /agents/my-chatbot/execute` - Execute the agent
|
|
40
39
|
|
|
41
40
|
## API Reference
|
|
42
41
|
|
|
@@ -86,28 +85,24 @@ serve({ agents: [agent], port: 8080 });
|
|
|
86
85
|
|
|
87
86
|
## Endpoint Input/Output Formats
|
|
88
87
|
|
|
89
|
-
### POST /agents/{name}/
|
|
88
|
+
### POST /agents/{name}/execute
|
|
90
89
|
|
|
91
|
-
|
|
90
|
+
Execute the agent with a prompt or messages.
|
|
92
91
|
|
|
93
|
-
**Request:**
|
|
92
|
+
**Request with prompt:**
|
|
94
93
|
```json
|
|
95
94
|
{
|
|
96
|
-
"
|
|
97
|
-
"prompt": "Summarize this text: ..."
|
|
98
|
-
}
|
|
95
|
+
"prompt": "Summarize this text: ..."
|
|
99
96
|
}
|
|
100
97
|
```
|
|
101
98
|
|
|
102
|
-
|
|
99
|
+
**Request with messages:**
|
|
103
100
|
```json
|
|
104
101
|
{
|
|
105
|
-
"
|
|
106
|
-
"
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
]
|
|
110
|
-
}
|
|
102
|
+
"messages": [
|
|
103
|
+
{"role": "system", "content": "You are a helpful assistant."},
|
|
104
|
+
{"role": "user", "content": "Hello!"}
|
|
105
|
+
]
|
|
111
106
|
}
|
|
112
107
|
```
|
|
113
108
|
|
|
@@ -118,29 +113,18 @@ Or with messages:
|
|
|
118
113
|
}
|
|
119
114
|
```
|
|
120
115
|
|
|
121
|
-
###
|
|
116
|
+
### Streaming
|
|
122
117
|
|
|
123
|
-
|
|
118
|
+
For streaming responses, set `stream: true` in the request:
|
|
124
119
|
|
|
125
|
-
**Request:**
|
|
126
120
|
```json
|
|
127
121
|
{
|
|
128
|
-
"
|
|
129
|
-
|
|
130
|
-
]
|
|
122
|
+
"prompt": "Tell me a story",
|
|
123
|
+
"stream": true
|
|
131
124
|
}
|
|
132
125
|
```
|
|
133
126
|
|
|
134
|
-
|
|
135
|
-
```json
|
|
136
|
-
{
|
|
137
|
-
"output": "The capital of France is Paris.",
|
|
138
|
-
"messages": [
|
|
139
|
-
{"role": "user", "content": "What is the capital of France?"},
|
|
140
|
-
{"role": "assistant", "content": "The capital of France is Paris."}
|
|
141
|
-
]
|
|
142
|
-
}
|
|
143
|
-
```
|
|
127
|
+
The response will be sent as Server-Sent Events (SSE).
|
|
144
128
|
|
|
145
129
|
## Runtime Documentation
|
|
146
130
|
|
package/dist/agent-adapter.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* OpenAI adapter for Reminix Runtime.
|
|
3
3
|
*/
|
|
4
4
|
import type OpenAI from 'openai';
|
|
5
|
-
import { AgentAdapter, type ServeOptions, type
|
|
5
|
+
import { AgentAdapter, type ServeOptions, type ExecuteRequest, type ExecuteResponse } from '@reminix/runtime';
|
|
6
6
|
/**
|
|
7
7
|
* Options for wrapping an OpenAI client.
|
|
8
8
|
*/
|
|
@@ -32,38 +32,26 @@ export declare class OpenAIAgentAdapter extends AgentAdapter {
|
|
|
32
32
|
*/
|
|
33
33
|
private toOpenAIMessage;
|
|
34
34
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* For task-oriented operations. Expects input with 'messages' key
|
|
38
|
-
* or a 'prompt' key for simple text generation.
|
|
39
|
-
*
|
|
40
|
-
* @param request - The invoke request with input data.
|
|
41
|
-
* @returns The invoke response with the output.
|
|
35
|
+
* Build OpenAI messages from execute request input.
|
|
42
36
|
*/
|
|
43
|
-
|
|
37
|
+
private buildOpenAIMessages;
|
|
44
38
|
/**
|
|
45
|
-
* Handle
|
|
46
|
-
*
|
|
47
|
-
* For conversational interactions.
|
|
39
|
+
* Handle an execute request.
|
|
48
40
|
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*/
|
|
52
|
-
chat(request: ChatRequest): Promise<ChatResponse>;
|
|
53
|
-
/**
|
|
54
|
-
* Handle a streaming invoke request.
|
|
41
|
+
* For both task-oriented and chat-style operations. Expects input with 'messages' key
|
|
42
|
+
* or a 'prompt' key for simple text generation.
|
|
55
43
|
*
|
|
56
|
-
* @param request - The
|
|
57
|
-
* @
|
|
44
|
+
* @param request - The execute request with input data.
|
|
45
|
+
* @returns The execute response with the output.
|
|
58
46
|
*/
|
|
59
|
-
|
|
47
|
+
execute(request: ExecuteRequest): Promise<ExecuteResponse>;
|
|
60
48
|
/**
|
|
61
|
-
* Handle a streaming
|
|
49
|
+
* Handle a streaming execute request.
|
|
62
50
|
*
|
|
63
|
-
* @param request - The
|
|
51
|
+
* @param request - The execute request with input data.
|
|
64
52
|
* @yields JSON-encoded chunks from the stream.
|
|
65
53
|
*/
|
|
66
|
-
|
|
54
|
+
executeStream(request: ExecuteRequest): AsyncGenerator<string, void, unknown>;
|
|
67
55
|
}
|
|
68
56
|
/**
|
|
69
57
|
* Wrap an OpenAI client for use with Reminix Runtime.
|
|
@@ -1 +1 @@
|
|
|
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,EAEZ,KAAK,YAAY,EACjB,KAAK,
|
|
1
|
+
{"version":3,"file":"agent-adapter.d.ts","sourceRoot":"","sources":["../src/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
|
@@ -39,80 +39,49 @@ export class OpenAIAgentAdapter extends AgentAdapter {
|
|
|
39
39
|
return result;
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* For task-oriented operations. Expects input with 'messages' key
|
|
45
|
-
* or a 'prompt' key for simple text generation.
|
|
46
|
-
*
|
|
47
|
-
* @param request - The invoke request with input data.
|
|
48
|
-
* @returns The invoke response with the output.
|
|
42
|
+
* Build OpenAI messages from execute request input.
|
|
49
43
|
*/
|
|
50
|
-
|
|
51
|
-
// Check if input contains messages
|
|
52
|
-
let messages;
|
|
44
|
+
buildOpenAIMessages(request) {
|
|
53
45
|
const input = request.input;
|
|
54
46
|
if ('messages' in input) {
|
|
55
|
-
messages = input.messages;
|
|
47
|
+
const messages = input.messages;
|
|
48
|
+
return messages.map((m) => this.toOpenAIMessage(m));
|
|
56
49
|
}
|
|
57
50
|
else if ('prompt' in input) {
|
|
58
|
-
|
|
51
|
+
return [{ role: 'user', content: String(input.prompt) }];
|
|
59
52
|
}
|
|
60
53
|
else {
|
|
61
|
-
|
|
54
|
+
return [{ role: 'user', content: JSON.stringify(input) }];
|
|
62
55
|
}
|
|
63
|
-
// Call OpenAI API
|
|
64
|
-
const response = await this.client.chat.completions.create({
|
|
65
|
-
model: this._model,
|
|
66
|
-
messages,
|
|
67
|
-
});
|
|
68
|
-
// Extract content from response
|
|
69
|
-
const output = response.choices[0]?.message?.content ?? '';
|
|
70
|
-
return { output };
|
|
71
56
|
}
|
|
72
57
|
/**
|
|
73
|
-
* Handle
|
|
58
|
+
* Handle an execute request.
|
|
74
59
|
*
|
|
75
|
-
* For
|
|
60
|
+
* For both task-oriented and chat-style operations. Expects input with 'messages' key
|
|
61
|
+
* or a 'prompt' key for simple text generation.
|
|
76
62
|
*
|
|
77
|
-
* @param request - The
|
|
78
|
-
* @returns The
|
|
63
|
+
* @param request - The execute request with input data.
|
|
64
|
+
* @returns The execute response with the output.
|
|
79
65
|
*/
|
|
80
|
-
async
|
|
81
|
-
|
|
82
|
-
const openaiMessages = request.messages.map((m) => this.toOpenAIMessage(m));
|
|
66
|
+
async execute(request) {
|
|
67
|
+
const messages = this.buildOpenAIMessages(request);
|
|
83
68
|
// Call OpenAI API
|
|
84
69
|
const response = await this.client.chat.completions.create({
|
|
85
70
|
model: this._model,
|
|
86
|
-
messages
|
|
71
|
+
messages,
|
|
87
72
|
});
|
|
88
73
|
// Extract content from response
|
|
89
74
|
const output = response.choices[0]?.message?.content ?? '';
|
|
90
|
-
|
|
91
|
-
const responseMessages = [
|
|
92
|
-
...request.messages,
|
|
93
|
-
{ role: 'assistant', content: output },
|
|
94
|
-
];
|
|
95
|
-
return { output, messages: responseMessages };
|
|
75
|
+
return { output };
|
|
96
76
|
}
|
|
97
77
|
/**
|
|
98
|
-
* Handle a streaming
|
|
78
|
+
* Handle a streaming execute request.
|
|
99
79
|
*
|
|
100
|
-
* @param request - The
|
|
80
|
+
* @param request - The execute request with input data.
|
|
101
81
|
* @yields JSON-encoded chunks from the stream.
|
|
102
82
|
*/
|
|
103
|
-
async *
|
|
104
|
-
|
|
105
|
-
let messages;
|
|
106
|
-
const input = request.input;
|
|
107
|
-
if ('messages' in input) {
|
|
108
|
-
messages = input.messages;
|
|
109
|
-
}
|
|
110
|
-
else if ('prompt' in input) {
|
|
111
|
-
messages = [{ role: 'user', content: String(input.prompt) }];
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
messages = [{ role: 'user', content: JSON.stringify(input) }];
|
|
115
|
-
}
|
|
83
|
+
async *executeStream(request) {
|
|
84
|
+
const messages = this.buildOpenAIMessages(request);
|
|
116
85
|
// Stream from OpenAI API
|
|
117
86
|
const stream = await this.client.chat.completions.create({
|
|
118
87
|
model: this._model,
|
|
@@ -126,28 +95,6 @@ export class OpenAIAgentAdapter extends AgentAdapter {
|
|
|
126
95
|
}
|
|
127
96
|
}
|
|
128
97
|
}
|
|
129
|
-
/**
|
|
130
|
-
* Handle a streaming chat request.
|
|
131
|
-
*
|
|
132
|
-
* @param request - The chat request with messages.
|
|
133
|
-
* @yields JSON-encoded chunks from the stream.
|
|
134
|
-
*/
|
|
135
|
-
async *chatStream(request) {
|
|
136
|
-
// Convert messages to OpenAI format
|
|
137
|
-
const openaiMessages = request.messages.map((m) => this.toOpenAIMessage(m));
|
|
138
|
-
// Stream from OpenAI API
|
|
139
|
-
const stream = await this.client.chat.completions.create({
|
|
140
|
-
model: this._model,
|
|
141
|
-
messages: openaiMessages,
|
|
142
|
-
stream: true,
|
|
143
|
-
});
|
|
144
|
-
for await (const chunk of stream) {
|
|
145
|
-
const content = chunk.choices[0]?.delta?.content;
|
|
146
|
-
if (content) {
|
|
147
|
-
yield JSON.stringify({ chunk: content });
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
98
|
}
|
|
152
99
|
/**
|
|
153
100
|
* Wrap an OpenAI client for use with Reminix Runtime.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-adapter.js","sourceRoot":"","sources":["../src/agent-adapter.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EACL,YAAY,EACZ,KAAK,
|
|
1
|
+
{"version":3,"file":"agent-adapter.js","sourceRoot":"","sources":["../src/agent-adapter.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EACL,YAAY,EACZ,KAAK,GAKN,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,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CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAChD,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;AAC7C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reminix/openai",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "Reminix adapter for OpenAI - serve agents as REST APIs",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"LICENSE"
|
|
46
46
|
],
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@reminix/runtime": "^0.0.
|
|
48
|
+
"@reminix/runtime": "^0.0.8"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"openai": ">=6.16.0"
|