Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ jobs:

remix-ide-browser:
docker:
- image: cimg/node:20.18.3-browsers
- image: cimg/node:20.19.0-browsers
resource_class:
xlarge
working_directory: ~/remix-project
Expand Down
6 changes: 3 additions & 3 deletions apps/remix-ide-e2e/src/tests/ai_panel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ module.exports = {
.assistantWorkspace('comment all function', 'mistralai')
.waitForElementVisible({
locateStrategy: 'xpath',
selector: '//div[contains(@class,"chat-bubble") and (contains(.,"Modified Files") or contains(.,"No Changes applied"))]',
selector: '//div[contains(@class,"chat-bubble") and (contains(.,"Modified Files") or contains(.,"No Changes applied") or contains(.,"No files modified"))]',
timeout: 60000
})
.waitForElementPresent({
Expand Down Expand Up @@ -203,7 +203,7 @@ module.exports = {
.assistantWorkspace('remove all comments', 'openai')
.waitForElementVisible({
locateStrategy: 'xpath',
selector: '//div[contains(@class,"chat-bubble") and (contains(.,"Modified Files") or contains(.,"No Changes applied"))]',
selector: '//div[contains(@class,"chat-bubble") and (contains(.,"Modified Files") or contains(.,"No Changes applied") or contains(.,"No files modified"))]',
timeout: 60000
})
.waitForElementPresent({
Expand All @@ -223,7 +223,7 @@ module.exports = {
.assistantWorkspace('remove all comments', 'anthropic')
.waitForElementVisible({
locateStrategy: 'xpath',
selector: '//div[contains(@class,"chat-bubble") and (contains(.,"Modified Files") or contains(.,"No Changes applied"))]',
selector: '//div[contains(@class,"chat-bubble") and (contains(.,"Modified Files") or contains(.,"No Changes applied") or contains(.,"No files modified"))]',
timeout: 60000
})
.waitForElementPresent({
Expand Down
1 change: 0 additions & 1 deletion apps/remix-ide-e2e/src/tests/generalSettings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ module.exports = {

'Should display settings menu ': function (browser: NightwatchBrowser) {
browser.waitForElementVisible('*[data-id="remixIdeIconPanel"]', 10000)
.click('*[data-id="landingPageStartSolidity"]')
.waitForElementVisible('*[data-id="verticalIconsKindsettings"]', 5000)
.click('*[data-id="verticalIconsKindsettings"]')
.waitForElementContainsText('h6[data-id="sidePanelSwapitTitle"]', 'SETTINGS')
Expand Down
2 changes: 0 additions & 2 deletions apps/remix-ide-e2e/src/tests/metamask.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ const tests = {
.switchBrowserTab(0)
.refreshPage()
.waitForElementVisible('*[data-id="remixIdeIconPanel"]', 10000)
.click('*[data-id="landingPageStartSolidity"]')
.clickLaunchIcon('udapp')
.waitForElementPresent('*[data-id="settingsNetworkEnv"]')
.switchEnvironment('injected-MetaMask')
Expand Down Expand Up @@ -282,7 +281,6 @@ const tests = {
})
.refreshPage()
.waitForElementVisible('*[data-id="remixIdeIconPanel"]', 10000)
.click('*[data-id="landingPageStartSolidity"]')
.clickLaunchIcon('udapp')
.switchEnvironment('injected-MetaMask')
.waitForElementPresent('*[data-id="settingsNetworkEnv"]')
Expand Down
1 change: 0 additions & 1 deletion apps/remix-ide-e2e/src/tests/quickDapp_metamask.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ const tests = {
.useCss().switchBrowserTab(0)
.refreshPage()
.waitForElementVisible('*[data-id="remixIdeIconPanel"]', 10000)
.click('*[data-id="landingPageStartSolidity"]')
.clickLaunchIcon('udapp')
.switchEnvironment('injected-MetaMask')

Expand Down
5 changes: 3 additions & 2 deletions libs/remix-ai-core/src/inferencers/remote/remoteInference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class RemoteInferencer implements ICompletions, IGeneration {
const requestURL = rType === AIRequestType.COMPLETION ? this.completion_url : this.api_url

try {
const options = { headers: { 'Content-Type': 'application/json', } }
const options = AIRequestType.COMPLETION ? { headers: { 'Content-Type': 'application/json', }, timeout: 3000 } : { headers: { 'Content-Type': 'application/json', } }
const result = await axios.post(requestURL, payload, options)

switch (rType) {
Expand All @@ -49,6 +49,7 @@ export class RemoteInferencer implements ICompletions, IGeneration {
} catch (e) {
ChatHistory.clearHistory()
console.error('Error making request to Inference server:', e.message)
return ""
}
finally {
this.event.emit("onInferenceDone")
Expand Down Expand Up @@ -110,7 +111,7 @@ export class RemoteInferencer implements ICompletions, IGeneration {
}

async code_completion(prompt, promptAfter, ctxFiles, fileName, options:IParams=CompletionParams): Promise<any> {
options.max_tokens = 10
options.max_tokens = 30
const payload = { prompt, 'context':promptAfter, "endpoint":"code_completion",
'ctxFiles':ctxFiles, 'currentFileName':fileName, ...options }
return this._makeRequest(payload, AIRequestType.COMPLETION)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
/**
* Adaptive Rate Limiter for Inline Completions
*
*/

interface CompletionHistoryEntry {
timestamp: number;
accepted: boolean;
}

interface AdaptiveRateLimiterOptions {
minRequestInterval?: number;
completionCooldown?: number;
historyWindow?: number;
baseAdaptiveCooldown?: number;
maxAdaptiveCooldown?: number;
}

interface AdaptiveRateLimiterStats {
acceptanceRate: number;
totalCompletions: number;
acceptedCompletions: number;
rejectedCompletions: number;
currentCooldown: number;
}

export class AdaptiveRateLimiter {
private lastRequestTime: number = 0;
private lastCompletionTime: number = 0;
private acceptanceRate: number = 0.5;
private totalCompletions: number = 0;
private acceptedCompletions: number = 0;
private rejectedCompletions: number = 0;
private recentCompletionHistory: CompletionHistoryEntry[] = [];

private readonly minRequestInterval: number = 500;
private readonly completionCooldown: number = 2000;
private readonly historyWindow: number = 300000; // 5 minutes
private readonly baseAdaptiveCooldown: number = 1000;
private readonly maxAdaptiveCooldown: number = 10000;

constructor(options?: AdaptiveRateLimiterOptions) {
if (options) {
this.minRequestInterval = options.minRequestInterval ?? this.minRequestInterval;
this.completionCooldown = options.completionCooldown ?? this.completionCooldown;
this.historyWindow = options.historyWindow ?? this.historyWindow;
this.baseAdaptiveCooldown = options.baseAdaptiveCooldown ?? this.baseAdaptiveCooldown;
this.maxAdaptiveCooldown = options.maxAdaptiveCooldown ?? this.maxAdaptiveCooldown;
}
}

shouldAllowRequest(currentTime: number = Date.now()): boolean {
const timeSinceLastRequest = currentTime - this.lastRequestTime;
const timeSinceLastCompletion = currentTime - this.lastCompletionTime;
const adaptiveCooldown = this.getAdaptiveCooldown();

const minIntervalCheck = timeSinceLastRequest < this.minRequestInterval;
const adaptiveCooldownCheck = timeSinceLastCompletion < adaptiveCooldown;

// console.log('[AdaptiveRateLimiter] shouldAllowRequest check:', {
// timeSinceLastRequest,
// timeSinceLastCompletion,
// minRequestInterval: this.minRequestInterval,
// adaptiveCooldown,
// acceptanceRate: this.acceptanceRate,
// minIntervalCheck,
// adaptiveCooldownCheck
// });

// Check minimum request interval
if (minIntervalCheck) {
// console.log('[AdaptiveRateLimiter] Blocked: minimum request interval not met');
return false;
}

// Check adaptive cooldown
if (adaptiveCooldownCheck) {
// console.log('[AdaptiveRateLimiter] Blocked: adaptive cooldown active');
return false;
}

// console.log('[AdaptiveRateLimiter] Request allowed');
return true;
}

recordRequest(currentTime: number = Date.now()): void {
// console.log('[AdaptiveRateLimiter] Recording request at:', currentTime);
this.lastRequestTime = currentTime;
}

recordCompletion(currentTime: number = Date.now()): void {
// console.log('[AdaptiveRateLimiter] Recording completion at:', currentTime);
this.lastCompletionTime = currentTime;
}

trackCompletionShown(): void {
this.totalCompletions++;
this.recentCompletionHistory.push({
timestamp: Date.now(),
accepted: false
});
// console.log('[AdaptiveRateLimiter] Completion shown, total:', this.totalCompletions);
}

trackCompletionAccepted(): void {
this.acceptedCompletions++;

// Update the most recent completion as accepted
if (this.recentCompletionHistory.length > 0) {
this.recentCompletionHistory[this.recentCompletionHistory.length - 1].accepted = true;
}

// console.log('[AdaptiveRateLimiter] Completion accepted, total accepted:', this.acceptedCompletions);
}

trackCompletionRejected(): void {
this.rejectedCompletions++;
// console.log('[AdaptiveRateLimiter] Completion rejected, total rejected:', this.rejectedCompletions);
}

private getAdaptiveCooldown(): number {
this.updateAcceptanceRate();
// high fidelity adoption
// Higher acceptance rate = shorter cooldown, lower acceptance rate = longer cooldown
const adaptiveFactor = Math.max(0.1, 1 - this.acceptanceRate);
const adaptiveCooldown = Math.min(
this.maxAdaptiveCooldown,
this.baseAdaptiveCooldown + (this.baseAdaptiveCooldown * adaptiveFactor * 5)
);

return Math.max(this.completionCooldown, adaptiveCooldown);
}

private updateAcceptanceRate(): void {
const currentTime = Date.now();
const oldHistoryLength = this.recentCompletionHistory.length;

// Remove old entries beyond the history window
this.recentCompletionHistory = this.recentCompletionHistory.filter(
entry => currentTime - entry.timestamp < this.historyWindow
);

// Calculate acceptance rate from recent history
if (this.recentCompletionHistory.length > 0) {
const recentAccepted = this.recentCompletionHistory.filter(entry => entry.accepted).length;
this.acceptanceRate = recentAccepted / this.recentCompletionHistory.length;
} else {
// Default to 0.5 if no recent history
// do not penalize anyone at startup
this.acceptanceRate = 0.5;
}

// console.log('[AdaptiveRateLimiter] Acceptance rate updated:', {
// oldHistoryLength,
// newHistoryLength: this.recentCompletionHistory.length,
// acceptanceRate: this.acceptanceRate
// });
}

getStats(): AdaptiveRateLimiterStats {
return {
acceptanceRate: this.acceptanceRate,
totalCompletions: this.totalCompletions,
acceptedCompletions: this.acceptedCompletions,
rejectedCompletions: this.rejectedCompletions,
currentCooldown: this.getAdaptiveCooldown()
};
}
}
Loading