Skip to content

Commit bf9ad9d

Browse files
Easier CLI config & O1 models.
1 parent 948e072 commit bf9ad9d

File tree

12 files changed

+242
-88
lines changed

12 files changed

+242
-88
lines changed

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"cwd": "${workspaceFolder}",
77
"name": "CLI",
88
"request": "launch",
9-
"runtimeArgs": ["run", "debug"],
9+
"runtimeArgs": ["run", "debug", "--", "-rv"],
1010
"runtimeExecutable": "npm",
1111
"type": "node"
1212
},

README.md

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,38 @@ Codeye is a revolutionary [Visual Studio Code](https://code.visualstudio.com/) e
1313

1414
## Getting Started
1515

16-
1. **Install Codeye**: Search for **Codeye** in the [Visual Studio Code](https://code.visualstudio.com/) **Extensions** tab or visit the [Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=codeye.codeye) for quick installation.
17-
2. **Select AI Model**: Navigate to `Settings` > `Extensions` > `Codeye` and choose you desired AI model.
18-
3. **Enter Credentials**: Enter your [Anthropic](https://www.anthropic.com), [Google AI Studio](https://ai.google.dev) or [OpenAI](https://openai.com/) credentials based on the selected model.
19-
2016
## How to Use
2117

2218
There are many ways you could launch **Codeye** once installed.
2319

2420
### From Command Palette
2521

26-
Hit `CMD + SHIFT + P` and start a **Codeye** session from the **Command Palette**.
22+
1. **Install Codeye**: Search for **Codeye** in the [Visual Studio Code](https://code.visualstudio.com/) **Extensions** tab or visit the [Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=codeye.codeye) for quick installation.
23+
2. **Select AI Model**: Navigate to `Settings` > `Extensions` > `Codeye` and choose you desired AI model.
24+
3. **Enter Credentials**: Enter your [Anthropic](https://www.anthropic.com), [Google AI Studio](https://ai.google.dev) or [OpenAI](https://openai.com/) credentials based on the selected model.
25+
4. Hit `CMD + SHIFT + P` and start a **Codeye** session from the **Command Palette**.
2726

2827
![Command](https://raw.githubusercontent.com/codeye-ai/codeye-vscode/main/images/command-palette.png)
2928

3029
### From Terminal
3130

32-
Start a Codeye session from the provided terminal profile.
31+
Install and configure as global CLI command from [npm](https://www.npmjs.com/package/codeye):
3332

34-
![Terminal Profile](https://raw.githubusercontent.com/codeye-ai/codeye-vscode/main/images/terminal-profile.png)
33+
```shell
34+
# install package as global
35+
npm i -g codeye
36+
37+
# configure model and credentials (only once)
38+
codeye configure
39+
```
3540

36-
## Install
41+
Then in any folder, start a session using below command:
42+
43+
```shell
44+
codeye chat
45+
```
46+
47+
## Development
3748

3849
Clone the repository, navigate to project folder and run below commands:
3950

@@ -50,16 +61,16 @@ cp .env.dist .env
5061
# update values in .env
5162
```
5263

53-
Use below command to run working copy of the tool:
64+
To run as [Visual Studio Code](https://code.visualstudio.com) extension, open the project is [Visual Studio Code](https://code.visualstudio.com) and hit `F5` to start a new [Visual Studio Code](https://code.visualstudio.com) window with this extension preloaded.
65+
66+
![Terminal Profile](https://raw.githubusercontent.com/codeye-ai/codeye-vscode/main/images/terminal-profile.png)
67+
68+
Or use below command to run working copy of the tool:
5469

5570
```shell
5671
npm run debug
5772
```
5873

59-
## Usage
60-
61-
To run as [Visual Studio Code](https://code.visualstudio.com) extension, open the project is [Visual Studio Code](https://code.visualstudio.com) and hit `F5` to start a new [Visual Studio Code](https://code.visualstudio.com) window with this extension preloaded.
62-
6374
## Publishing
6475

6576
Before publishing, package your extension as `vsix` file.

cli.js

Lines changed: 116 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,121 @@ const path = require("path");
55
require("dotenv").config({ path: path.join(__dirname, ".env") });
66
const yargs = require("yargs/yargs");
77
const { hideBin } = require("yargs/helpers");
8-
const argv = yargs(hideBin(process.argv))
9-
.option("file", {
10-
alias: "f",
11-
type: "string",
12-
description: "Path to current/active file (e.g., in the editor).",
13-
})
14-
.option("reset", {
15-
alias: "r",
16-
type: "boolean",
17-
description: "Resets the conversation history.",
18-
})
19-
.option("verbose", {
20-
alias: "v",
21-
type: "boolean",
22-
description: "Enables verbose output.",
23-
})
24-
.parse();
8+
const prompts = require("prompts");
9+
const { main } = require("./src/codeye");
10+
const { load, save } = require("./src/utils/persistence");
2511

26-
const { run } = require("./src/codeye");
12+
const MODEL_IDS = [
13+
"claude-3-5-sonnet-20240620",
14+
"gemini-1.5-flash-001",
15+
"gemini-1.5-pro-001",
16+
"gpt-3.5-turbo",
17+
"gpt-4o",
18+
"gpt-4o-mini",
19+
"o1-preview",
20+
"o1-mini",
21+
];
2722

28-
(async function main(params) {
29-
await run(argv.file, !!argv.reset, !!argv.verbose);
30-
})();
23+
const MODEL_NAMES = [
24+
"Claude 3.5 Sonnet",
25+
"Gemini 1.5 Flash",
26+
"Gemini 1.5 Pro",
27+
"GPT-3.5 Turbo",
28+
"GPT-4o",
29+
"GPT-4o Mini",
30+
"O1 Preview",
31+
,
32+
"O1 Mini",
33+
];
34+
35+
yargs(hideBin(process.argv))
36+
.command("configure", "configure settings", async (argv) => {
37+
const settings = await load(null, "settings", "json");
38+
const response = await prompts([
39+
{
40+
type: "select",
41+
name: "model",
42+
message: "Pick an LLM",
43+
choices: MODEL_IDS.map((x, i) => ({
44+
title: MODEL_NAMES[i],
45+
value: x,
46+
})),
47+
initial: MODEL_IDS.indexOf(settings?.model || MODEL_IDS[0]),
48+
},
49+
{
50+
type: (prev, values) =>
51+
values.model.indexOf("claude") === 0 ? "text" : null,
52+
name: "apiKey",
53+
message: "Anthropic API key",
54+
initial: settings?.apiKey,
55+
validate: (value) =>
56+
value.indexOf("sk-ant-") === 0
57+
? true
58+
: "This must be a valid Anthropic API key.",
59+
},
60+
{
61+
type: (prev, values) =>
62+
values.model.indexOf("gemini") === 0 ? "text" : null,
63+
name: "apiKey",
64+
message: "Gemini API key",
65+
initial: settings?.apiKey,
66+
},
67+
{
68+
type: (prev, values) =>
69+
values.model.indexOf("gpt") === 0 || values.model.indexOf("o1") === 0
70+
? "text"
71+
: null,
72+
name: "apiKey",
73+
message: "OpenAI API key",
74+
initial: settings?.apiKey,
75+
validate: (value) =>
76+
value.indexOf("sk-") === 0
77+
? true
78+
: "This must be a valid OpenAI API key.",
79+
},
80+
{
81+
type: (prev, values) =>
82+
values.model.indexOf("gpt") === 0 ? "text" : null,
83+
name: "organization",
84+
message: "OpenAI organization",
85+
initial: settings?.organization,
86+
validate: (value) =>
87+
value.indexOf("org-") === 0
88+
? true
89+
: "This must be a valid OpenAI organization ID.",
90+
},
91+
]);
92+
93+
if (response.model && response.apiKey) {
94+
await save(null, response, "settings", "json");
95+
}
96+
})
97+
.command(
98+
"chat",
99+
"start a chat",
100+
(yargs) => {
101+
return yargs
102+
.option("file", {
103+
alias: "f",
104+
type: "string",
105+
description: "Path to current/active file (e.g., in the editor).",
106+
})
107+
.option("reset", {
108+
alias: "r",
109+
type: "boolean",
110+
description: "Resets the conversation history.",
111+
})
112+
.option("verbose", {
113+
alias: "v",
114+
type: "boolean",
115+
description: "Enables verbose output.",
116+
});
117+
},
118+
async (argv) => {
119+
await main(argv.file, !!argv.reset, !!argv.verbose);
120+
},
121+
)
122+
.scriptName("codeye")
123+
.strictCommands()
124+
.demandCommand(1)
125+
.parse();

extension.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function create(args = []) {
5050
},
5151
name: "Codeye",
5252
shellPath: "node",
53-
shellArgs: [script, ...args],
53+
shellArgs: [script, "chat", ...args],
5454
};
5555
}
5656

package.json

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,31 @@
2929
"claude-3-5-sonnet-20240620",
3030
"gemini-1.5-flash-001",
3131
"gemini-1.5-pro-001",
32+
"gpt-3.5-turbo",
3233
"gpt-4o",
33-
"gpt-3.5-turbo"
34+
"gpt-4o-mini",
35+
"o1-preview",
36+
"o1-mini"
3437
],
3538
"enumDescriptions": [
3639
"Claude 3.5 Sonnet (by Anthropic) is performant, accurate and works well for projects of all sizes.",
3740
"Gemini 1.5 Flash (by Google) is a faster model from the Gemini series.",
3841
"Gemini 1.5 Pro (by Google) is an updated and capable model for projects of all sizes.",
42+
"GPT-3.5 Turbo (by OpenAI) is cheaper but only suitable from small projects.",
3943
"GPT-4o (by OpenAI) is fast and works well with projects of all sizes.",
40-
"GPT-3.5 Turbo (by OpenAI) is cheaper but only suitable from small projects."
44+
"GPT-4o Mini (by OpenAI) is faster and cheaper sibling og GPT-4o.",
45+
"O1 Preview (by OpenAI) is better at mathematics and code generation.",
46+
"O1 Mini (by OpenAI) is faster and cheaper sibling og O1 Preview."
4147
],
4248
"enumItemLabels": [
4349
"Claude 3.5 Sonnet",
4450
"Gemini 1.5 Flash",
4551
"Gemini 1.5 Pro",
52+
"GPT-3.5 Turbo",
4653
"GPT-4o",
47-
"GPT-3.5 Turbo"
54+
"GPT-4o Mini",
55+
"O1 Preview",
56+
"O1 Mini"
4857
],
4958
"type": [
5059
"string"
@@ -116,6 +125,7 @@
116125
"mime-types": "^2.1.35",
117126
"openai": "^4.47.2",
118127
"ora": "^5.4",
128+
"prompts": "^2.4.2",
119129
"yargs": "^17.7.2"
120130
},
121131
"description": "AI-powered SWE agent to help you quickly ship quality software, built right into Visual Studio Code.",
@@ -146,7 +156,7 @@
146156
"build": "npm run build:cli && npm run build:extension",
147157
"build:cli": "esbuild ./cli.js --bundle --outfile=cli.build.js --format=cjs --platform=node --minify",
148158
"build:extension": "esbuild ./extension.js --bundle --outfile=extension.build.js --external:vscode --format=cjs --platform=node --minify",
149-
"debug": "node cli.js -rv",
159+
"debug": "node cli.js",
150160
"lint": "eslint .",
151161
"pretest": "yarn run lint",
152162
"test": "vscode-test"

src/codeye.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ const repl = require("repl");
66
const engines = require("./engines");
77
const { processes } = require("./functions/run-command");
88
const { check, initiate, verify } = require("./utils/auth");
9+
const { load } = require("./utils/persistence");
910
const { ask, loader } = require("./utils/cli");
1011

1112
const wd = process.cwd();
1213

13-
async function run(file = null, reset = false, verbose = false) {
14+
async function main(file = null, reset = false, verbose = false) {
1415
let auth;
1516
while (true) {
1617
auth = await loader(chalk.cyan("loading…"), () =>
@@ -59,7 +60,10 @@ async function run(file = null, reset = false, verbose = false) {
5960
};
6061
}
6162

62-
const { init, respond } = engines(process.env.CODEYE_AI_MODEL);
63+
const settings = await load(null, "settings", "json");
64+
const { init, respond } = engines(
65+
process.env.CODEYE_AI_MODEL || settings?.model,
66+
);
6367
const instructions = [
6468
"You are a code generation tool named Codeye, designed to write quality code/software.",
6569
"You can read and process any kind of text or image files for understanding the task.",
@@ -76,7 +80,7 @@ async function run(file = null, reset = false, verbose = false) {
7680
instructions.push(`Current file is: '${file}'.`);
7781
}
7882

79-
const state = await init(wd, reset, instructions.join(" "));
83+
const state = await init(wd, reset, instructions.join(" "), settings);
8084
const writer = verbose
8185
? (tool, args) => console.log(chalk.yellow(`tool → ${tool}`), args)
8286
: null;
@@ -95,4 +99,4 @@ async function run(file = null, reset = false, verbose = false) {
9599
});
96100
}
97101

98-
module.exports = { run };
102+
module.exports = { main };

src/engines/anthropic/claude.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,15 @@ const { Anthropic } = require("@anthropic-ai/sdk");
33
const functions = require("../../functions");
44
const { load, save } = require("../../utils/persistence");
55

6-
const ANTHROPIC_MODEL =
7-
process.env.CODEYE_AI_MODEL || "claude-3-5-sonnet-20240620";
86
const ANTHROPIC_TOKEN_LIMIT = 200 * 1000; // 200K is max on claude-*
97

10-
const anthropic = new Anthropic({
11-
apiKey: process.env.CODEYE_ANTHROPIC_API_KEY,
12-
});
13-
148
const tools = Object.values(functions).map((x) => ({
159
name: x.spec.name,
1610
description: x.spec.description,
1711
input_schema: x.spec.parameters,
1812
}));
1913

20-
async function init(wd, reset, instructions) {
14+
async function init(wd, reset, instructions, settings) {
2115
const messages = [];
2216
if (!reset) {
2317
const history = await load(wd, "claude", "history");
@@ -26,12 +20,21 @@ async function init(wd, reset, instructions) {
2620
}
2721
}
2822

29-
return { messages, instructions };
23+
const anthropic = new Anthropic({
24+
apiKey: process.env.CODEYE_ANTHROPIC_API_KEY || settings?.apiKey,
25+
});
26+
27+
return {
28+
anthropic,
29+
messages,
30+
model: process.env.CODEYE_AI_MODEL || settings?.model,
31+
instructions,
32+
};
3033
}
3134

3235
async function respond(
3336
wd,
34-
{ messages, instructions },
37+
{ anthropic, messages, model, instructions },
3538
text,
3639
a,
3740
b,
@@ -49,7 +52,7 @@ async function respond(
4952
}
5053

5154
const message = await anthropic.messages.create({
52-
model: ANTHROPIC_MODEL,
55+
model,
5356
max_tokens: 4096,
5457
messages,
5558
system: instructions,

0 commit comments

Comments
 (0)