Skip to content

Commit 499b8e4

Browse files
authored
Fake AI provider (#1769)
* Fake AI * Do not show Fake AI in Roo-Code settings * Rename providers/fake-provider.ts to providers/fake-ai.ts
1 parent 891a55d commit 499b8e4

File tree

6 files changed

+49
-2
lines changed

6 files changed

+49
-2
lines changed

src/api/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { ApiStream } from "./transform/stream"
2020
import { UnboundHandler } from "./providers/unbound"
2121
import { RequestyHandler } from "./providers/requesty"
2222
import { HumanRelayHandler } from "./providers/human-relay"
23+
import { FakeAIHandler } from "./providers/fake-ai"
2324

2425
export interface SingleCompletionHandler {
2526
completePrompt(prompt: string): Promise<string>
@@ -75,6 +76,8 @@ export function buildApiHandler(configuration: ApiConfiguration): ApiHandler {
7576
return new RequestyHandler(options)
7677
case "human-relay":
7778
return new HumanRelayHandler(options)
79+
case "fake-ai":
80+
return new FakeAIHandler(options)
7881
default:
7982
return new AnthropicHandler(options)
8083
}

src/api/providers/fake-ai.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { Anthropic } from "@anthropic-ai/sdk"
2+
import { ApiHandler, SingleCompletionHandler } from ".."
3+
import { ApiHandlerOptions, ModelInfo } from "../../shared/api"
4+
import { ApiStream } from "../transform/stream"
5+
6+
interface FakeAI {
7+
createMessage(systemPrompt: string, messages: Anthropic.Messages.MessageParam[]): ApiStream
8+
getModel(): { id: string; info: ModelInfo }
9+
countTokens(content: Array<Anthropic.Messages.ContentBlockParam>): Promise<number>
10+
completePrompt(prompt: string): Promise<string>
11+
}
12+
13+
export class FakeAIHandler implements ApiHandler, SingleCompletionHandler {
14+
private ai: FakeAI
15+
16+
constructor(options: ApiHandlerOptions) {
17+
if (!options.fakeAi) {
18+
throw new Error("Fake AI is not set")
19+
}
20+
21+
this.ai = options.fakeAi as FakeAI
22+
}
23+
24+
async *createMessage(systemPrompt: string, messages: Anthropic.Messages.MessageParam[]): ApiStream {
25+
yield* this.ai.createMessage(systemPrompt, messages)
26+
}
27+
28+
getModel(): { id: string; info: ModelInfo } {
29+
return this.ai.getModel()
30+
}
31+
32+
countTokens(content: Array<Anthropic.Messages.ContentBlockParam>): Promise<number> {
33+
return this.ai.countTokens(content)
34+
}
35+
36+
completePrompt(prompt: string): Promise<string> {
37+
return this.ai.completePrompt(prompt)
38+
}
39+
}

src/exports/roo-code.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ export type GlobalStateKey =
254254
| "showRooIgnoredFiles"
255255
| "remoteBrowserEnabled"
256256
| "language"
257+
| "fakeAi"
257258

258259
export type ConfigurationKey = GlobalStateKey | SecretKey
259260

src/shared/api.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export type ApiProvider =
1717
| "unbound"
1818
| "requesty"
1919
| "human-relay"
20+
| "fake-ai"
2021

2122
export interface ApiHandlerOptions {
2223
apiModelId?: string
@@ -76,6 +77,7 @@ export interface ApiHandlerOptions {
7677
modelTemperature?: number | null
7778
modelMaxTokens?: number
7879
modelMaxThinkingTokens?: number
80+
fakeAi?: unknown
7981
}
8082

8183
export type ApiConfiguration = ApiHandlerOptions & {
@@ -134,6 +136,7 @@ export const API_CONFIG_KEYS: GlobalStateKey[] = [
134136
"modelTemperature",
135137
"modelMaxTokens",
136138
"modelMaxThinkingTokens",
139+
"fakeAi",
137140
]
138141

139142
// Models

src/shared/checkExistApiConfig.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { SECRET_KEYS } from "./globalState"
44
export function checkExistKey(config: ApiConfiguration | undefined) {
55
if (!config) return false
66

7-
// Special case for human-relay provider which doesn't need any configuration
8-
if (config.apiProvider === "human-relay") {
7+
// Special case for human-relay and fake-ai providers which don't need any configuration
8+
if (config.apiProvider === "human-relay" || config.apiProvider === "fake-ai") {
99
return true
1010
}
1111

src/shared/globalState.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ export const GLOBAL_STATE_KEYS = [
122122
"remoteBrowserEnabled",
123123
"language",
124124
"maxWorkspaceFiles",
125+
"fakeAi",
125126
] as const
126127

127128
export const PASS_THROUGH_STATE_KEYS = ["taskHistory"] as const

0 commit comments

Comments
 (0)