@fancyrobot/fred-openai 0.1.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/dist/index.js +87175 -0
- package/package.json +35 -0
- package/src/index.ts +60 -0
- package/tsconfig.json +9 -0
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fancyrobot/fred-openai",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "OpenAI provider for Fred AI framework",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./src/index.ts",
|
|
7
|
+
"types": "./src/index.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./src/index.ts",
|
|
11
|
+
"import": "./src/index.ts",
|
|
12
|
+
"default": "./src/index.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "bun build src/index.ts --outdir dist --target bun --format esm"
|
|
17
|
+
},
|
|
18
|
+
"peerDependencies": {
|
|
19
|
+
"@fancyrobot/fred": "^0.1.0",
|
|
20
|
+
"effect": "^3.19.0",
|
|
21
|
+
"@effect/ai": "^0.33.0",
|
|
22
|
+
"@effect/ai-openai": "^0.37.0"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@fancyrobot/fred": "^0.1.0",
|
|
26
|
+
"effect": "^3.19.15",
|
|
27
|
+
"@effect/ai": "^0.33.2",
|
|
28
|
+
"@effect/ai-openai": "^0.37.2"
|
|
29
|
+
},
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
},
|
|
33
|
+
"keywords": ["fred", "openai", "ai", "provider"],
|
|
34
|
+
"license": "MIT"
|
|
35
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Effect, Redacted } from 'effect';
|
|
2
|
+
import { registerBuiltinPack } from '@fancyrobot/fred';
|
|
3
|
+
import type { EffectProviderFactory, ProviderConfig, ProviderModelDefaults } from '@fancyrobot/fred';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* OpenAI provider pack factory.
|
|
7
|
+
*
|
|
8
|
+
* Implements EffectProviderFactory interface for use as both built-in
|
|
9
|
+
* and external pack pattern. Uses dynamic import to avoid hard dependency.
|
|
10
|
+
*/
|
|
11
|
+
export const OpenAiProviderFactory: EffectProviderFactory = {
|
|
12
|
+
id: 'openai',
|
|
13
|
+
aliases: ['openai'],
|
|
14
|
+
load: async (config: ProviderConfig) => {
|
|
15
|
+
// Dynamic import to avoid hard dependency
|
|
16
|
+
let module: typeof import('@effect/ai-openai');
|
|
17
|
+
try {
|
|
18
|
+
module = await import('@effect/ai-openai');
|
|
19
|
+
} catch (error) {
|
|
20
|
+
throw new Error(
|
|
21
|
+
`Failed to load @effect/ai-openai. Install it with: bun add @effect/ai-openai`
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const apiKeyEnvVar = config.apiKeyEnvVar ?? 'OPENAI_API_KEY';
|
|
26
|
+
const apiKeyString = process.env[apiKeyEnvVar];
|
|
27
|
+
const apiKey = apiKeyString ? Redacted.make(apiKeyString) : undefined;
|
|
28
|
+
|
|
29
|
+
// Use OpenAiClient.layer for client initialization
|
|
30
|
+
const layer = module.OpenAiClient?.layer?.({
|
|
31
|
+
apiKey,
|
|
32
|
+
apiUrl: config.baseUrl,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
if (!layer) {
|
|
36
|
+
throw new Error('OpenAI provider pack did not expose a client layer');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
layer,
|
|
41
|
+
getModel: (modelId: string, overrides?: ProviderModelDefaults) => {
|
|
42
|
+
if (!module.OpenAiLanguageModel?.model) {
|
|
43
|
+
return Effect.fail(new Error('OpenAI LanguageModel not available in provider pack'));
|
|
44
|
+
}
|
|
45
|
+
return Effect.succeed(
|
|
46
|
+
module.OpenAiLanguageModel.model(modelId, {
|
|
47
|
+
temperature: overrides?.temperature,
|
|
48
|
+
max_output_tokens: overrides?.maxTokens,
|
|
49
|
+
})
|
|
50
|
+
);
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// Auto-register when imported
|
|
57
|
+
registerBuiltinPack(OpenAiProviderFactory);
|
|
58
|
+
|
|
59
|
+
export { OpenAiProviderFactory as openaiPack };
|
|
60
|
+
export default OpenAiProviderFactory;
|