Skip to content

Commit

Permalink
Add config metadata for server (#182)
Browse files Browse the repository at this point in the history
* Add config metadata for server

* wip, add interfaces, read/write config

* toggle configuration support

* remove project id set in activation

* remove unnecessary imports

* add toggle back

* inventory toggle

* add read config json
  • Loading branch information
jpan8866 authored Dec 3, 2024
1 parent 2e7b3b0 commit 8033264
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
17 changes: 4 additions & 13 deletions core/llm/llms/PearAIServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
pruneRawPromptFromTop,
} from "./../countTokens.js";
import { PearAICredentials } from "../../pearaiServer/PearAICredentials.js";
import { editConfigJson } from "../../util/paths.js";
import { readConfigJson } from "../../util/paths.js";
import { execSync } from "child_process";
import * as vscode from "vscode";

Expand Down Expand Up @@ -58,16 +58,7 @@ class PearAIServer extends BaseLLM {
// no-op
}

private _getIntegrations(): any {
let integrations = {};
editConfigJson((config) => {
integrations = config.integrations || {};
return config;
});
return integrations;
}

public static _getRepoId(): string {
private _getRepoId(): string {
try {
const gitRepo = vscode.workspace.workspaceFolders?.[0];
if (gitRepo) {
Expand All @@ -89,8 +80,8 @@ class PearAIServer extends BaseLLM {
private _convertArgs(options: CompletionOptions): any {
return {
model: options.model,
integrations: this._getIntegrations(),
repoId: PearAIServer._getRepoId(),
integrations: readConfigJson().integrations || {},
repoId: this._getRepoId(),
frequency_penalty: options.frequencyPenalty,
presence_penalty: options.presencePenalty,
max_tokens: options.maxTokens,
Expand Down
9 changes: 9 additions & 0 deletions core/util/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,15 @@ export function editConfigJson(
}
}

export function readConfigJson(): any {
const config = fs.readFileSync(getConfigJsonPath(), "utf8");
const configJson = JSONC.parse(config);
if (typeof configJson === "object" && configJson !== null) {
return configJson;
}
throw new Error("config.json is not a valid object");
}

function getMigrationsFolderPath(): string {
const migrationsPath = path.join(getContinueGlobalPath(), ".migrations");
if (!fs.existsSync(migrationsPath)) {
Expand Down

0 comments on commit 8033264

Please sign in to comment.