Skip to content

Commit

Permalink
add ai
Browse files Browse the repository at this point in the history
  • Loading branch information
Xicheng Guo committed Apr 10, 2024
1 parent 30e046f commit 81ca641
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 14 deletions.
3 changes: 2 additions & 1 deletion src/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ export default defineConfig(
nav: [
{ text: 'Home', link: '/' },
{ text: 'JavaScript', link: '/javascript/index' },
{ text: '前端', link: '/frontend/react/jsx' },
{ text: '前端', link: '/frontend/index' },
{ text: '后端', link: '/backend/nodejs/index' },
{ text: 'AI', link: '/artificial-intelligence/index'},
{ text: '参考', link: '/reference' }
],

Expand Down
3 changes: 3 additions & 0 deletions src/.vitepress/sidebar.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,6 @@
link: /backend/nodejs/event-emitter
- text: File System
link: /backend/nodejs/file-system
/artificial-intelligence:
- text: OpenAI API
link: /artificial-intelligence/openai-api
Empty file.
32 changes: 32 additions & 0 deletions src/artificial-intelligence/openai-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# OpenAI API

## 基本用法

可以使用POST请求向OpenAI API提交内容,其中**content**字段包含提问与回答的内容。

**temperature**用于控制生成文本的创造性,值越高,生成的文本越有创造性。

::: code-group

<<< @/../projects/javascript-sandbox/src/openai/basic-usage.ts [Request]

<<< @/../projects/javascript-sandbox/src/openai/basic-usage-output.json [Response]

:::

## 连续对话

连续对话需要把每一次的提问和回答都追加到`messages`数组中,以便OpenAI能够理解对话的上下文。

**role**可用于指定对话的角色:
- `user`:表示用户的提问
- `assistant`:表示助手的回答
- `system`:用于定义整个对话的行为,通常放在`messages`数组的第一个元素

::: code-group

<<< @/../projects/javascript-sandbox/src/openai/chat-usage.ts [Request]

<<< @/../projects/javascript-sandbox/src/openai/chat-usage-output.json [Response]

:::
Empty file added src/frontend/index.md
Empty file.
2 changes: 2 additions & 0 deletions src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,6 @@ import MarkMap from './MarkMap.vue';
- [NodeJS](backend/nodejs/index)
- [EventEmitter](backend/nodejs/event-emitter)
- [File System](backend/nodejs/file-system)
- AI
- [OpenAI API](artificial-intelligence/openai-api)
"/>
34 changes: 21 additions & 13 deletions sync.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,30 @@ import fs from "fs";

(async () => {
const projectsDir = './projects';
const repoURL = 'https://github.com/GuoXiCheng/react-sandbox.git';
let cloneCommand;

// 使用数组来支持多个repoURL
const repoURLs = [
'https://github.com/GuoXiCheng/react-sandbox.git',
'https://github.com/GuoXiCheng/javascript-sandbox.git',
];

if (!fs.existsSync(projectsDir)) {
fs.mkdirSync(projectsDir);
}

repoURLs.forEach(repoURL => {
let cloneCommand;

if (process.env.CI) {
// 在CI环境中
const token = process.env.GITHUB_TOKEN; // 确保在CI环境中已设置GITHUB_TOKEN
cloneCommand = `git clone https://${token}:x-oauth-basic@${repoURL.replace('https://', '')}`;
} else {
// 在本地环境中
cloneCommand = `git clone ${repoURL}`;
}
if (process.env.CI) {
// 在CI环境中
const token = process.env.GITHUB_TOKEN; // 确保在CI环境中已设置GITHUB_TOKEN
cloneCommand = `git clone https://${token}:x-oauth-basic@${repoURL.replace('https://', '')}`;
} else {
// 在本地环境中
cloneCommand = `git clone ${repoURL}`;
}

// 在projects目录中克隆仓库
execSync(cloneCommand, { cwd: projectsDir });
// 在projects目录中克隆仓库
execSync(cloneCommand, { cwd: projectsDir });
});
})();

0 comments on commit 81ca641

Please sign in to comment.