
---
url: /mod/openai.md
---
# x openai

集成 OpenAI API，提供强大的 AI 能力，包括 ChatGPT 对话、文本生成、图片创作、语音转换等


::: tip
- 获取 OpenAI 的私人令牌: https://platform.openai.com/api-keys
- 快速初始化配置：在交互环境中运行 `x openai init`，配置将本地保存
- 直接添加 API 密钥：运行命令 `x openai --cfg apikey=<apikey>`
:::


## 例子

使用 OpenAI 生成 Git 提交信息

```sh
git diff | @gpt generate a suitable Git commit message that follows the Conventional Commits format
```

使用 OpenAI 把文件内容翻译为中文

```sh
@gpt --file ./abstract.en.md --file ./content.en.md "Translate to chinese"
```

把文件内容翻译为中文

```sh
x openai chat request --file ./abstract.en.md --file ./content.en.md "Translate to chinese"
```

生成一张狗的图片

```sh
x openai image create --prompt "a dog"
```

将文本转为语音

```sh
x openai audio generate --input "hello x-cmd" --model tts-1 --voice alloy
```
## 介绍

OpenAI 模块是由 x-cmd 开发的命令行工具，用于与 OpenAI 的模型进行交互。

## 子命令

| 名称 | 描述 |
| ------- | ------- |
| [x openai init](/mod/openai/init.md) | 交互式初始化配置 |
| [x openai --cfg](/mod/openai/--cfg.md) | 配置管理，可管理 apikey、请求默认代理等配置 |
| [x openai --cur](/mod/openai/--cur.md) | 当前会话默认值管理 |
| [x openai chat](/mod/openai/chat.md) | 与 OpenAI 对话 |
| [x openai audio](/mod/openai/audio.md) | 语音和文字互相转换 |
| [x openai image](/mod/openai/image.md) | 图片生成 |
| [x openai finetuning](/mod/openai/finetuning.md) | 微调模型管理 |
| [x openai embedding](/mod/openai/embedding.md) | 文本向量计算 |
| [x openai model](/mod/openai/model.md) | 获取模型的信息 |
