Skip to content

Commit 324f4a3

Browse files
committed
docs(development): update language model documentation with optional chaining and warnings
- Add optional chaining operator to model invocation example - Include warning about potential undefined values when accessing reactive properties - Document the need for explicit checks when model or parameters are missing
1 parent b53bfb3 commit 324f4a3

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

docs/development/call-core-services/language-model.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const model = await ctx.chatluna.createChatModel("openai/gpt-5-nano")
2020
// ^?
2121

2222

23-
const message = await model.value.invoke("你好,世界!")
23+
const message = await model.value?.invoke("你好,世界!")
2424
console.log(message)
2525
// ^?
2626

@@ -32,6 +32,10 @@ console.log(message)
3232
>
3333
> 请先创建这个值并保存到类或者其他地方里面,在需要的时候调用 `ref.value` 来获取真正的值。
3434
35+
> [!WARNING] 警告
36+
> 响应式获取的 `value` 可能会 `undefined`
37+
> 如果返回空值,则说明当前获取的模型或者其他值不存在。你需要提取判断并告知用户,需要的模型或者其他参数不存在。
38+
3539
`ChatLunaChatModel` 继承自 [`BaseChatModel`](https://v03.api.js.langchain.com/classes/_langchain_core.language_models_chat_models.BaseChatModel.html)
3640

3741
你可以直接使用 `BaseChatModel` 的所有方法,并和 LangChain 的其他 API 无缝衔接。

0 commit comments

Comments
 (0)