OCI Generative AI Sample Bot

Whether you are taking an Oracle Generative AI workshop or pursuing Oracle Generative AI Professional certification, you can't miss the OCI Generative AI ChatBot sample code.

The code is in the GitHub public repository and allows you to build a simple AI-powered web chat using well-known frameworks such as LangChain and Streamlit.

I don't want to discuss the code itself too deeply. It is not overly complicated, but you may run into another "API drift," as I have. So here is a little tip on how to make it work.

After completing all the prerequisites, configure OCI CLI, install all the libraries, and clone the code. This is the GenAI initialization part.

llm = OCIGenAI(
        model_id="cohere.command",
        service_endpoint="https://inference.generativeai.us-chicago-1.oci.oraclecloud.com",
        compartment_id="<<your compartment id>>",
        model_kwargs={"max_tokens":200}
        )

Original code.

This code works if you use only the default configuration API keys, but for complex OCI client configurations, you may want to adjust your code with two more parameters:

llm = OCIGenAI(
        model_id="cohere.command",
        service_endpoint="https://inference.generativeai.us-chicago-1.oci.oraclecloud.com",
        compartment_id="<<your compartment id>>",
        model_kwargs={"max_tokens":200},
    auth_profile="CHICAGO",
    auth_type="SECURITY_TOKEN"
)

Additional authentication parameters.

Those two parameters point the code to the right OCI configuration profile and specify the correct authentication method.