@stratix/ai-openai 0.4.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/README.md +163 -0
- package/dist/OpenAIProvider.d.ts +50 -0
- package/dist/OpenAIProvider.d.ts.map +1 -0
- package/dist/OpenAIProvider.js +204 -0
- package/dist/OpenAIProvider.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/package.json +63 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 P. Andrés Carvajal
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# @stratix/ai-openai
|
|
2
|
+
|
|
3
|
+
OpenAI LLM provider for Stratix AI agents.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @stratix/ai-openai
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- Support for GPT-4, GPT-4 Turbo, GPT-3.5 Turbo, and GPT-4o models
|
|
14
|
+
- Function/tool calling support
|
|
15
|
+
- Streaming responses
|
|
16
|
+
- Embeddings generation
|
|
17
|
+
- Automatic cost calculation based on token usage
|
|
18
|
+
- Structured output with JSON schemas
|
|
19
|
+
- Response format control (JSON object, JSON schema)
|
|
20
|
+
|
|
21
|
+
## Supported Models
|
|
22
|
+
|
|
23
|
+
**Chat Models:**
|
|
24
|
+
- `gpt-4o` - Latest GPT-4 optimized model
|
|
25
|
+
- `gpt-4o-mini` - Smaller, faster GPT-4o
|
|
26
|
+
- `gpt-4` - Base GPT-4 model
|
|
27
|
+
- `gpt-4-turbo` - GPT-4 Turbo with improved performance
|
|
28
|
+
- `gpt-4-turbo-preview` - Preview version of GPT-4 Turbo
|
|
29
|
+
- `gpt-3.5-turbo` - Fast and cost-effective model
|
|
30
|
+
- `gpt-3.5-turbo-16k` - Extended context version
|
|
31
|
+
|
|
32
|
+
**Embedding Models:**
|
|
33
|
+
- `text-embedding-3-small` - Small, efficient embeddings
|
|
34
|
+
- `text-embedding-3-large` - High-quality embeddings
|
|
35
|
+
- `text-embedding-ada-002` - Legacy embedding model
|
|
36
|
+
|
|
37
|
+
## Quick Example
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
import { OpenAIProvider } from '@stratix/ai-openai';
|
|
41
|
+
|
|
42
|
+
const provider = new OpenAIProvider({
|
|
43
|
+
apiKey: process.env.OPENAI_API_KEY!,
|
|
44
|
+
organization: 'org-123', // Optional
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// Chat completion
|
|
48
|
+
const response = await provider.chat({
|
|
49
|
+
model: 'gpt-4o',
|
|
50
|
+
messages: [
|
|
51
|
+
{ role: 'system', content: 'You are a helpful assistant.', timestamp: new Date() },
|
|
52
|
+
{ role: 'user', content: 'Hello!', timestamp: new Date() }
|
|
53
|
+
],
|
|
54
|
+
temperature: 0.7,
|
|
55
|
+
maxTokens: 1000
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
console.log(response.content);
|
|
59
|
+
console.log('Cost:', provider.calculateCost('gpt-4o', response.usage));
|
|
60
|
+
|
|
61
|
+
// Streaming chat
|
|
62
|
+
for await (const chunk of provider.streamChat({
|
|
63
|
+
model: 'gpt-4o',
|
|
64
|
+
messages: [
|
|
65
|
+
{ role: 'user', content: 'Tell me a story', timestamp: new Date() }
|
|
66
|
+
]
|
|
67
|
+
})) {
|
|
68
|
+
process.stdout.write(chunk.content);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Embeddings
|
|
72
|
+
const embeddingsResponse = await provider.embeddings({
|
|
73
|
+
model: 'text-embedding-3-small',
|
|
74
|
+
input: ['Hello world', 'OpenAI embeddings']
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
console.log(embeddingsResponse.embeddings.length); // 2
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Tool/Function Calling
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
const response = await provider.chat({
|
|
84
|
+
model: 'gpt-4o',
|
|
85
|
+
messages: [
|
|
86
|
+
{ role: 'user', content: 'What is the weather in NYC?', timestamp: new Date() }
|
|
87
|
+
],
|
|
88
|
+
tools: [
|
|
89
|
+
{
|
|
90
|
+
name: 'get_weather',
|
|
91
|
+
description: 'Get the current weather in a location',
|
|
92
|
+
parameters: {
|
|
93
|
+
type: 'object',
|
|
94
|
+
properties: {
|
|
95
|
+
location: { type: 'string', description: 'The city name' }
|
|
96
|
+
},
|
|
97
|
+
required: ['location']
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
]
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
if (response.toolCalls) {
|
|
104
|
+
console.log('Tool call:', response.toolCalls[0].name);
|
|
105
|
+
console.log('Arguments:', response.toolCalls[0].arguments);
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Structured Output
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
const response = await provider.chat({
|
|
113
|
+
model: 'gpt-4o',
|
|
114
|
+
messages: [
|
|
115
|
+
{ role: 'user', content: 'Extract user info: John Doe, 30 years old', timestamp: new Date() }
|
|
116
|
+
],
|
|
117
|
+
responseFormat: {
|
|
118
|
+
type: 'json_schema',
|
|
119
|
+
schema: {
|
|
120
|
+
type: 'object',
|
|
121
|
+
properties: {
|
|
122
|
+
name: { type: 'string' },
|
|
123
|
+
age: { type: 'number' }
|
|
124
|
+
},
|
|
125
|
+
required: ['name', 'age']
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
const userInfo = JSON.parse(response.content);
|
|
131
|
+
console.log(userInfo); // { name: 'John Doe', age: 30 }
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Configuration
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
interface OpenAIProviderConfig {
|
|
138
|
+
apiKey: string; // Required: OpenAI API key
|
|
139
|
+
organization?: string; // Optional: OpenAI organization ID
|
|
140
|
+
baseURL?: string; // Optional: Custom API base URL
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Cost Calculation
|
|
145
|
+
|
|
146
|
+
The provider automatically tracks token usage and can calculate costs:
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
const response = await provider.chat({...});
|
|
150
|
+
|
|
151
|
+
const cost = provider.calculateCost('gpt-4o', response.usage);
|
|
152
|
+
console.log(`Cost: $${cost.toFixed(4)}`);
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Pricing is based on January 2025 rates and included in the provider.
|
|
156
|
+
|
|
157
|
+
## Exports
|
|
158
|
+
|
|
159
|
+
- `OpenAIProvider` - Main provider class implementing `LLMProvider` interface
|
|
160
|
+
|
|
161
|
+
## License
|
|
162
|
+
|
|
163
|
+
MIT
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { LLMProvider, ChatParams, ChatResponse, ChatChunk, EmbeddingParams, EmbeddingResponse } from '@stratix/core';
|
|
2
|
+
import type { TokenUsage } from '@stratix/core';
|
|
3
|
+
/**
|
|
4
|
+
* OpenAI provider implementation for Stratix AI Agents.
|
|
5
|
+
*
|
|
6
|
+
* Supports GPT-4, GPT-3.5, and embeddings models with function calling.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const provider = new OpenAIProvider({
|
|
11
|
+
* apiKey: process.env.OPENAI_API_KEY!,
|
|
12
|
+
* organization: 'org-123'
|
|
13
|
+
* });
|
|
14
|
+
*
|
|
15
|
+
* const response = await provider.chat({
|
|
16
|
+
* model: 'gpt-4',
|
|
17
|
+
* messages: [
|
|
18
|
+
* { role: 'user', content: 'Hello!', timestamp: new Date() }
|
|
19
|
+
* ],
|
|
20
|
+
* temperature: 0.7
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare class OpenAIProvider implements LLMProvider {
|
|
25
|
+
readonly name = "openai";
|
|
26
|
+
readonly models: string[];
|
|
27
|
+
private client;
|
|
28
|
+
constructor(config: {
|
|
29
|
+
apiKey: string;
|
|
30
|
+
organization?: string;
|
|
31
|
+
baseURL?: string;
|
|
32
|
+
});
|
|
33
|
+
chat(params: ChatParams): Promise<ChatResponse>;
|
|
34
|
+
streamChat(params: ChatParams): AsyncIterable<ChatChunk>;
|
|
35
|
+
embeddings(params: EmbeddingParams): Promise<EmbeddingResponse>;
|
|
36
|
+
/**
|
|
37
|
+
* Calculates the cost of a chat completion based on token usage
|
|
38
|
+
*
|
|
39
|
+
* @param model - The model used
|
|
40
|
+
* @param usage - Token usage information
|
|
41
|
+
* @returns Cost in USD
|
|
42
|
+
*/
|
|
43
|
+
calculateCost(model: string, usage: TokenUsage): number;
|
|
44
|
+
private convertMessages;
|
|
45
|
+
private convertTools;
|
|
46
|
+
private convertResponseFormat;
|
|
47
|
+
private extractToolCalls;
|
|
48
|
+
private mapFinishReason;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=OpenAIProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OpenAIProvider.d.ts","sourceRoot":"","sources":["../src/OpenAIProvider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,YAAY,EACZ,SAAS,EACT,eAAe,EACf,iBAAiB,EAClB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAgB,UAAU,EAAY,MAAM,eAAe,CAAC;AAoBxE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,cAAe,YAAW,WAAW;IAChD,QAAQ,CAAC,IAAI,YAAY;IACzB,QAAQ,CAAC,MAAM,WAQb;IAEF,OAAO,CAAC,MAAM,CAAS;gBAEX,MAAM,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE;IAQzE,IAAI,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC;IAuC9C,UAAU,CAAC,MAAM,EAAE,UAAU,GAAG,aAAa,CAAC,SAAS,CAAC;IAuBzD,UAAU,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAoBrE;;;;;;OAMG;IACH,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,MAAM;IAavD,OAAO,CAAC,eAAe;IASvB,OAAO,CAAC,YAAY;IAapB,OAAO,CAAC,qBAAqB;IA2B7B,OAAO,CAAC,gBAAgB;IAUxB,OAAO,CAAC,eAAe;CAgBxB"}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import OpenAI from 'openai';
|
|
2
|
+
/**
|
|
3
|
+
* Pricing per 1M tokens for OpenAI models (as of January 2025)
|
|
4
|
+
* Source: https://openai.com/api/pricing/
|
|
5
|
+
* Update these values as pricing changes
|
|
6
|
+
*/
|
|
7
|
+
const MODEL_PRICING = {
|
|
8
|
+
'gpt-4o': { input: 5.0, output: 20.0 },
|
|
9
|
+
'gpt-4o-mini': { input: 0.6, output: 2.4 },
|
|
10
|
+
'gpt-4': { input: 30.0, output: 60.0 },
|
|
11
|
+
'gpt-4-turbo': { input: 10.0, output: 30.0 },
|
|
12
|
+
'gpt-4-turbo-preview': { input: 10.0, output: 30.0 },
|
|
13
|
+
'gpt-3.5-turbo': { input: 0.5, output: 1.5 },
|
|
14
|
+
'gpt-3.5-turbo-16k': { input: 3.0, output: 4.0 },
|
|
15
|
+
'text-embedding-3-small': { input: 0.02, output: 0 },
|
|
16
|
+
'text-embedding-3-large': { input: 0.13, output: 0 },
|
|
17
|
+
'text-embedding-ada-002': { input: 0.1, output: 0 },
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* OpenAI provider implementation for Stratix AI Agents.
|
|
21
|
+
*
|
|
22
|
+
* Supports GPT-4, GPT-3.5, and embeddings models with function calling.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const provider = new OpenAIProvider({
|
|
27
|
+
* apiKey: process.env.OPENAI_API_KEY!,
|
|
28
|
+
* organization: 'org-123'
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* const response = await provider.chat({
|
|
32
|
+
* model: 'gpt-4',
|
|
33
|
+
* messages: [
|
|
34
|
+
* { role: 'user', content: 'Hello!', timestamp: new Date() }
|
|
35
|
+
* ],
|
|
36
|
+
* temperature: 0.7
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export class OpenAIProvider {
|
|
41
|
+
name = 'openai';
|
|
42
|
+
models = [
|
|
43
|
+
'gpt-4o',
|
|
44
|
+
'gpt-4o-mini',
|
|
45
|
+
'gpt-4',
|
|
46
|
+
'gpt-4-turbo',
|
|
47
|
+
'gpt-4-turbo-preview',
|
|
48
|
+
'gpt-3.5-turbo',
|
|
49
|
+
'gpt-3.5-turbo-16k',
|
|
50
|
+
];
|
|
51
|
+
client;
|
|
52
|
+
constructor(config) {
|
|
53
|
+
this.client = new OpenAI({
|
|
54
|
+
apiKey: config.apiKey,
|
|
55
|
+
organization: config.organization,
|
|
56
|
+
baseURL: config.baseURL,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
async chat(params) {
|
|
60
|
+
const messages = this.convertMessages(params.messages);
|
|
61
|
+
const completion = await this.client.chat.completions.create({
|
|
62
|
+
model: params.model,
|
|
63
|
+
messages,
|
|
64
|
+
temperature: params.temperature ?? 0.7,
|
|
65
|
+
max_tokens: params.maxTokens,
|
|
66
|
+
tools: params.tools ? this.convertTools(params.tools) : undefined,
|
|
67
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
68
|
+
response_format: params.responseFormat
|
|
69
|
+
? this.convertResponseFormat(params.responseFormat)
|
|
70
|
+
: undefined,
|
|
71
|
+
});
|
|
72
|
+
const choice = completion.choices[0];
|
|
73
|
+
if (!choice) {
|
|
74
|
+
throw new Error('No completion choice returned from OpenAI');
|
|
75
|
+
}
|
|
76
|
+
const content = choice.message.content || '';
|
|
77
|
+
const toolCalls = choice.message.tool_calls
|
|
78
|
+
? this.extractToolCalls(choice.message.tool_calls)
|
|
79
|
+
: undefined;
|
|
80
|
+
const usage = {
|
|
81
|
+
promptTokens: completion.usage?.prompt_tokens || 0,
|
|
82
|
+
completionTokens: completion.usage?.completion_tokens || 0,
|
|
83
|
+
totalTokens: completion.usage?.total_tokens || 0,
|
|
84
|
+
};
|
|
85
|
+
return {
|
|
86
|
+
content,
|
|
87
|
+
toolCalls,
|
|
88
|
+
usage,
|
|
89
|
+
finishReason: this.mapFinishReason(choice.finish_reason),
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
async *streamChat(params) {
|
|
93
|
+
const messages = this.convertMessages(params.messages);
|
|
94
|
+
const stream = await this.client.chat.completions.create({
|
|
95
|
+
model: params.model,
|
|
96
|
+
messages,
|
|
97
|
+
temperature: params.temperature ?? 0.7,
|
|
98
|
+
max_tokens: params.maxTokens,
|
|
99
|
+
tools: params.tools ? this.convertTools(params.tools) : undefined,
|
|
100
|
+
stream: true,
|
|
101
|
+
});
|
|
102
|
+
for await (const chunk of stream) {
|
|
103
|
+
const delta = chunk.choices[0]?.delta;
|
|
104
|
+
if (delta?.content) {
|
|
105
|
+
yield {
|
|
106
|
+
content: delta.content,
|
|
107
|
+
isComplete: chunk.choices[0]?.finish_reason !== null,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
async embeddings(params) {
|
|
113
|
+
const response = await this.client.embeddings.create({
|
|
114
|
+
model: params.model,
|
|
115
|
+
input: params.input,
|
|
116
|
+
});
|
|
117
|
+
const embeddings = response.data.map((item) => item.embedding);
|
|
118
|
+
const usage = {
|
|
119
|
+
promptTokens: response.usage.prompt_tokens,
|
|
120
|
+
completionTokens: 0,
|
|
121
|
+
totalTokens: response.usage.total_tokens,
|
|
122
|
+
};
|
|
123
|
+
return {
|
|
124
|
+
embeddings,
|
|
125
|
+
usage,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Calculates the cost of a chat completion based on token usage
|
|
130
|
+
*
|
|
131
|
+
* @param model - The model used
|
|
132
|
+
* @param usage - Token usage information
|
|
133
|
+
* @returns Cost in USD
|
|
134
|
+
*/
|
|
135
|
+
calculateCost(model, usage) {
|
|
136
|
+
const pricing = MODEL_PRICING[model];
|
|
137
|
+
if (!pricing) {
|
|
138
|
+
console.warn(`No pricing information for model: ${model}`);
|
|
139
|
+
return 0;
|
|
140
|
+
}
|
|
141
|
+
const inputCost = (usage.promptTokens / 1_000_000) * pricing.input;
|
|
142
|
+
const outputCost = (usage.completionTokens / 1_000_000) * pricing.output;
|
|
143
|
+
return inputCost + outputCost;
|
|
144
|
+
}
|
|
145
|
+
convertMessages(messages) {
|
|
146
|
+
return messages.map((msg) => ({
|
|
147
|
+
role: msg.role,
|
|
148
|
+
content: msg.content,
|
|
149
|
+
}));
|
|
150
|
+
}
|
|
151
|
+
convertTools(tools) {
|
|
152
|
+
return tools.map((tool) => ({
|
|
153
|
+
type: 'function',
|
|
154
|
+
function: {
|
|
155
|
+
name: tool.name,
|
|
156
|
+
description: tool.description,
|
|
157
|
+
parameters: tool.parameters,
|
|
158
|
+
},
|
|
159
|
+
}));
|
|
160
|
+
}
|
|
161
|
+
convertResponseFormat(format) {
|
|
162
|
+
if (format.type === 'json_object') {
|
|
163
|
+
return { type: 'json_object' };
|
|
164
|
+
}
|
|
165
|
+
if (format.type === 'json_schema' && format.schema) {
|
|
166
|
+
// OpenAI requires additionalProperties: false for structured outputs
|
|
167
|
+
const schemaWithAdditionalProps = {
|
|
168
|
+
...format.schema,
|
|
169
|
+
additionalProperties: false,
|
|
170
|
+
};
|
|
171
|
+
return {
|
|
172
|
+
type: 'json_schema',
|
|
173
|
+
json_schema: {
|
|
174
|
+
name: 'response_schema',
|
|
175
|
+
schema: schemaWithAdditionalProps,
|
|
176
|
+
strict: true,
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
return undefined;
|
|
181
|
+
}
|
|
182
|
+
extractToolCalls(toolCalls) {
|
|
183
|
+
return toolCalls.map((tc) => ({
|
|
184
|
+
name: tc.function.name,
|
|
185
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
186
|
+
arguments: JSON.parse(tc.function.arguments),
|
|
187
|
+
}));
|
|
188
|
+
}
|
|
189
|
+
mapFinishReason(reason) {
|
|
190
|
+
switch (reason) {
|
|
191
|
+
case 'stop':
|
|
192
|
+
return 'stop';
|
|
193
|
+
case 'length':
|
|
194
|
+
return 'length';
|
|
195
|
+
case 'tool_calls':
|
|
196
|
+
return 'tool_calls';
|
|
197
|
+
case 'content_filter':
|
|
198
|
+
return 'content_filter';
|
|
199
|
+
default:
|
|
200
|
+
return 'stop';
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
//# sourceMappingURL=OpenAIProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OpenAIProvider.js","sourceRoot":"","sources":["../src/OpenAIProvider.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAW5B;;;;GAIG;AACH,MAAM,aAAa,GAAG;IACpB,QAAQ,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE;IACtC,aAAa,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE;IAC1C,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE;IACtC,aAAa,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE;IAC5C,qBAAqB,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE;IACpD,eAAe,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE;IAC5C,mBAAmB,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE;IAChD,wBAAwB,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE;IACpD,wBAAwB,EAAE,EAAE,KAAK,EAAE,IAAI,EAA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CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;YAC5B,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI;YACtB,mEAAmE;YACnE,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC;SAC7C,CAAC,CAAC,CAAC;IACN,CAAC;IAEO,eAAe,CACrB,MAAiC;QAEjC,QAAQ,MAAM,EAAE,CAAC;YACf,KAAK,MAAM;gBACT,OAAO,MAAM,CAAC;YAChB,KAAK,QAAQ;gBACX,OAAO,QAAQ,CAAC;YAClB,KAAK,YAAY;gBACf,OAAO,YAAY,CAAC;YACtB,KAAK,gBAAgB;gBACnB,OAAO,gBAAgB,CAAC;YAC1B;gBACE,OAAO,MAAM,CAAC;QAClB,CAAC;IACH,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stratix/ai-openai",
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "Stratix AI Agents - OpenAI Provider",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"keywords": [
|
|
18
|
+
"ai",
|
|
19
|
+
"openai",
|
|
20
|
+
"gpt",
|
|
21
|
+
"gpt-4",
|
|
22
|
+
"chatgpt",
|
|
23
|
+
"llm",
|
|
24
|
+
"provider",
|
|
25
|
+
"ai-agents",
|
|
26
|
+
"typescript"
|
|
27
|
+
],
|
|
28
|
+
"author": "P. Andrés Carvajal <causticrez@gmail.com>",
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"openai": "^4.75.0",
|
|
35
|
+
"@stratix/core": "0.4.0"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/node": "^20.0.0",
|
|
39
|
+
"eslint": "^8.0.0",
|
|
40
|
+
"typescript": "^5.3.0",
|
|
41
|
+
"vitest": "^1.0.0"
|
|
42
|
+
},
|
|
43
|
+
"repository": {
|
|
44
|
+
"type": "git",
|
|
45
|
+
"url": "https://github.com/stratix-dev/stratix.git",
|
|
46
|
+
"directory": "packages/plugins/ai/openai"
|
|
47
|
+
},
|
|
48
|
+
"homepage": "https://github.com/stratix-dev/stratix#readme",
|
|
49
|
+
"bugs": {
|
|
50
|
+
"url": "https://github.com/stratix-dev/stratix/issues"
|
|
51
|
+
},
|
|
52
|
+
"engines": {
|
|
53
|
+
"node": ">=18.0.0"
|
|
54
|
+
},
|
|
55
|
+
"scripts": {
|
|
56
|
+
"build": "tsc",
|
|
57
|
+
"test": "vitest run",
|
|
58
|
+
"test:watch": "vitest",
|
|
59
|
+
"typecheck": "tsc --noEmit",
|
|
60
|
+
"lint": "eslint src --ignore-pattern '**/*.test.ts' --ignore-pattern '**/__tests__/**'",
|
|
61
|
+
"clean": "rm -rf dist"
|
|
62
|
+
}
|
|
63
|
+
}
|