contextual-client Python SDK。在此处了解更多信息。
概述
此集成调用 Contextual AI 的 Grounded Language Model。集成详情
| Class | Package | Local | Serializable | JS support | Downloads | Version |
|---|---|---|---|---|---|---|
| ChatContextual | langchain-contextual | ❌ | beta | ❌ |
模型功能
| Tool calling | Structured output | JSON mode | Image input | Audio input | Video input | Token-level streaming | Native async | Token usage | Logprobs |
|---|---|---|---|---|---|---|---|---|---|
| ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
设置
要访问 Contextual 模型,您需要创建 Contextual AI 帐户、获取 API 密钥并安装langchain-contextual 集成包。
凭证
前往 app.contextual.ai 注册 Contextual 并生成 API 密钥。完成后,设置 CONTEXTUAL_AI_API_KEY 环境变量:安装
LangChain Contextual 集成位于langchain-contextual 包中:
实例化
现在我们可以实例化模型对象并生成聊天完成。 可以使用以下附加设置实例化聊天客户端:| Parameter | Type | Description | Default |
|---|---|---|---|
| temperature | Optional[float] | The sampling temperature, which affects the randomness in the response. Note that higher temperature values can reduce groundedness. | 0 |
| top_p | Optional[float] | A parameter for nucleus sampling, an alternative to temperature which also affects the randomness of the response. Note that higher top_p values can reduce groundedness. | 0.9 |
| max_new_tokens | Optional[int] | The maximum number of tokens that the model can generate in the response. Minimum is 1 and maximum is 2048. | 1024 |
调用
Contextual Grounded Language Model 在调用ChatContextual.invoke 方法时接受额外的 kwargs。
这些额外的输入是:
| Parameter | Type | Description |
|---|---|---|
| knowledge | list[str] | Required: A list of strings of knowledge sources the grounded language model can use when generating a response. |
| system_prompt | Optional[str] | Optional: Instructions the model should follow when generating responses. Note that we do not guarantee that the model follows these instructions exactly. |
| avoid_commentary | Optional[bool] | Optional (Defaults to False): Flag to indicate whether the model should avoid providing additional commentary in responses. Commentary is conversational in nature and does not contain verifiable claims; therefore, commentary is not strictly grounded in available context. However, commentary may provide useful context which improves the helpfulness of responses. |