OCI GenAI Cohere Chat
OCI GenAI Service 提供生成式 AI chat,支持按需模型或专用 AI 集群。
OCI Chat Models Page 和 OCI Generative AI Playground 提供了有关在 OCI 上使用和托管 chat models 的详细信息。
Prerequisites
您需要一个活跃的 Oracle Cloud Infrastructure (OCI) 账户才能使用 OCI GenAI Cohere Chat 客户端。客户端提供四种不同的连接方式,包括使用用户和私钥的简单身份验证、workload identity、instance principal 或 OCI 配置文件身份验证。
Add Repositories and BOM
Spring AI artifacts 发布在 Maven Central 和 Spring Snapshot 仓库中。 请参阅 Artifact Repositories 部分,将这些仓库添加到您的构建系统中。
为了帮助进行依赖管理,Spring AI 提供了一个 BOM (bill of materials),以确保在整个项目中使用一致版本的 Spring AI。请参阅 Dependency Management 部分,将 Spring AI BOM 添加到您的构建系统中。
Auto-configuration
注意: Spring AI auto-configuration、starter modules 的 artifact 名称发生了重大变化。 请参阅 upgrade notes 了解更多信息。
Spring AI 为 OCI GenAI Cohere Chat Client 提供 Spring Boot auto-configuration。
要启用它,请将以下依赖项添加到项目的 Maven pom.xml 文件中:
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-model-oci-genai</artifactId>
</dependency>
或添加到您的 Gradle build.gradle 构建文件中。
dependencies {
implementation 'org.springframework.ai:spring-ai-starter-model-oci-genai'
}
提示: 请参阅 Dependency Management 部分,将 Spring AI BOM 添加到您的构建文件中。
Chat Properties
Connection Properties
前缀 spring.ai.oci.genai 是用于配置与 OCI GenAI 连接的属性前缀。
| Property | Description | Default |
|---|---|---|
| spring.ai.oci.genai.authenticationType | 在向 OCI 进行身份验证时使用的身份验证类型。可以是 file、instance-principal、workload-identity 或 simple。 | file |
| spring.ai.oci.genai.region | OCI 服务区域。 | us-chicago-1 |
| spring.ai.oci.genai.tenantId | OCI 租户 OCID,在使用 simple auth 进行身份验证时使用。 | - |
| spring.ai.oci.genai.userId | OCI 用户 OCID,在使用 simple auth 进行身份验证时使用。 | - |
| spring.ai.oci.genai.fingerprint | 私钥指纹,在使用 simple auth 进行身份验证时使用。 | - |
| spring.ai.oci.genai.privateKey | 私钥内容,在使用 simple auth 进行身份验证时使用。 | - |
| spring.ai.oci.genai.passPhrase | 可选的私钥密码短语,在使用 simple auth 和受密码保护的私钥进行身份验证时使用。 | - |
| spring.ai.oci.genai.file | OCI 配置文件的路径。在使用 file auth 进行身份验证时使用。 | /user-home-directory/.oci/config |
| spring.ai.oci.genai.profile | OCI profile 名称。在使用 file auth 进行身份验证时使用。 | DEFAULT |
| spring.ai.oci.genai.endpoint | 可选的 OCI GenAI endpoint。 | - |
Configuration Properties
注意: 现在通过前缀为
spring.ai.model.chat的顶级属性来配置 chat auto-configurations 的启用和禁用。 要启用,spring.ai.model.chat=oci-genai(默认启用) 要禁用,spring.ai.model.chat=none(或任何与 oci-genai 不匹配的值) 此更改是为了允许配置多个模型。
前缀 spring.ai.oci.genai.cohere.chat 是用于配置 OCI GenAI Cohere Chat 的 ChatModel 实现的属性前缀。
| Property | Description | Default |
|---|---|---|
| spring.ai.model.chat | 启用 OCI GenAI Cohere chat model。 | oci-genai |
| spring.ai.oci.genai.cohere.chat.enabled (no longer valid) | 启用 OCI GenAI Cohere chat model。 | true |
| spring.ai.oci.genai.cohere.chat.options.model | Model OCID 或 endpoint | - |
| spring.ai.oci.genai.cohere.chat.options.compartment | Model compartment OCID。 | - |
| spring.ai.oci.genai.cohere.chat.options.servingMode | 要使用的 model serving mode。可以是 on-demand 或 dedicated。 | on-demand |
| spring.ai.oci.genai.cohere.chat.options.preambleOverride | 覆盖 chat model 的 prompt preamble | - |
| spring.ai.oci.genai.cohere.chat.options.temperature | Inference temperature | - |
| spring.ai.oci.genai.cohere.chat.options.topP | Top P 参数 | - |
| spring.ai.oci.genai.cohere.chat.options.topK | Top K 参数 | - |
| spring.ai.oci.genai.cohere.chat.options.frequencyPenalty | 较高的值将减少重复的 tokens,输出将更加随机。 | - |
| spring.ai.oci.genai.cohere.chat.options.presencePenalty | 较高的值鼓励生成使用未使用过的 tokens 的输出。 | - |
| spring.ai.oci.genai.cohere.chat.options.stop | 将结束 completions 生成的文本序列列表。 | - |
| spring.ai.oci.genai.cohere.chat.options.documents | 在 chat context 中使用的文档列表。 | - |
提示: 所有前缀为
spring.ai.oci.genai.cohere.chat.options的属性都可以通过在Prompt调用中添加请求特定的chat-options在运行时覆盖。
Runtime Options [[chat-options]]
OCICohereChatOptions.java 提供模型配置,例如要使用的模型、temperature、frequency penalty 等。