Skip to content
Closed
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
5 changes: 5 additions & 0 deletions .changeset/curly-owls-visit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"overide": minor
---

Now we are able to use response_format in case of OpenAi api
5 changes: 5 additions & 0 deletions .changeset/dry-peaches-bow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"overide": patch
---

Added support for `--path` option in `init` and `start` commands. This allows user to initialise and start overide in any target path on a system.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"groq-sdk": "^0.7.0",
"inquirer": "^11.1.0",
"open": "^10.1.0",
"openai": "^4.67.2",
"openai": "^4.77.0",
"three": "^0.170.0",
"tree-sitter": "^0.22.0",
"tree-sitter-c": "^0.23.1",
Expand Down
13 changes: 8 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 10 additions & 52 deletions src/commands/command.init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Initialize extends OiCommand {

initCommand
.option('-i, --ignore <files...>', 'Specify files or directories to ignore')
.option('-p, --path <path>', 'Specify the path to the project directory')
.option('-n, --project-name <name>', 'Specify a project name')
.action((options: InitOption) => {
this.initializeProject(options);
Expand Down Expand Up @@ -53,54 +54,6 @@ class Initialize extends OiCommand {
console.log("3. Run 'overide config -e' to enable embeddings based context.");
}

/**
* Adds specified files to the ignore list in the configuration file (`oi-config.json`).
*
* @param {string|string[]} files - A file or an array of files to add to the ignore list.
*/
addIgnoreFiles(files: string[]): void {
const configPath = CommandHelper.getConfigFilePath(false);

// Check if oi-config.json exists
if (!CommandHelper.configExists(false)) {
console.error(`Error: oi-config.json not found at ${configPath}`);
process.exit(1);
}

try {
// Read the current configuration file
const config: LocalConfig = JSON.parse(fs.readFileSync(configPath, 'utf-8'));

// Ensure 'ignore' field exists in the configuration
if (!Array.isArray(config.ignore)) {
config.ignore = [];
}

// Convert a single file string into an array
if (typeof files === 'string') {
files = [files];
}

// Add each file to the ignore list if it is not already present
files.forEach(file => {
if (!config.ignore.includes(file)) {
config.ignore.push(file);
console.log(`Added ${file} to ignore list.`);
} else {
console.log(`${file} is already in the ignore list.`);
}
});

// Write the updated configuration back to oi-config.json
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
console.log('Updated oi-config.json with new ignore files.');
} catch (error) {
if (error instanceof Error) {
console.error(`Error updating oi-config.json: ${error.message}`);
}
}
}

/**
* Initializes the project by creating the configuration file (`oi-config.json`)
* and setting up ignore files, project name, and other options. If the project
Expand All @@ -111,14 +64,19 @@ class Initialize extends OiCommand {
async initializeProject(options: InitOption): Promise<void> {
try {
// Determine the output path for the configuration file
const outputPath = path.join(process.cwd(), 'oi-config.json');
const dependencyFilePath = path.join(process.cwd(), 'oi-dependency.json');
// Check if the path is passed in the options.
let outputPath = '';
if (options.path) {
outputPath = path.join(options.path, 'oi-config.json');
} else {
outputPath = path.join(process.cwd(), 'oi-config.json');
}

const dependencyFilePath = path.join(options.path ?? process.cwd(), 'oi-dependency.json');
const ignoreFiles = options.ignore || [];
const verbose = options.verbose || false;
const projectName = options.projectName || 'default-project';

console.log(options);

// Verbose mode: Display the initialization options
if (verbose) {
console.log(`Initializing project with the following options:`);
Expand Down
22 changes: 15 additions & 7 deletions src/commands/command.start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,17 @@ class Start extends OiCommand {
configureCommand(): void {
const startCommand = this.program
.command('start')
.option('-p, --path <path>', 'Specify the path to the project directory')
.description('Start watching files for prompt changes');
this.addCommonOptions(startCommand); // Add common options such as --verbose

// Load the dependency graph from the oi-dependency.json file
this.dependencyGraph = configCommandUtil.loadDependencyGraph() as DependencyGraph[] | null;

startCommand.action((options: StartOption) => this.startWatch(options));
startCommand.action((options: StartOption) => {
// Load the dependency graph from the oi-dependency.json file
this.dependencyGraph = configCommandUtil.loadDependencyGraph(options.path) as
| DependencyGraph[]
| null;
this.startWatch(options);
});
}

/**
Expand All @@ -51,17 +55,21 @@ class Start extends OiCommand {
console.log('Watching files for prompts...');

try {
const { verbose } = options;
const { verbose, path } = options;

if (!configCommandUtil.configExists()) {
console.error('Error: oi-config.json file not found in the current directory.');
process.exit(1);
}

// get current config.
const config = (await configCommandUtil.readConfigFileData()) as LocalConfig;
const config = (await configCommandUtil.readConfigFileData(false, path)) as LocalConfig;
const ignoredFiles = config.ignore || [];
const currentDir = process.cwd();
const currentDir = options.path ?? process.cwd();

if (verbose) {
console.log(`Watching files in directory: ${currentDir}`);
}

this.watcher = chokidar.watch(currentDir, {
persistent: true,
Expand Down
2 changes: 2 additions & 0 deletions src/models/model.options.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
export interface InitOption {
path?: string;
ignore?: string[];
verbose?: boolean;
projectName?: string;
}

export interface StartOption {
verbose?: boolean;
path?: string;
}

export interface ConfigOption {
Expand Down
2 changes: 2 additions & 0 deletions src/models/model.request.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ResponseFormatJSONSchema } from 'openai/resources';
import { ChatCompletionMessageParam as OpenAIChatCompletionMessageParam } from 'openai/resources/chat/completions';
import { ChatCompletionMessageParam as GroqChatCompletionMessageParam } from 'groq-sdk/resources/chat/completions';
import { ActivePlatformDetails } from './model.config';
Expand All @@ -16,6 +17,7 @@ export interface OpenAiRequestObject {
stream?: boolean;
presence_penalty?: number;
frequency_penalty?: number;
response_format: ResponseFormatJSONSchema;
}

export interface DeepSeekRequestObject {
Expand Down
6 changes: 2 additions & 4 deletions src/services/service.network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,7 @@ class NetworkServiceImpl extends NetworkService {
// Handle requests based on the selected platform
switch (platform) {
case 'openai':
return this.handleOpenAIRequest(activeServiceDetails, {
...metadata,
messages: metadata.messages as OpenAIChatCompletionMessageParam[]
});
return this.handleOpenAIRequest(activeServiceDetails, metadata as OpenAiRequestObject);
case 'deepseek':
return this.handleDeepSeekRequest(activeServiceDetails, {
...metadata,
Expand Down Expand Up @@ -141,6 +138,7 @@ class NetworkServiceImpl extends NetworkService {
...metadata,
stream: false
});
console.log(completions.choices[0]);
return (completions.choices[0] as ChatCompletion.Choice).message.content || ''; // Return the content string from OpenAI completion
} catch (error) {
if (error instanceof Error) {
Expand Down
45 changes: 38 additions & 7 deletions src/services/service.process/process.request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,45 @@ class ProcessRequest {
}

const metadata: OpenAiRequestObject = {
model: 'gpt-4o', // Specify the model to use
model: 'gpt-4o',
messages: messages,
temperature: 0.5, // Adjust temperature for creativity (lower = more deterministic)
max_tokens: 2500, // Max tokens for the response
n: 1, // Number of completions to generate
stream: false, // Whether to stream results
presence_penalty: 0, // Adjusts frequency of introducing new ideas
frequency_penalty: 0 // Adjusts repetition
temperature: 0.5,
max_tokens: 2500,
n: 1,
stream: false,
presence_penalty: 0,
frequency_penalty: 0,
response_format: {
type: 'json_schema',
json_schema: {
name: 'changes',
schema: {
type: 'object',
properties: {
changes: {
type: 'array',
items: {
type: 'object',
properties: {
find: {
type: 'array',
items: { type: 'string' }
},
replace: {
type: 'array',
items: { type: 'string' }
}
},
required: ['find', 'replace'],
additionalProperties: false
}
}
},
required: ['changes'],
additionalProperties: false
}
}
}
};

// Construct the request body for OpenAI API
Expand Down
7 changes: 7 additions & 0 deletions src/services/service.process/process.response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ class ProcessResponse {
response: string,
verbose: boolean = false
): Promise<ReplacementBlock[] | null> {
// IN case of OpenAi we receive a proper json format.
try {
return JSON.parse(response)['changes'] as ReplacementBlock[];
} catch (error) {
console.error(`Error in formatting response: ${(error as Error).message}`);
}

try {
const replacementObject: ReplacementBlock[] = serviceDev.extractCodeBlock(response, verbose);
for (const bloc of replacementObject) {
Expand Down
35 changes: 24 additions & 11 deletions src/utilis/util.command.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class ConfigCommandUtil {
private static globalConfigFileName = 'oi-global-config.json';
private static dependencyFileName = 'oi-dependency.json';

loadDependencyGraph(): DependencyGraph[] | null {
const dependencyFilePath = this.getDependencyFilePath();
loadDependencyGraph(localPath?: string): DependencyGraph[] | null {
const dependencyFilePath = this.getDependencyFilePath(localPath);
if (fs.existsSync(dependencyFilePath)) {
const dependencyData = fs.readFileSync(dependencyFilePath, 'utf-8');
const dependencyGraph = JSON.parse(dependencyData);
Expand All @@ -33,8 +33,8 @@ class ConfigCommandUtil {
/**
* Get the file path for the dependency file.
*/
public getDependencyFilePath(): string {
return path.join(process.cwd(), ConfigCommandUtil.dependencyFileName);
public getDependencyFilePath(localPath?: string): string {
return path.join(localPath ?? process.cwd(), ConfigCommandUtil.dependencyFileName);
}

/**
Expand All @@ -52,8 +52,8 @@ class ConfigCommandUtil {
* @param {boolean} global - True if checking the global config, false for local.
* @returns {boolean} - True if the configuration file exists, false otherwise.
*/
public configExists(global: boolean = false): boolean {
const configPath = this.getConfigFilePath(global);
public configExists(global: boolean = false, localPath?: string): boolean {
const configPath = this.getConfigFilePath(global, localPath);
return fs.existsSync(configPath);
}

Expand All @@ -63,10 +63,16 @@ class ConfigCommandUtil {
* @param {boolean} global - True if retrieving the global config file path.
* @returns {string} - The full path to the configuration file.
*/
public getConfigFilePath(global: boolean = false): string {
public getConfigFilePath(global: boolean = false, localPath?: string): string {
if (global) {
return path.join(this.getGlobalConfigDirectory(), ConfigCommandUtil.globalConfigFileName);
}

if (localPath) {
// Return the local config file path from the specified directory
return path.join(localPath, ConfigCommandUtil.configFileName);
}
// Return the local config file path
return path.join(process.cwd(), ConfigCommandUtil.configFileName);
}

Expand Down Expand Up @@ -110,8 +116,11 @@ class ConfigCommandUtil {
* @param {boolean} global - True if reading global config, false for local.
* @returns {LocalConfig | GlobalConfig | null} - The configuration object or null if not found.
*/
public readConfigFileData(global: boolean = false): LocalConfig | GlobalConfig | null {
const configPath = this.getConfigFilePath(global);
public readConfigFileData(
global: boolean = false,
localPath?: string
): LocalConfig | GlobalConfig | null {
const configPath = this.getConfigFilePath(global, localPath);

if (!this.configExists(global)) {
console.error(`Configuration file not found at ${configPath}`);
Expand All @@ -136,8 +145,12 @@ class ConfigCommandUtil {
* @param {boolean} global - True if writing to global config, false for local.
* @param {LocalConfig | GlobalConfig} data - The configuration data to write.
*/
public writeConfigFileData(global: boolean = false, data: LocalConfig | GlobalConfig): void {
const configPath = this.getConfigFilePath(global);
public writeConfigFileData(
global: boolean = false,
data: LocalConfig | GlobalConfig,
localPath?: string
): void {
const configPath = this.getConfigFilePath(global, localPath);

// Ensure the directory exists
this.makeRequiredDirectories();
Expand Down