Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ OPENAI_API_KEY=

# Optional: custom OpenAI-compatible base URL
# 留空时使用 OpenAI 默认地址;DeepSeek 可填写 https://api.deepseek.com
OPENAI_API_BASE_URL=https://api.deepseek.com
OPENAI_API_BASE_URL=xxx

# Optional: memory persistence file path
# 默认 .agent-memory/memory.json,通常无需修改
# AGENT_MEMORY_FILE=.agent-memory/memory.json

# Optional: OpenAI-compatible model name
# 默认 deepseek-v4-flash
OPENAI_MODEL=deepseek-v4-flash
# Required: OpenAI-compatible model name
# 必填,无默认值;未配置时 CLI 会提示你设置 OPENAI_MODEL
OPENAI_MODEL=xxx

# Optional: override the desktop directory used by path aliases
# 默认 ~/Desktop,用于测试或自定义工作环境
Expand Down
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
node_modules
package.json
pnpm-lock.yaml
yarn.lock
.env
.env.local
Expand All @@ -23,5 +21,5 @@ out
.agent-memory/
bundle.*
docs/*
Agent.md
/test/
pnpm-workspace.yaml
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,7 @@ vitest.config.ts # Vitest 测试配置
```bash
cp .env.example .env
pnpm install
```

CLI 启动方式取决于项目实际的 `package.json` scripts;当前仓库中主要入口是 `source/app.tsx`。如果使用 `tsx`,可直接运行:

```bash
pnpm exec tsx source/app.tsx
pnpm dev
```

## 环境变量
Expand All @@ -89,7 +84,7 @@ pnpm exec tsx source/app.tsx
| --- | --- |
| `OPENAI_API_KEY` | 必填,OpenAI 兼容 API 的 Key。 |
| `OPENAI_API_BASE_URL` | 可选,自定义 OpenAI 兼容 base URL。 |
| `OPENAI_MODEL` | 可选,模型名称,默认 `deepseek-v4-flash`。 |
| `OPENAI_MODEL` | 必填,模型名称,无默认值;未配置时 CLI 会提示。 |
| `AGENT_MEMORY_FILE` | 可选,记忆持久化文件路径,默认 `.agent-memory/memory.json`。 |
| `AGENT_DESKTOP_DIR` | 可选,覆盖桌面目录路径,便于测试或自定义工作环境。 |

Expand All @@ -98,6 +93,9 @@ pnpm exec tsx source/app.tsx
以下命令与当前 CI 保持一致:

```bash
# 启动 CLI
pnpm dev

# 类型检查
pnpm exec tsc -p tsconfig.json --noEmit

Expand Down
30 changes: 30 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "call-code",
"version": "0.1.0",
"private": true,
"type": "module",
"scripts": {
"dev": "tsx source/app.tsx",
"start": "tsx source/app.tsx",
"typecheck": "tsc -p tsconfig.json --noEmit",
"test": "vitest run --reporter verbose",
"build:agent-core": "tsc -p packages/agent-core/tsconfig.json"
},
"dependencies": {
"dotenv": "^17.4.2",
"ink": "^7.1.1",
"ink-spinner": "^5.0.0",
"ink-text-input": "^6.0.0",
"openai": "^6.34.0",
"react": "^19.2.8",
"tiktoken": "^1.0.20"
},
"devDependencies": {
"@types/node": "^25.6.0",
"@types/react": "^19.2.18",
"prettier": "^3.4.2",
"tsx": "^4.23.7",
"typescript": "^6.0.3",
"vitest": "^3.2.4"
}
}
18 changes: 16 additions & 2 deletions packages/agent-core/src/core/llm.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import 'dotenv/config';
import dotenv from 'dotenv';
import { OpenAI } from 'openai';

dotenv.config();
dotenv.config({ path: '.env.local' });
Comment on lines +4 to +5

export interface Message {
role: 'system' | 'user' | 'assistant';
content: string;
Expand All @@ -19,9 +22,16 @@ const client = new OpenAI({
baseURL: process.env.OPENAI_API_BASE_URL,
});

const llmModel = process.env.OPENAI_MODEL ?? 'deepseek-v4-flash';
export const llmModel = process.env.OPENAI_MODEL ?? '';

const missingModelMessage =
'你没有配置 OPENAI_MODEL,请在 .env 或 .env.local 中设置模型名称。';

export async function callLLM(messages: Message[]) {
if (!llmModel) {
throw new Error(missingModelMessage);
}

const res = await client.chat.completions.create({
model: llmModel,
messages,
Expand All @@ -38,6 +48,10 @@ export async function streamLLM(
handlers.onStart?.();

try {
if (!llmModel) {
throw new Error(missingModelMessage);
}

const stream = await client.chat.completions.create({
model: llmModel,
messages,
Expand Down
Loading
Loading