@tmlmobilidade/go-providers-ai 20260828.1636.54
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 +3 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/models.d.ts +21 -0
- package/dist/models.js +18 -0
- package/dist/oci-generativeai.d.ts +22 -0
- package/dist/oci-generativeai.js +107 -0
- package/package.json +49 -0
package/README.md
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './oci-generativeai.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './oci-generativeai.js';
|
package/dist/models.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface AiModel {
|
|
2
|
+
ocid: string;
|
|
3
|
+
release_date: string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Available AI models for the AI provider.
|
|
7
|
+
*/
|
|
8
|
+
export declare const availableAiModels: {
|
|
9
|
+
readonly 'cohere.command-a-03-2025 v1.0': {
|
|
10
|
+
readonly ocid: "ocid1.generativeaimodel.oc1.eu-frankfurt-1.amaaaaaask7dceyaaypm2hg4db3evqkmjfdli5mggcxrhp2i4qmhvggyb4ja";
|
|
11
|
+
readonly release_date: "2025-03-01";
|
|
12
|
+
};
|
|
13
|
+
readonly 'google.gemini-2.5-flash': {
|
|
14
|
+
readonly ocid: "ocid1.generativeaimodel.oc1.eu-frankfurt-1.amaaaaaask7dceyacn5rezarysrnds7bjsu6iy5nrxdvq6hyqcygode5o5xq";
|
|
15
|
+
readonly release_date: "2025-03-01";
|
|
16
|
+
};
|
|
17
|
+
readonly 'google.gemini-2.5-pro': {
|
|
18
|
+
readonly ocid: "ocid1.generativeaimodel.oc1.eu-frankfurt-1.amaaaaaask7dceyan6gecfjovk7wtgl3r65b5tmpuegfxojbp2mebjgtvhra";
|
|
19
|
+
readonly release_date: "2025-03-01";
|
|
20
|
+
};
|
|
21
|
+
};
|
package/dist/models.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/* * */
|
|
2
|
+
/**
|
|
3
|
+
* Available AI models for the AI provider.
|
|
4
|
+
*/
|
|
5
|
+
export const availableAiModels = {
|
|
6
|
+
'cohere.command-a-03-2025 v1.0': {
|
|
7
|
+
ocid: 'ocid1.generativeaimodel.oc1.eu-frankfurt-1.amaaaaaask7dceyaaypm2hg4db3evqkmjfdli5mggcxrhp2i4qmhvggyb4ja',
|
|
8
|
+
release_date: '2025-03-01',
|
|
9
|
+
},
|
|
10
|
+
'google.gemini-2.5-flash': {
|
|
11
|
+
ocid: 'ocid1.generativeaimodel.oc1.eu-frankfurt-1.amaaaaaask7dceyacn5rezarysrnds7bjsu6iy5nrxdvq6hyqcygode5o5xq',
|
|
12
|
+
release_date: '2025-03-01',
|
|
13
|
+
},
|
|
14
|
+
'google.gemini-2.5-pro': {
|
|
15
|
+
ocid: 'ocid1.generativeaimodel.oc1.eu-frankfurt-1.amaaaaaask7dceyan6gecfjovk7wtgl3r65b5tmpuegfxojbp2mebjgtvhra',
|
|
16
|
+
release_date: '2025-03-01',
|
|
17
|
+
},
|
|
18
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is a simple wrapper around the OCI Generative AI SDK to make it easier
|
|
3
|
+
* to use in our application. It currently only supports running a text prompt
|
|
4
|
+
* through the "openai.gpt-oss-120b" model and getting a response.
|
|
5
|
+
*/
|
|
6
|
+
export interface OCIGenerativeAIRunOptions {
|
|
7
|
+
temperature?: number;
|
|
8
|
+
}
|
|
9
|
+
export declare class OCIGenerativeAIProvider {
|
|
10
|
+
private readonly ociClient;
|
|
11
|
+
constructor();
|
|
12
|
+
/**
|
|
13
|
+
* Runs a prompt through the OCI Generative AI service and returns the response.
|
|
14
|
+
* This is using the "openai.gpt-oss-120b" model, which is a 120B parameter model
|
|
15
|
+
* based on the open source Falcon-40B-Instruct-v2 architecture,
|
|
16
|
+
* but with more parameters and trained on more data.
|
|
17
|
+
* @param prompt The prompt to run through the model.
|
|
18
|
+
* @param options Optional generation parameters (defaults match the OCI SDK baseline).
|
|
19
|
+
* @returns The response from the model.
|
|
20
|
+
*/
|
|
21
|
+
run(prompt: string, options?: OCIGenerativeAIRunOptions): Promise<string>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/* * */
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { NoRetryConfigurationDetails, Region, SimpleAuthenticationDetailsProvider } from 'oci-common';
|
|
4
|
+
import { GenerativeAiInferenceClient } from 'oci-generativeaiinference';
|
|
5
|
+
import { availableAiModels } from './models.js';
|
|
6
|
+
export class OCIGenerativeAIProvider {
|
|
7
|
+
//
|
|
8
|
+
ociClient;
|
|
9
|
+
constructor() {
|
|
10
|
+
//
|
|
11
|
+
//
|
|
12
|
+
// Validate that all required environment variables are set
|
|
13
|
+
if (!process.env.OCI_AI_FINGERPRINT)
|
|
14
|
+
throw new Error('Missing OCI_AI_FINGERPRINT environment variable for OCI Generative AI Provider');
|
|
15
|
+
if (!process.env.OCI_AI_PRIVATE_KEY_PATH && !process.env.OCI_AI_PRIVATE_KEY)
|
|
16
|
+
throw new Error('Missing OCI_AI_PRIVATE_KEY_PATH or OCI_AI_PRIVATE_KEY environment variable for OCI Generative AI Provider');
|
|
17
|
+
if (!process.env.OCI_AI_REGION)
|
|
18
|
+
throw new Error('Missing OCI_AI_REGION environment variable for OCI Generative AI Provider');
|
|
19
|
+
if (!process.env.OCI_AI_TENANCY)
|
|
20
|
+
throw new Error('Missing OCI_AI_TENANCY environment variable for OCI Generative AI Provider');
|
|
21
|
+
if (!process.env.OCI_AI_USER)
|
|
22
|
+
throw new Error('Missing OCI_AI_USER environment variable for OCI Generative AI Provider');
|
|
23
|
+
if (!process.env.OCI_AI_COMPARTMENT)
|
|
24
|
+
throw new Error('Missing OCI_AI_COMPARTMENT environment variable for OCI Generative AI Provider');
|
|
25
|
+
//
|
|
26
|
+
// Resolve private key
|
|
27
|
+
const privateKeyPath = process.env.OCI_AI_PRIVATE_KEY_PATH;
|
|
28
|
+
const privateKeyValue = process.env.OCI_AI_PRIVATE_KEY;
|
|
29
|
+
if (!privateKeyPath && !privateKeyValue)
|
|
30
|
+
throw new Error('OCI_AI_PRIVATE_KEY or OCI_AI_PRIVATE_KEY_PATH is not set');
|
|
31
|
+
let privateKey;
|
|
32
|
+
if (privateKeyPath)
|
|
33
|
+
privateKey = readFileSync(privateKeyPath, 'utf8');
|
|
34
|
+
else if (privateKeyValue)
|
|
35
|
+
privateKey = privateKeyValue.replace(/\\n/g, '\n');
|
|
36
|
+
else
|
|
37
|
+
throw new Error('Could not resolve private key for OCI Generative AI Provider (missing OCI_AI_PRIVATE_KEY or OCI_AI_PRIVATE_KEY_PATH)');
|
|
38
|
+
//
|
|
39
|
+
// Build the OCI client using the environment variables for authentication
|
|
40
|
+
this.ociClient = new GenerativeAiInferenceClient({
|
|
41
|
+
authenticationDetailsProvider: new SimpleAuthenticationDetailsProvider(process.env.OCI_AI_TENANCY, process.env.OCI_AI_USER, process.env.OCI_AI_FINGERPRINT, privateKey, null, Region.fromRegionId(process.env.OCI_AI_REGION)),
|
|
42
|
+
});
|
|
43
|
+
this.ociClient.endpoint = `https://inference.generativeai.${process.env.OCI_AI_REGION}.oci.oraclecloud.com`;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Runs a prompt through the OCI Generative AI service and returns the response.
|
|
47
|
+
* This is using the "openai.gpt-oss-120b" model, which is a 120B parameter model
|
|
48
|
+
* based on the open source Falcon-40B-Instruct-v2 architecture,
|
|
49
|
+
* but with more parameters and trained on more data.
|
|
50
|
+
* @param prompt The prompt to run through the model.
|
|
51
|
+
* @param options Optional generation parameters (defaults match the OCI SDK baseline).
|
|
52
|
+
* @returns The response from the model.
|
|
53
|
+
*/
|
|
54
|
+
async run(prompt, options) {
|
|
55
|
+
//
|
|
56
|
+
//
|
|
57
|
+
// Build the chat request, in the most complicated way possible
|
|
58
|
+
// because the OCI SDK is a nightmare to work with.
|
|
59
|
+
// (This was written by AI, I swear.)
|
|
60
|
+
const chatRequest = {
|
|
61
|
+
chatDetails: {
|
|
62
|
+
chatRequest: {
|
|
63
|
+
apiFormat: 'GENERIC',
|
|
64
|
+
frequencyPenalty: 0,
|
|
65
|
+
maxTokens: 2048,
|
|
66
|
+
messages: [
|
|
67
|
+
{
|
|
68
|
+
content: [
|
|
69
|
+
{
|
|
70
|
+
// @ts-expect-error — OMG this has to be the most convoluted way to send
|
|
71
|
+
// a simple text message I've ever seen in my life.
|
|
72
|
+
text: prompt,
|
|
73
|
+
type: 'TEXT',
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
role: 'USER',
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
presencePenalty: 0,
|
|
80
|
+
temperature: options?.temperature ?? 0,
|
|
81
|
+
topK: 1,
|
|
82
|
+
topP: 0.95,
|
|
83
|
+
},
|
|
84
|
+
compartmentId: process.env.OCI_AI_COMPARTMENT,
|
|
85
|
+
servingMode: {
|
|
86
|
+
modelId: availableAiModels['google.gemini-2.5-flash'].ocid,
|
|
87
|
+
servingType: 'ON_DEMAND',
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
retryConfiguration: NoRetryConfigurationDetails,
|
|
91
|
+
};
|
|
92
|
+
//
|
|
93
|
+
// Send the chat request and return the response.
|
|
94
|
+
// Again, this is the most convoluted way to get a simple text response from the model.
|
|
95
|
+
const chatResponse = await this.ociClient.chat(chatRequest);
|
|
96
|
+
if (!('chatResult' in chatResponse)) {
|
|
97
|
+
throw new Error('Invalid response from OCI Generative AI service: ' + JSON.stringify(chatResponse));
|
|
98
|
+
}
|
|
99
|
+
if (!('choices' in chatResponse.chatResult.chatResponse)) {
|
|
100
|
+
throw new Error('Invalid response from OCI Generative AI service: ' + JSON.stringify(chatResponse));
|
|
101
|
+
}
|
|
102
|
+
// @ts-expect-error — Yes, I know this is a nightmare to read,
|
|
103
|
+
// but this is the documented way to get the text response from the model.
|
|
104
|
+
return chatResponse.chatResult.chatResponse.choices[0].message.content[0].text;
|
|
105
|
+
//
|
|
106
|
+
}
|
|
107
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tmlmobilidade/go-providers-ai",
|
|
3
|
+
"version": "20260828.1636.54",
|
|
4
|
+
"author": {
|
|
5
|
+
"email": "iso@tmlmobilidade.pt",
|
|
6
|
+
"name": "TML-ISO"
|
|
7
|
+
},
|
|
8
|
+
"license": "AGPL-3.0-or-later",
|
|
9
|
+
"homepage": "https://github.com/tmlmobilidade/go#readme",
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/tmlmobilidade/go/issues"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/tmlmobilidade/go.git"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"public transit",
|
|
19
|
+
"tml",
|
|
20
|
+
"transportes metropolitanos de lisboa",
|
|
21
|
+
"services"
|
|
22
|
+
],
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"type": "module",
|
|
27
|
+
"files": [
|
|
28
|
+
"dist"
|
|
29
|
+
],
|
|
30
|
+
"main": "./dist/index.js",
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsc && resolve-tspaths",
|
|
34
|
+
"lint": "eslint && tsc --noEmit",
|
|
35
|
+
"lint:fix": "eslint --fix",
|
|
36
|
+
"watch": "tsc-watch --onSuccess 'resolve-tspaths'"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"oci-common": "2.139.0",
|
|
40
|
+
"oci-generativeaiinference": "2.139.0"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@tmlmobilidade/go-utils-tsconfig": "*",
|
|
44
|
+
"@types/node": "26.1.2",
|
|
45
|
+
"resolve-tspaths": "0.8.23",
|
|
46
|
+
"tsc-watch": "7.2.1",
|
|
47
|
+
"typescript": "6.0.3"
|
|
48
|
+
}
|
|
49
|
+
}
|