Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
OurBuilding Ambient Agents with LangGraph course is now available on LangChain Academy!
Open In ColabOpen on GitHub

ChatOCIGenAI

This notebook provides a quick overview for getting started with OCIGenAIchat models. For detailed documentation of all ChatOCIGenAI features and configurations head to theAPI reference.

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 availablehere andhere.

Overview

Integration details

ClassPackageLocalSerializableJS support
ChatOCIGenAIlangchain-community

Model features

Tool callingStructured outputJSON modeImage inputAudio inputVideo inputToken-level streamingNative asyncToken usageLogprobs

Setup

To access OCIGenAI models you'll need to install theoci andlangchain-community packages.

Credentials

The credentials and authentication methods supported for this integration are equivalent to those used with other OCI services and follow thestandard SDK authentication methods, specifically API Key, session token, instance principal, and resource principal.

API key is the default authentication method used in the examples above. The following example demonstrates how to use a different authentication method (session token)

Installation

The LangChain OCIGenAI integration lives in thelangchain-community package and you will also need to install theoci package:

%pip install-qU langchain-community oci

Instantiation

Now we can instantiate our model object and generate chat completions:

from langchain_community.chat_models.oci_generative_aiimport ChatOCIGenAI
from langchain_core.messagesimport AIMessage, HumanMessage, SystemMessage

chat= ChatOCIGenAI(
model_id="cohere.command-r-16k",
service_endpoint="https://inference.generativeai.us-chicago-1.oci.oraclecloud.com",
compartment_id="MY_OCID",
model_kwargs={"temperature":0.7,"max_tokens":500},
)

Invocation

messages=[
SystemMessage(content="your are an AI assistant."),
AIMessage(content="Hi there human!"),
HumanMessage(content="tell me a joke."),
]
response= chat.invoke(messages)
print(response.content)

Chaining

We canchain our model with a prompt template like so:

from langchain_core.promptsimport ChatPromptTemplate

prompt= ChatPromptTemplate.from_template("Tell me a joke about {topic}")
chain= prompt| chat

response= chain.invoke({"topic":"dogs"})
print(response.content)
API Reference:ChatPromptTemplate

API reference

For detailed documentation of all ChatOCIGenAI features and configurations head to the API reference:https://python.langchain.com/api_reference/community/chat_models/langchain_community.chat_models.oci_generative_ai.ChatOCIGenAI.html

Related


[8]ページ先頭

©2009-2025 Movatter.jp