Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/trypear/pearai-submodule in…
Browse files Browse the repository at this point in the history
…to him/fixessss
  • Loading branch information
Himanshu-Singh-Chauhan committed Jan 28, 2025
2 parents ad27a69 + 7d28a0e commit f3d102f
Show file tree
Hide file tree
Showing 156 changed files with 15,485 additions and 5,136 deletions.
3 changes: 1 addition & 2 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"label": "vscode-extension:continue-ui:build",
"type": "shell",
"command": "node",
"args": ["${workspaceFolder}/extensions/vscode/scripts/prepackage.js"],
"args": ["scripts/prepackage.js"],
"problemMatcher": ["$tsc"],
"presentation": {
"revealProblems": "onProblem",
Expand All @@ -73,7 +73,6 @@
"cwd": "${workspaceFolder}/extensions/vscode"
}
},
//
// Compile and bundle tests
{
"label": "vscode-extension:tests:build",
Expand Down
89 changes: 11 additions & 78 deletions core/config/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
SlashCommandDescription,
CustomCommand,
} from "../index.js";
import { SERVER_URL } from "../util/parameters";


export const FREE_TRIAL_MODELS: ModelDescription[] = [
{
Expand Down Expand Up @@ -97,77 +99,7 @@ export const defaultSlashCommandsJetBrains = [
];

export const defaultConfig: SerializedContinueConfig = {
models: [
{
model: "pearai_model",
contextLength: 300000,
title: "PearAI Model",
systemMessage:
"You are an expert software developer. You give helpful and concise responses.",
provider: "pearai_server",
isDefault: true,
},
{
model: "gpt-4o",
contextLength: 300000,
title: "GPT-4o (PearAI)",
systemMessage:
"You are an expert software developer. You give helpful and concise responses.",
provider: "pearai_server",
isDefault: true,
},
{
model: "claude-3-5-sonnet",
contextLength: 3000000,
title: "Claude 3.5 Sonnet - New (PearAI)",
systemMessage:
"You are an expert software developer. You give helpful and concise responses.",
provider: "pearai_server",
isDefault: true,
},
{
model: "perplexity",
title: "PearAI Search (Powered by Perplexity)",
systemMessage:
"You are an expert documentation and information gatherer. You give succinct responses based on the latest software engineering practices and documentation. Always go to the web to get the latest information and data.",
provider: "pearai_server",
isDefault: true,
},
{
model: "claude-3-5-haiku",
title: "Claude 3.5 Haiku (PearAI)",
provider: "pearai_server",
isDefault: true,
},
{
model: "gemini-1.5-pro",
contextLength: 3000000,
title: "Gemini 1.5 Pro (PearAI)",
systemMessage:
"You are an expert software developer. You give helpful and concise responses.",
provider: "pearai_server",
isDefault: true,
},
{
model: "pearai_model",
contextLength: 300000,
title: "pearai_model (PearAI Creator)",
provider: "aider",
isDefault: true,
},
{
model: "o1-mini",
title: "GPTo1 Mini (PearAI annual only)",
provider: "pearai_server",
isDefault: true,
},
{
model: "o1-preview",
title: "GPTo1 Preview (PearAI annual only)",
provider: "pearai_server",
isDefault: true,
},
],
models: [],
customCommands: [
{
name: "test",
Expand All @@ -176,14 +108,15 @@ export const defaultConfig: SerializedContinueConfig = {
description: "Write unit tests for highlighted code",
},
],
// WIP: Add autocomplete by default
// tabAutocompleteModel: {
// title: "PearAI Autocomplete",
// provider: "pearai_server",
// model: "pearai_autocomplete",
// },
contextProviders: defaultContextProvidersVsCode,
slashCommands: defaultSlashCommandsVscode,
integrations: [
{
name: "mem0",
description: "PearAI Personalized Chat powered by Mem0",
enabled: false,
}
],
};

export const defaultCustomCommands: CustomCommand[] = [
Expand Down Expand Up @@ -233,4 +166,4 @@ export const defaultConfigJetBrains: SerializedContinueConfig = {
},
contextProviders: defaultContextProvidersJetBrains,
slashCommands: defaultSlashCommandsJetBrains,
};
};
91 changes: 80 additions & 11 deletions core/config/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import {
getConfigTsPath,
getContinueDotEnv,
readAllGlobalPromptFiles,
editConfigJson
} from "../util/paths.js";
import {
defaultConfig,
Expand All @@ -65,6 +66,7 @@ import {
getPromptFiles,
slashCommandFromPromptFile,
} from "./promptFile.js";
import { SERVER_URL } from "../util/parameters";

function resolveSerializedConfig(filepath: string): SerializedContinueConfig {
let content = fs.readFileSync(filepath, "utf8");
Expand Down Expand Up @@ -120,6 +122,11 @@ function loadSerializedConfig(
config.allowAnonymousTelemetry = true;
}

// If integrations doesn't exist in config, write it to config.json
if (!config.integrations) {
config.integrations = [];
}

if (ideSettings.remoteConfigServerUrl) {
try {
const remoteConfigJson = resolveSerializedConfig(
Expand Down Expand Up @@ -175,7 +182,7 @@ async function serializedToIntermediateConfig(
const promptFolder = initial.experimental?.promptPath;

if (loadPromptFiles) {
let promptFiles: { path: string; content: string }[] = [];
let promptFiles: { path: string; content: string } [] = [];
promptFiles = (
await Promise.all(
workspaceDirs.map((dir) =>
Expand Down Expand Up @@ -498,6 +505,7 @@ function finalToBrowserConfig(
ui: final.ui,
experimental: final.experimental,
isBetaAccess: final?.isBetaAccess,
integrations: final.integrations || []
};
}

Expand Down Expand Up @@ -587,22 +595,83 @@ async function buildConfigTs() {
}
return fs.readFileSync(getConfigJsPath(), "utf8");
}
function addDefaults(config: SerializedContinueConfig): void {
addDefaultModels(config);

async function addDefaults(config: SerializedContinueConfig) {
await addDefaultModels(config);
addDefaultCustomCommands(config);
addDefaultContextProviders(config);
addDefaultSlashCommands(config);
addDefaultIntegrations(config);
}

function addDefaultModels(config: SerializedContinueConfig): void {
const defaultModels = defaultConfig.models.filter(
(model) => model.isDefault === true,
);
defaultModels.forEach((defaultModel) => {
function addDefaultIntegrations(config: SerializedContinueConfig): void {
defaultConfig!.integrations!.forEach((defaultIntegration) => {
const integrationExists = config?.integrations?.some(
(configIntegration) =>
configIntegration.name === defaultIntegration.name
);
if (!integrationExists) {
config!.integrations!.push(defaultIntegration);
editConfigJson((configJson) => {
if (!configJson.integrations) {
configJson.integrations = [];
}
configJson.integrations.push(defaultIntegration);
return configJson;
});
}
});
}

const STATIC_MODELS: ModelDescription[] = [
{
model: "pearai_model",
contextLength: 300000,
title: "PearAI Model",
systemMessage: "You are an expert software developer. You give helpful and concise responses.",
provider: "pearai_server",
isDefault: true,
},
{
model: "perplexity",
title: "PearAI Search (Powered by Perplexity)",
systemMessage: "You are an expert documentation and information gatherer. You give succinct responses based on the latest software engineering practices and documentation. Always go to the web to get the latest information and data.",
provider: "pearai_server",
isDefault: true,
}
];

const getDefaultModels = async () => {
try {
const res = await fetch(`${SERVER_URL}/getDefaultConfig`);
const config = await res.json();
return config.models;
} catch {
return [];
}
};

async function addDefaultModels(config: SerializedContinueConfig): Promise<void> {
// First, add static models
STATIC_MODELS.forEach((staticModel) => {
const modelExists = config.models.some(
(configModel) =>
configModel.title === staticModel.title &&
configModel.provider === staticModel.provider
);

if (!modelExists) {
config.models.push({ ...staticModel });
}
});

// Then, add dynamic models from server
const dynamicModels = await getDefaultModels();
dynamicModels.forEach((defaultModel: ModelDescription) => {
const modelExists = config.models.some(
(configModel) =>
configModel.title === defaultModel.title &&
configModel.provider === defaultModel.provider,
configModel.provider === defaultModel.provider
);

if (!modelExists) {
Expand Down Expand Up @@ -669,7 +738,7 @@ async function loadFullConfigNode(
);

// check and enforce default models
addDefaults(serialized);
await addDefaults(serialized);

// Convert serialized to intermediate config
let intermediate = await serializedToIntermediateConfig(serialized, ide);
Expand Down Expand Up @@ -726,4 +795,4 @@ export {
loadFullConfigNode,
serializedToIntermediateConfig,
type BrowserSerializedContinueConfig,
};
};
10 changes: 10 additions & 0 deletions core/config/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,13 @@ export function deleteModel(title: string) {
return config;
});
}

export function toggleIntegration(name: string) {
editConfigJson((config) => {
const integration = config!.integrations!.find((i: any) => i.name === name);
if (integration) {
integration.enabled = !integration.enabled;
}
return config;
});
}
28 changes: 18 additions & 10 deletions core/core.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as fs from "node:fs";
import { v4 as uuidv4 } from "uuid";
import type { ContextItemId, IDE, IndexingProgressUpdate } from ".";
import type { ChatMessage, ContextItemId, IDE, IndexingProgressUpdate } from ".";
import { CompletionProvider } from "./autocomplete/completionProvider";
import { ConfigHandler } from "./config/ConfigHandler";
import {
Expand All @@ -10,7 +10,7 @@ import {
setupLocalMode,
} from "./config/onboarding";
import { createNewPromptFile } from "./config/promptFile";
import { addModel, addOpenAIKey, deleteModel } from "./config/util";
import { addModel, addOpenAIKey, deleteModel, toggleIntegration } from "./config/util";
import { recentlyEditedFilesCache } from "./context/retrieval/recentlyEditedFilesCache";
import { ContinueServerClient } from "./continueServer/stubs/client";
import { getAuthUrlForTokenPage } from "./control-plane/auth/index";
Expand Down Expand Up @@ -242,6 +242,10 @@ export class Core {
deleteModel(msg.data.title);
this.configHandler.reloadConfig();
});
on("config/toggleIntegration", (msg) => {
toggleIntegration(msg.data.name);
this.configHandler.reloadConfig();
});

on("config/newPromptFile", async (msg) => {
createNewPromptFile(
Expand Down Expand Up @@ -383,7 +387,14 @@ export class Core {
});
break;
}
yield { content: next.value.content, citations: next.value?.citations };
// Assert that next.value is a ChatMessage
const chatMessage = next.value as ChatMessage;

yield {
content: chatMessage.content,
citations: chatMessage.citations
};

next = await gen.next();
}

Expand Down Expand Up @@ -444,7 +455,7 @@ export class Core {
const { accessToken, refreshToken } = msg.data || {};
const config = await this.configHandler.loadConfig();
const pearAIModels = config.models.filter(model => model instanceof PearAIServer) as PearAIServer[];
const aiderModels = config.models.filter(model => model instanceof Aider) as Aider[];
const aiderModel = config.models.find(model => model instanceof Aider) as Aider;

try {
if (pearAIModels.length > 0) {
Expand All @@ -457,13 +468,10 @@ export class Core {
console.warn(`Error resetting PearAI credentials: ${e}`);
return undefined;
}
// TODO @nang - handle this better
try {
if (aiderModels.length > 0) {
aiderModels.forEach(model => {
model.setPearAIAccessToken(accessToken);
model.setPearAIRefreshToken(refreshToken);
});
if (aiderModel) {
aiderModel.setPearAIAccessToken(accessToken);
aiderModel.setPearAIRefreshToken(refreshToken);
}
} catch (e) {
console.warn(`Error resetting PearAI credentials for aider: ${e}`);
Expand Down
Loading

0 comments on commit f3d102f

Please sign in to comment.