|
| 1 | +/** |
| 2 | + * Copyright (c) 2020, 2021 Oracle and/or its affiliates. All rights reserved. |
| 3 | + * This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license. |
| 4 | + */ |
| 5 | + |
| 6 | +/* |
| 7 | + * This example demonstrates to get embeddings response for the given inputs to Cohere llm. |
| 8 | + * In order to run this example, this code must be in an Oracle Cloud instance. |
| 9 | + */ |
| 10 | + |
| 11 | +import { GenerativeAiInferenceClient, models, requests } from "oci-generativeaiinference"; |
| 12 | +import { |
| 13 | + SessionAuthDetailProvider, |
| 14 | + NoRetryConfigurationDetails |
| 15 | +} from "oci-common"; |
| 16 | + |
| 17 | +// TODO: Please update config profile name and use the compartmentId that has policies grant permissions for using Generative AI Service |
| 18 | +const CONFIG_LOCATION = "~/.oci/config"; |
| 19 | +const CONFIG_PROFILE = "DEFAULT"; |
| 20 | +const COMPARTMENT_ID = ""; // Fill-in with compartment Id with access to generative AI API |
| 21 | + |
| 22 | +(async () => { |
| 23 | + // Configuring the AuthenticationDetailsProvider. It's assuming there is a default OCI config file "~/.oci/config", and |
| 24 | + // a profile in that config with the name defined in CONFIG_PROFILE variable. |
| 25 | + const provider = new SessionAuthDetailProvider(CONFIG_LOCATION, CONFIG_PROFILE) |
| 26 | + provider.setRegion("us-chicago-1"); |
| 27 | + |
| 28 | + const client = new GenerativeAiInferenceClient({ |
| 29 | + authenticationDetailsProvider: provider, |
| 30 | + } |
| 31 | + ); |
| 32 | + |
| 33 | + // On Demand Serving Mode |
| 34 | + // Check a list of pretrained Cohere Embedding Models availability in different regions: |
| 35 | + // https://docs.oracle.com/en-us/iaas/Content/generative-ai/pretrained-models.htm#pretrained-models |
| 36 | + const servingMode: models.OnDemandServingMode = { |
| 37 | + modelId: "cohere.embed-english-v3.0", |
| 38 | + servingType: "ON_DEMAND", |
| 39 | + }; |
| 40 | + |
| 41 | + // Dedicated Serving Mode |
| 42 | + // const servingMode: models.DedicatedServingMode = { |
| 43 | + // endpointId: "", // Fill-in with endpoint Id, if you have active Dedicated AI cluster resource |
| 44 | + // servingType: "DEDICATED", |
| 45 | + // }; |
| 46 | + |
| 47 | + // Embed Details |
| 48 | + const embedRequest: requests.EmbedTextRequest = { |
| 49 | + embedTextDetails: { |
| 50 | + inputs: ["In order to maintain our growth, we need to track our billings to ensure we are charging our customers enough to support our business."," We have a system in place to track our billings and ensure we are billing our customers accurately."," We have a dedicated billing team that is responsible for generating invoices and tracking payments."," Our billing system is integrated with our customer relationship management (CRM) system, which allows us to track our billings and customer interactions in one place."," We use a third-party billing service to help us manage our billings and ensure we are billing our customers correctly."," We are committed to providing our customers with accurate billings and clear explanations of our charges."," Timely and accurate billing is important to our customers, and we strive to provide them with the best possible service."," We are constantly looking for ways to improve our billing process and ensure we are billing our customers fairly."," We are committed to being transparent with our customers about our billing process and how we calculate our charges."," Billing can be a complex process, and we are here to help our customers understand their bills and answer any questions they may have."," We value our customers and want to ensure that they are happy with our billing process and the services we provide."], |
| 51 | + truncate: models.EmbedTextDetails.Truncate.None, |
| 52 | + servingMode: servingMode, |
| 53 | + compartmentId: COMPARTMENT_ID, |
| 54 | + }, |
| 55 | + retryConfiguration: NoRetryConfigurationDetails |
| 56 | + } |
| 57 | + |
| 58 | + const embedResponse = await client.embedText(embedRequest) |
| 59 | + |
| 60 | + // Print embed text response |
| 61 | + console.log("**************************Embed Texts Response**************************") |
| 62 | + console.log(JSON.stringify(embedResponse)) |
| 63 | + |
| 64 | +})(); |
0 commit comments