-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
969c78b
commit 3eb3c83
Showing
3 changed files
with
53 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# 混元助手 | ||
|
||
在这里获取你的 [API密钥](https://console.cloud.tencent.com/cam/capi) 。 | ||
|
||
## 通用对话 | ||
|
||
当前支持 `hunyuan` 模型。 | ||
|
||
```ts | ||
import { HunYuanAI } from '@zhengxs/ai'; | ||
|
||
const client = new HunYuanAI({ | ||
appId: 'My APP ID', // defaults to process.env["HUNYUAN_APP_ID"] | ||
secretId: 'My Secret ID', // defaults to process.env["HUNYUAN_SECRET_ID"] | ||
secretKey: 'My Secret Key', // defaults to process.env["HUNYUAN_SECRET_KEY"] | ||
}); | ||
|
||
async function main() { | ||
const chatCompletion = await client.chat.completions.create({ | ||
model: 'hunyuan', | ||
messages: [{ role: 'user', content: 'Say this is a test' }], | ||
}); | ||
} | ||
|
||
main(); | ||
``` | ||
|
||
### 支持流式 | ||
|
||
```ts | ||
import { HunYuanAI } from '@zhengxs/ai'; | ||
|
||
const client = new HunYuanAI(); | ||
|
||
async function main() { | ||
const stream = await client.chat.completions.create({ | ||
model: 'hunyuan', | ||
messages: [{ role: 'user', content: 'Say this is a test' }], | ||
stream: true, | ||
}); | ||
|
||
for await (const chunk of stream) { | ||
process.stdout.write(chunk.choices[0]?.delta?.content || ''); | ||
} | ||
} | ||
|
||
main(); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters