Skip to content

Commit

Permalink
fix: add model name check to config command
Browse files Browse the repository at this point in the history
- Added model name checking to avoid printing internal config values
- Improved logging for better user experience
- Removed unnecessary types casting for model names
  • Loading branch information
tak-bro committed Aug 13, 2024
1 parent 1faf9bd commit 23a11df
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
3 changes: 0 additions & 3 deletions src/commands/aicommit2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ export default async (
rawArgv
);

console.log(config);
// throw new KnownError('Please set at least one API key via the `aicommit2 config set` command');

if (config.systemPromptPath) {
try {
fs.readFileSync(path.resolve(config.systemPromptPath), 'utf-8');
Expand Down
8 changes: 7 additions & 1 deletion src/commands/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { command } from 'cleye';

import { ConsoleManager } from '../managers/console.manager.js';
import { getConfig, hasOwn, setConfigs } from '../utils/config.js';
import { ModelName, getConfig, hasOwn, modelNames, setConfigs } from '../utils/config.js';
import { KnownError, handleCliError } from '../utils/error.js';

export default command(
Expand All @@ -17,6 +17,12 @@ export default command(
const config = await getConfig({}, []);
for (const key of keyValues) {
if (hasOwn(config, key)) {
const isModel = modelNames.includes(key as ModelName);
if (isModel) {
// @ts-ignore ignore
console.log(key, config[key]);
return;
}
console.log(`${key}=${config[key as keyof typeof config]}`);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/services/ai/codestral.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class CodestralService extends AIService {
return fromPromise(this.generateMessage()).pipe(
concatMap(messages => from(messages)),
map(data => ({
name: `${this.serviceName} ${this.params.config.ignoreBody} ${data.title}`,
name: `${this.serviceName} ${data.title}`,
short: data.title,
value: this.params.config.ignoreBody ? data.title : data.value,
description: this.params.config.ignoreBody ? '' : data.value,
Expand Down
2 changes: 1 addition & 1 deletion src/services/ai/hugging-face.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class HuggingFaceService extends AIService {
return fromPromise(this.generateMessage()).pipe(
concatMap(messages => from(messages)),
map(data => ({
name: `${this.serviceName} ${this.params.config.ignoreBody} ${data.title}`,
name: `${this.serviceName} ${data.title}`,
short: data.title,
value: this.params.config.ignoreBody ? data.title : data.value,
description: this.params.config.ignoreBody ? '' : data.value,
Expand Down
2 changes: 1 addition & 1 deletion src/services/ai/ollama.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class OllamaService extends AIService {
return fromPromise(this.generateMessage()).pipe(
concatMap(messages => from(messages)),
map(data => ({
name: `${this.serviceName} ${this.params.config.ignoreBody} ${data.title}`,
name: `${this.serviceName} ${data.title}`,
short: data.title,
value: this.params.config.ignoreBody ? data.title : data.value,
description: this.params.config.ignoreBody ? '' : data.value,
Expand Down

0 comments on commit 23a11df

Please sign in to comment.