Skip to content
This repository was archived by the owner on Mar 19, 2026. It is now read-only.

Commit a16de60

Browse files
committed
docs(README): update usage examples and clarify project goals
- Add detailed usage examples for CortexLuna API - Explain the project's purpose and its relationship to Vercel AI SDK and Langchain - Simplify the "Should I use CortexLuna?" section - Remove outdated TODO placeholder
1 parent 46172db commit a16de60

File tree

1 file changed

+71
-6
lines changed

1 file changed

+71
-6
lines changed

README.MD

Lines changed: 71 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,83 @@ CortexLuna 基于 Langchain 和 Vercel AI SDK 派生开发。
2222
* [ ] Vector Store 向量存储和检索
2323
* [ ] Hybrid search, bm25 混合向量查询
2424

25+
## 用法
26+
27+
和 Vercel AI SDK 类似,CortexLuna 提供了 `generateText``generateObject` 等 API。
28+
29+
```typescript
30+
const { text, usage, finishReason } = await generatateText({
31+
model: openaiCompatible('gemini-2.0-flash-lite-preview'),
32+
prompt: 'Talk a joke about programming'
33+
})
34+
35+
console.log(text, usage, finishReason)
36+
```
37+
38+
我们也支持 PromptTemplate 格式化:
39+
40+
```typescript
41+
const prompt = promptTemplate(
42+
'Now is {time}. I will ask you a question: {question}. Please answer it.'
43+
)
44+
45+
const chain = bindPromptTemplate(prompt, generatateText)
46+
const { text, usage, finishReason } = await chain({
47+
model: openaiCompatible('gemini-2.0-flash-lite-preview'),
48+
input: {
49+
time: new Date().toLocaleString(),
50+
question: 'what time is it'
51+
}
52+
})
53+
54+
console.log(text, usage, finishReason)
55+
```
56+
57+
流式文本也是支持的:
58+
59+
```typescript
60+
const {textStream, text } = streamText({
61+
model: openaiCompatible('gemini-2.0-flash-lite-preview'),
62+
prompt: 'Talk a joke about programming'
63+
64+
})
65+
for await (const chunk of textStream) {
66+
console.log(chunk)
67+
}
68+
69+
console.log(await text)
70+
```
71+
72+
结构化输出也支持:
73+
74+
```typescript
75+
const { object, usage } = await generateObject({
76+
model: openaiCompatible('gemini-2.0-flash-lite-preview'),
77+
prompt: 'Tell me a joke about programming',
78+
schema: z.object({
79+
joke: z.string().describe('The joke'),
80+
punchline: z.string().describe('The punchline')
81+
})
82+
})
83+
84+
console.log(object, usage)
85+
```
86+
2587
## 我是否应该使用 CortexLuna?
2688

27-
CortexLuna 并不是为了取代 Langchain 或 Vercel AI SDK,而是为了给一部分(像我一样的用户)提供一个更简单,轻量级的 LLM 框架。
89+
看到上面的例子,你会觉得:
2890

29-
由于 Langchain 过于笨重,但是 Vercel AI SDK 的设计又有一些简洁。我尝试将两者结合起来,就形成了 CortexLuna。
91+
> Vercel AI SDK 有什么区别?
3092
31-
> [! TIP]
32-
> 请注意,此项目是实验性的,不应该用于生产环境。
3393

34-
## 用法
94+
从这个角度来看,确实是很接近。因为 CortexLuna 是基于 Vercel AI SDK 派生开发的,所以它的 API 设计也很接近。
95+
96+
但 CortexLuna 并不是为了取代 Langchain 或 Vercel AI SDK,而是为了给其他项目(当然指的是 ChatLuna)提供一个更简单,轻量级的 LLM 框架。
3597

36-
TODO...
98+
Langchain 实在是过于笨重了,我不想再继续依赖它。但 Vercel AI SDK 的设计又有一些简洁,我仍需要扩展一些东西。最后我尝试将两者的部分特定结合起来,就形成了 CortexLuna。
99+
100+
> [!TIP]
101+
> 请注意,此项目是实验性的,不应该用于生产环境。
37102
38103
## 致谢
39104

0 commit comments

Comments
 (0)