@mathrunet/masamune
Version:
Manages packages for the server portion (NodeJS) of the Masamune framework.
117 lines • 5.38 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const functions = __importStar(require("firebase-functions/v2"));
const api_1 = require("../lib/api");
/**
* The text is generated using Open AI's GPT.
*
* Open AIのChat GPTを利用して文章を生成します。
*
* @param process.env.OPENAI_APIKEY
* Set the API key, which can be obtained from the following URL.
*
* 下記URLから取得できるAPIキーを設定します。
*
* https://platform.openai.com/account/api-keys
*
* @param message
* Specify the actual message to be passed.
*
* 実際に渡すメッセージを指定します。
*
* @param model
* Specifies the model to be used. Default is `gpt-3.5-turbo`.
*
* 使用するモデルを指定します。デフォルトは`gpt-3.5-turbo`。
*
* @param temperature
* Specify the sampling temperature (*) between 0 and 1.
* The lower the value, the more relevant words are likely to be selected; the higher the value, the more diverse words are likely to be selected.
*
* サンプリング温度(※)を 0〜1 の間で指定します。
* 値が低いほど、より関連性の高い単語が選ばれやすくなり、値が高いほど、より多様な単語が選ばれやすくなります。
*/
module.exports = (regions, options, data) => {
var _a, _b, _c, _d;
return functions.https.onCall({
region: (_a = options.region) !== null && _a !== void 0 ? _a : regions,
timeoutSeconds: options.timeoutSeconds,
memory: options.memory,
minInstances: options.minInstances,
concurrency: options.concurrency,
maxInstances: options.maxInstances,
serviceAccount: (_b = options === null || options === void 0 ? void 0 : options.serviceAccount) !== null && _b !== void 0 ? _b : undefined,
enforceAppCheck: (_c = options.enforceAppCheck) !== null && _c !== void 0 ? _c : undefined,
consumeAppCheckToken: (_d = options.consumeAppCheckToken) !== null && _d !== void 0 ? _d : undefined,
}, (query) => __awaiter(void 0, void 0, void 0, function* () {
var _a, _b, _c, _d;
try {
const apiKey = (_a = process.env.OPENAI_APIKEY) !== null && _a !== void 0 ? _a : "";
const message = (_b = query.data.message) !== null && _b !== void 0 ? _b : [];
const model = (_c = query.data.model) !== null && _c !== void 0 ? _c : "gpt-3.5-turbo";
const temperature = (_d = query.data.temperature) !== null && _d !== void 0 ? _d : 1;
if (message.length <= 0) {
throw new functions.https.HttpsError("invalid-argument", "No content specified in `message`.");
}
const res = yield api_1.Api.post("https://api.openai.com/v1/chat/completions", {
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${apiKey}`,
},
data: JSON.stringify({
"model": model,
"messages": message,
"temperature": temperature,
}),
});
return (yield res.json());
}
catch (err) {
console.log(err);
throw err;
}
}));
};
//# sourceMappingURL=openai_chat_gpt.js.map