-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Fake AI provider #1769
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Fake AI provider #1769
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we hide this in the settings UI? I'm assuming this will only be used programmatically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is better to hide it. My only concern would be if the
fake-aiprovider is set viaRooCodeAPI.setConfiguration, and later the settings view is opened as part of the e2e test, wouldn't this lead to some inconsistent state and possibly the setting view "normalizing" and overwriting the config value? Although, you could just say "don't open settings during e2e tests" and that would be fine for us, since we can use setConfiguration to setup settings for a test.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can deal with this if it ever comes up in the e2e tests; for now let's optimize for not causing user confusion and hide this in the settings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
It seems that when Fake AI is set as an API provider, in the settings view the API Provider input simply shows an empty field (no API provider is selected).
Saving the settings will clear the
fakeAiobject that handles API requests (and thus further requests will fail until the user sets another API provider). Showing settings view without saving does not overwrite configuration.