2025 Mar 11 7:20 PM - edited 2025 Mar 17 9:31 PM
Hello Experts
I am working with the @SAP-ai-sdk/ai-api library to connect to a configured Generative AI Hub and query the available models. However, I'm having trouble identifying the correct API or function within the SDK to use in order to retrieve the results.
async function main() {
try {
const { GenerativeAIHubClient } = await import('@sap-ai-sdk/ai-api'); // Dynamic import
const client = new GenerativeAIHubClient({
uaa: {
url: process.env.GENAI_HUB_TOKEN_URL, // UAA URL from service key
clientId: process.env.GENAI_HUB_CLIENT_ID, // Client ID from service key
clientSecret: process.env.GENAI_HUB_CLIENT_SECRET, // Client secret from service key
},
baseUrl: process.env.GENAI_HUB_URL, // Base URL from service key or env variable.
});
// List Models
const models = await client.listModels();
console.log("Available Models:", models);
// Invoke Model
const invokeResponse = await GenerativeAIHubClient.invokeModel({
modelId: 'sap/generative-text', // Model ID
prompt: "Explain SAP BTP in simple terms."
});
console.log("AI Response:", invokeResponse.output);
} catch (error) {
console.error("Error:", error);
if (error.response) {
console.error("Response Data:", error.response.data);
}
}
}
main();
Getting this error as this api is not available in the sdk export list.
ERROR TypeError: GenerativeAIHubClient is not a constructor
Could someone please guide me on the proper method/function/approach (Not using Python) to invoke and get the desired output from the Generative AI Hub?
Request clarification before answering.
I would need to check how it is done in JavaScript SDK, because in Python SDK it is enough to set the environment variables or a config file `~/.aicore/config.json` as per https://help.sap.com/doc/generative-ai-hub-sdk/CLOUD/en-US/_reference/README_sphynx.html#configurati....
Then the code automatically initiates a client with credentials from those configurations, without an explicit read from env variables or from that config file in your code.
But that's how it is done in Python, and I would need to check how it is done in JS.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
88 | |
9 | |
9 | |
8 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.