oci_generative_ai
Oracle Cloud Infrastructure Generative AI
Oracle Cloud Infrastructure (OCI) Generative AI is a fully managed service that provides a set of state-of-the-art, customizable large language models (LLMs) that cover a wide range of use cases, and which is available through a single API. Using the OCI Generative AI service you can access ready-to-use pretrained models, or create and host your own fine-tuned custom models based on your own data on dedicated AI clusters. Detailed documentation of the service and API is available here and here.
This notebook explains how to use OCI's Generative AI complete models with LangChain.
Setup
Ensure that the oci sdk and the langchain-community package are installed
!pip install -U oci langchain-community
Usage
from langchain_community.llms.oci_generative_ai import OCIGenAI
llm = OCIGenAI(
model_id="cohere.command",
service_endpoint="https://inference.generativeai.us-chicago-1.oci.oraclecloud.com",
compartment_id="MY_OCID",
model_kwargs={"temperature": 0, "max_tokens": 500},
)
response = llm.invoke("Tell me one fact about earth", temperature=0.7)
print(response)
API Reference:OCIGenAI
Chaining with prompt templates
from langchain_core.prompts import PromptTemplate
llm = OCIGenAI(
model_id="cohere.command",
service_endpoint="https://inference.generativeai.us-chicago-1.oci.oraclecloud.com",
compartment_id="MY_OCID",
model_kwargs={"temperature": 0, "max_tokens": 500},
)
prompt = PromptTemplate(input_variables=["query"], template="{query}")
llm_chain = prompt | llm
response = llm_chain.invoke("what is the capital of france?")
print(response)
API Reference:PromptTemplate