Wednesday, June 28, 2023

Using Chat GPT APIs With Microservices

 The ChatGPT API, developed by OpenAI, is a robust tool for language processing. Built upon the GPT model, it has been trained extensively on vast amounts of text data to produce text that closely resembles human language. By integrating the API into their applications, developers can leverage the power of GPT to create advanced language-based functionalities such as natural language understanding, text generation, and chatbot capabilities.

The ChatGPT API excels in comprehending and responding to natural language input, making it an excellent choice for chatbot applications. It can understand user queries and provide responses that feel natural and human-like. Additionally, the API has the ability to generate text, enabling the automation of responses, summaries, and even entire articles. This feature proves particularly valuable in content creation and summarization scenarios.

Scalability is another key advantage of the ChatGPT API. It can effortlessly handle large volumes of data and seamlessly integrate with other systems and platforms. Furthermore, developers have the flexibility to fine-tune the model according to their specific requirements, leading to improved accuracy and relevance of the generated text.

The ChatGPT API is designed to be user-friendly, with comprehensive documentation and ease of use. It caters to developers of all skill levels and offers a range of software development kits (SDKs) and libraries to simplify integration into applications.


To utilize the ChatGPT API, you will need to follow a few steps:

  • Obtain an API key: To begin using the ChatGPT API, sign up for an API key on the OpenAI website. This key will grant you access to the API's functionalities.
  • Choose a programming language: The ChatGPT API provides SDKs and libraries in various programming languages, including Python, Java, and JavaScript. Select the one that you are most comfortable working with.
  • Install the SDK: After selecting your preferred programming language, install the corresponding SDK or library. You can typically accomplish this using a package manager like pip or npm.
  • Create an API instance: Once you have the SDK installed, create a new instance of the API by providing your API key and any additional required configuration options.
  • Make API requests: With an instance of the API set up, you can start making requests to it. For instance, you can use the "generate" method to generate text based on a given prompt.
  • Process the API response: After receiving a response from the API, process it as necessary. For example, you might extract the generated text from the response and display it within your application.


import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; @Service public class ChatGptService { private final String API_URL = "https://api.openai.com/v1/engines/davinci-codex/completions"; private final String API_KEY = "YOUR_API_KEY"; public String getChatResponse(String prompt) { RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); headers.setBearerAuth(API_KEY); String requestBody = "{\"prompt\": \"" + prompt + "\", \"max_tokens\": 50}"; HttpEntity<String> request = new HttpEntity<>(requestBody, headers); ResponseEntity<ChatGptResponse> response = restTemplate.exchange( API_URL, HttpMethod.POST, request, ChatGptResponse.class ); if (response.getStatusCode().is2xxSuccessful()) { ChatGptResponse responseBody = response.getBody(); if (responseBody != null) { return responseBody.choices.get(0).text; } } return "Failed to get a response from the Chat GPT API."; } }


In the above code, replace "YOUR_API_KEY" with your actual API key obtained from OpenAI. The getChatResponse method takes a prompt as input and sends a POST request to the Chat GPT API to get a response. The response is then extracted and returned as a string.

Note that you need to have the necessary dependencies added to your Spring Boot project, including spring-boot-starter-web and spring-web. Additionally, make sure your project is configured with the necessary versions of Java and Spring Boot.

You can then inject the ChatGptService into your controllers or other Spring components to use the getChatResponse method and retrieve responses from the Chat GPT API.


Sunday, June 11, 2023

Title: Uploading CCB and C2M Data files Files from Oracle Object Store to Oracle Utilities Customer Cloud Service (CCS) using Oracle Integration Cloud (OIC)

 Title: Uploading  CCB/C2M Data files from Oracle Object Store to Oracle Utilities Customer Cloud Service (CCS) using Oracle Integration Cloud (OIC)


Introduction:

As the digital landscape continues to evolve, businesses are adopting cloud-based solutions to streamline their operations. In this blog entry, we will explore how to upload files, such as images or documents, from Oracle Object Store to Oracle Utilities Customer Cloud Service (CCS) using Oracle Integration Cloud (OIC). This integration enables you to seamlessly transfer files from Object Store to CCS, ensuring that your blog entries are enriched with relevant and engaging multimedia content.


Prerequisites:

Before you proceed with the integration, ensure you have the following prerequisites in place:


1. An active Oracle Object Store instance with the files you want to upload.

2. Access to Oracle Utilities Customer Cloud Service (CCS) with the necessary permissions to manage files.

3. Access to Oracle Integration Cloud (OIC) with the required permissions to create integrations.


Step 1: Create an Integration in Oracle Integration Cloud (OIC):

1. Log in to your Oracle Integration Cloud account.

2. Create a new integration by selecting "Create Integration" from the OIC dashboard.

3. Provide a name and description for your integration and select the appropriate package.

4. Choose the integration style that best fits your requirements and click "Create."


Step 2: Configure the Source Connection (Oracle Object Store):

1. Within the integration canvas, click on the plus (+) icon to add a connection.

2. Select "Oracle Storage" from the list of available connections.

3. Provide the necessary details to configure the connection, including the Object Store details, authentication method, and credentials.

4. Test the connection to ensure it is set up correctly.


Step 3: Configure the Target Connection (Oracle Utilities Customer Cloud Service - CCS):

1. Similar to Step 2, add a new connection by clicking on the plus (+) icon.

2. Select "Oracle Utilities" from the connection list.

3. Provide the required details to establish the connection, including the CCS instance URL, authentication method, and credentials.

4. Test the connection to verify its functionality.


Step 4: Design the Integration Flow:

1. On the integration canvas, drag and drop the appropriate start activity, depending on your integration style (e.g., "Scheduled Orchestration," "Event-Driven," etc.).

2. Add a "File Read" activity from the component palette and configure it to read the files from the Oracle Object Store.

3. Connect the "File Read" activity to a "File Write" activity representing the target connection to CCS.

4. Configure the "File Write" activity to upload the files to the desired location in CCS.

5. Optionally, you can add additional activities or transformations to modify the file or metadata during the integration flow.

6. Save the integration.


Step 5: Configure the Trigger (if using Event-Driven style):

1. If you chose the "Event-Driven" style, configure the trigger by selecting the appropriate event (e.g., file upload event) that will initiate the integration.

2. Set up the event parameters, such as the Object Store bucket and event filters.

3. Save the trigger configuration.


Step 6: Activate and Monitor the Integration:

1. Activate the integration by clicking the "Activate" button in the top-right corner of the OIC interface.

2. Monitor the integration runs and logs to ensure the successful transfer of files from Object Store to CCS.

3. Test the integration by manually triggering it or performing the event that initiates the integration.


Conclusion:

By integrating Oracle Object Store with Oracle Utilities Customer Cloud Service (CCS) using Oracle Integration Cloud (OIC), you can effortlessly upload blog entry files, enriching your content with multimedia

Sunday, June 4, 2023

Null Pointer at com.sforce.ws.codegen.Compiler.(Compiler.java:48)

When compiling enterprise.wsdl with  force-wsc-58.0.0-uber.jar I was getting the following exception:


$ java -classpath force-wsc-58.0.0-uber.jar com.sforce.ws.tools.wsdlc enterprise-58-0.wsdl enterprise-58-0.0.jar

[WSC][wsdlc.main:72]Generating Java files from schema ...

[WSC][wsdlc.main:72]Generated 2724 java files.

Exception in thread "main" java.lang.NullPointerException

        at com.sforce.ws.codegen.Compiler.<init>(Compiler.java:48)

        at com.sforce.ws.codegen.Generator.compileTypes(Generator.java:137)

        at com.sforce.ws.tools.wsdlc.run(wsdlc.java:129)

        at com.sforce.ws.tools.wsdlc.run(wsdlc.java:163)

        at com.sforce.ws.tools.wsdlc.main(wsdlc.java:72)


To resolve this issue, I pointed to Oracle JDK and that resolved the issue:

$ /c/jdk1-8-0_202/bin/java -classpath force-wsc-58.0.0-uber.jar com.sforce.ws.tools.wsdlc enterprise-58-0.wsdl enterprise-58-0.0.jar
[WSC][wsdlc.main:72]Generating Java files from schema ...
[WSC][wsdlc.main:72]Generated 2724 java files.
[WSC][wsdlc.main:72]Compiled 2728 java files.
[WSC][wsdlc.main:72]Generating jar file ... enterprise-58-0.0.jar
[WSC][wsdlc.main:72]Generated jar file enterprise-58-0.0.jar

Thursday, June 1, 2023

Create HDFS Agent for Oracle Integration Cloud Generation 3

 Create HDFS Agent for Oracle Integration Cloud Generation 3

Oracle Integration 3 is a fully managed, preconfigured environment that gives you the power to integrate your cloud and on-premises applications, automate business processes, develop visual applications, use an SFTP-compliant file server to store and retrieve files, and exchange business documents with a B2B trading.

This code will create an HDFS agent that connects to a Hadoop Distributed File System (HDFS) cluster running on localhost. The agent will be started and then stopped. You can use this code as a starting point for creating your own HDFS agents.

Here are some additional notes about the code:

  • The HdfsAgentProperties class is used to configure the HDFS agent. The properties that can be configured include the HDFS URL, username, and password.
  • The HdfsAgentFactory class is used to create HDFS agents. The factory can be used to create agents that connect to different types of HDFS clusters.
  • The start() and stop() methods are used to start and stop the HDFS agent.


Code Snippet

Code snippet
import com.oracle.integration.cloud.agent.hdfs.HdfsAgent;
import com.oracle.integration.cloud.agent.hdfs.HdfsAgentFactory;
import com.oracle.integration.cloud.agent.hdfs.HdfsAgentProperties;

public class CreateHdfsAgent {

    public static void main(String[] args) throws Exception {
        // Create the HDFS agent properties
        HdfsAgentProperties properties = new HdfsAgentProperties();
        properties.setHdfsUrl("hdfs://localhost:9000");
        properties.setHdfsUsername("user");
        properties.setHdfsPassword("password");

        // Create the HDFS agent
        HdfsAgent agent = HdfsAgentFactory.create(properties);

        // Start the HDFS agent
        agent.start();

        // Do something with the HDFS agent
        // ...

        // Stop the HDFS agent
        agent.stop();
    }
}

 


OCI Knowledge Series: OCI Infrastructure components

  Oracle Cloud Infrastructure (OCI) provides a comprehensive set of infrastructure services that enable you to build and run a wide range of...