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
This commit is contained in:
Wojciech Kordalski 2025-03-20 03:07:59 +01:00 committed by GitHub
parent 891a55d5f0
commit 499b8e4665
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 49 additions and 2 deletions

View file

@ -20,6 +20,7 @@ import { ApiStream } from "./transform/stream"
import { UnboundHandler } from "./providers/unbound"
import { RequestyHandler } from "./providers/requesty"
import { HumanRelayHandler } from "./providers/human-relay"
import { FakeAIHandler } from "./providers/fake-ai"
export interface SingleCompletionHandler {
completePrompt(prompt: string): Promise<string>
@ -75,6 +76,8 @@ export function buildApiHandler(configuration: ApiConfiguration): ApiHandler {
return new RequestyHandler(options)
case "human-relay":
return new HumanRelayHandler(options)
case "fake-ai":
return new FakeAIHandler(options)
default:
return new AnthropicHandler(options)
}

View file

@ -0,0 +1,39 @@
import { Anthropic } from "@anthropic-ai/sdk"
import { ApiHandler, SingleCompletionHandler } from ".."
import { ApiHandlerOptions, ModelInfo } from "../../shared/api"
import { ApiStream } from "../transform/stream"
interface FakeAI {
createMessage(systemPrompt: string, messages: Anthropic.Messages.MessageParam[]): ApiStream
getModel(): { id: string; info: ModelInfo }
countTokens(content: Array<Anthropic.Messages.ContentBlockParam>): Promise<number>
completePrompt(prompt: string): Promise<string>
}
export class FakeAIHandler implements ApiHandler, SingleCompletionHandler {
private ai: FakeAI
constructor(options: ApiHandlerOptions) {
if (!options.fakeAi) {
throw new Error("Fake AI is not set")
}
this.ai = options.fakeAi as FakeAI
}
async *createMessage(systemPrompt: string, messages: Anthropic.Messages.MessageParam[]): ApiStream {
yield* this.ai.createMessage(systemPrompt, messages)
}
getModel(): { id: string; info: ModelInfo } {
return this.ai.getModel()
}
countTokens(content: Array<Anthropic.Messages.ContentBlockParam>): Promise<number> {
return this.ai.countTokens(content)
}
completePrompt(prompt: string): Promise<string> {
return this.ai.completePrompt(prompt)
}
}

View file

@ -254,6 +254,7 @@ export type GlobalStateKey =
| "showRooIgnoredFiles"
| "remoteBrowserEnabled"
| "language"
| "fakeAi"
export type ConfigurationKey = GlobalStateKey | SecretKey

View file

@ -17,6 +17,7 @@ export type ApiProvider =
| "unbound"
| "requesty"
| "human-relay"
| "fake-ai"
export interface ApiHandlerOptions {
apiModelId?: string
@ -76,6 +77,7 @@ export interface ApiHandlerOptions {
modelTemperature?: number | null
modelMaxTokens?: number
modelMaxThinkingTokens?: number
fakeAi?: unknown
}
export type ApiConfiguration = ApiHandlerOptions & {
@ -134,6 +136,7 @@ export const API_CONFIG_KEYS: GlobalStateKey[] = [
"modelTemperature",
"modelMaxTokens",
"modelMaxThinkingTokens",
"fakeAi",
]
// Models

View file

@ -4,8 +4,8 @@ import { SECRET_KEYS } from "./globalState"
export function checkExistKey(config: ApiConfiguration | undefined) {
if (!config) return false
// Special case for human-relay provider which doesn't need any configuration
if (config.apiProvider === "human-relay") {
// Special case for human-relay and fake-ai providers which don't need any configuration
if (config.apiProvider === "human-relay" || config.apiProvider === "fake-ai") {
return true
}

View file

@ -122,6 +122,7 @@ export const GLOBAL_STATE_KEYS = [
"remoteBrowserEnabled",
"language",
"maxWorkspaceFiles",
"fakeAi",
] as const
export const PASS_THROUGH_STATE_KEYS = ["taskHistory"] as const