Skip to content

Commit 6916bd7

Browse files
committed
feat(docs): update language model documentation with reactive reference usage
- Rename `model` to `modelRef` to reflect ComputedRef return type - Add documentation for passing message lists to ChatLunaChatModel - Include examples for multimodal input with image support - Remove redundant blank line in documentation The changes clarify the usage of reactive values and expand the documented capabilities of the chat model interface, including multimodal support and proper handling of message sequences.
1 parent 324f4a3 commit 6916bd7

File tree

1 file changed

+72
-3
lines changed

1 file changed

+72
-3
lines changed

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

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ const ctx = new Context()
1616
// ---cut---
1717
import type {} from "koishi-plugin-chatluna/services/chat";
1818

19-
const model = await ctx.chatluna.createChatModel("openai/gpt-5-nano")
19+
const modelRef = await ctx.chatluna.createChatModel("openai/gpt-5-nano")
2020
// ^?
2121

2222

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

@@ -31,7 +31,6 @@ console.log(message)
3131
> 自 ChatLuna 1.3.0 开始,ChatLuna 开始深度整合 vue 的响应式系统。如果返回的值为 `ComputedRef<T>`,则代表此值是可以根据其他配置改动进行变化的。
3232
>
3333
> 请先创建这个值并保存到类或者其他地方里面,在需要的时候调用 `ref.value` 来获取真正的值。
34-
3534
> [!WARNING] 警告
3635
> 响应式获取的 `value` 可能会 `undefined`
3736
> 如果返回空值,则说明当前获取的模型或者其他值不存在。你需要提取判断并告知用户,需要的模型或者其他参数不存在。
@@ -40,6 +39,76 @@ console.log(message)
4039

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

42+
## 传入消息列表与多模态
43+
44+
`ChatLunaChatModel` 也可以传入消息列表:
45+
46+
```ts twoslash
47+
// @noImplicitAny: false
48+
// @strictNullChecks: false
49+
import { Context, Schema } from 'koishi'
50+
51+
const ctx = new Context()
52+
53+
// ---cut---
54+
import type {} from "koishi-plugin-chatluna/services/chat"
55+
import { HumanMessage, SystemMessage } from "@langchain/core/messages"
56+
57+
const modelRef = await ctx.chatluna.createChatModel("openai/gpt-5-nano")
58+
59+
const messages = [
60+
new SystemMessage("You are a helpful assistant."),
61+
new HumanMessage("你好,世界!")
62+
]
63+
64+
const message = await modelRef.value?.invoke(messages)
65+
console.log(message)
66+
// ^?
67+
68+
69+
```
70+
71+
并且支持多模态消息(目前仅支持图片,还需确保使用的模型支持多模态输入):
72+
73+
```ts twoslash
74+
// @noImplicitAny: false
75+
// @strictNullChecks: false
76+
import { Context, Schema } from 'koishi'
77+
78+
const ctx = new Context()
79+
80+
// ---cut---
81+
import type {} from "koishi-plugin-chatluna/services/chat"
82+
import { HumanMessage, SystemMessage } from "@langchain/core/messages"
83+
84+
const modelRef = await ctx.chatluna.createChatModel("openai/gpt-5-nano")
85+
86+
const messages = [
87+
new SystemMessage("You are a helpful assistant."),
88+
new HumanMessage({
89+
content: [
90+
{
91+
type: "image_url",
92+
image_url: {
93+
// 也支持 base64 编码的图片
94+
url: "https://example.com/image.png"
95+
}
96+
},
97+
{
98+
type: "text",
99+
content: "图片上的内容是什么?"
100+
}
101+
]
102+
})
103+
]
104+
105+
const message = await modelRef.value?.invoke(messages)
106+
console.log(message)
107+
// ^?
108+
109+
110+
```
111+
43112
## 获取可用的模型
44113

45114
在 ChatLuna 中,实际掌握各类模型和平台的是 `PlatformService` 类。

0 commit comments

Comments
 (0)