-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
155 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 |
---|---|---|
@@ -1 +1,18 @@ | ||
export interface PromptExecutor {} | ||
import { CompletionPrompt } from "prompt-schema"; | ||
import { OpenAIExecutor } from "./OpenAI"; | ||
import Result from "./Result"; | ||
|
||
export interface PromptExecutor { | ||
executeCompletion(prompt: CompletionPrompt): Promise<Result>; | ||
} | ||
|
||
export class PromptExecutionDelegate implements PromptExecutor { | ||
private openAiExecutor: OpenAIExecutor; | ||
constructor(private openAIApiKey: string) { | ||
this.openAiExecutor = new OpenAIExecutor(openAIApiKey); | ||
} | ||
|
||
async executeCompletion(prompt: CompletionPrompt): Promise<Result> { | ||
return this.openAiExecutor.executeCompletion(prompt); | ||
} | ||
} |
This file contains 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 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,21 @@ | ||
/** | ||
* see: | ||
* https://platform.openai.com/docs/api-reference | ||
* https://learn.microsoft.com/en-us/azure/ai-services/openai/reference | ||
*/ | ||
|
||
export class Choice { | ||
constructor(public text: string, public index: number, public finishReason: string) {} | ||
} | ||
|
||
export default class Result { | ||
constructor(public id: string, public created: number, public choices: Choice[]) {} | ||
static fromJSON(json: any): Result { | ||
const choices = json.choices.map( | ||
(choiceJSON: any) => | ||
new Choice(choiceJSON.text, choiceJSON.index, choiceJSON.finishReason) | ||
); | ||
|
||
return new Result(json.id, json.created, choices); | ||
} | ||
} |
This file contains 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,16 @@ | ||
import { ChatPrompt, CompletionPrompt } from "prompt-schema"; | ||
import { vscode } from "./vscode"; | ||
|
||
export function syncPrompt(newPrompt: ChatPrompt | CompletionPrompt) { | ||
vscode.postMessage({ | ||
type: "sync", | ||
text: JSON.stringify(newPrompt, null, 2), | ||
}); | ||
} | ||
|
||
export function showError(info: string) { | ||
vscode.postMessage({ | ||
type: "error", | ||
text: info, | ||
}); | ||
} |