Merge pull request #2837 from continuedev/dallin/prediction
OpenAI Prediction
This commit is contained in:
commit
aca7a7a4f0
2 changed files with 29 additions and 1 deletions
9
core/index.d.ts
vendored
9
core/index.d.ts
vendored
|
|
@ -780,6 +780,14 @@ export interface CustomCommand {
|
|||
description: string;
|
||||
}
|
||||
|
||||
interface Prediction {
|
||||
type: "content"
|
||||
content: string | {
|
||||
type: "text"
|
||||
text: string
|
||||
}[]
|
||||
}
|
||||
|
||||
interface BaseCompletionOptions {
|
||||
temperature?: number;
|
||||
topP?: number;
|
||||
|
|
@ -794,6 +802,7 @@ interface BaseCompletionOptions {
|
|||
keepAlive?: number;
|
||||
raw?: boolean;
|
||||
stream?: boolean;
|
||||
prediction?: Prediction;
|
||||
}
|
||||
|
||||
export interface ModelCapability {
|
||||
|
|
|
|||
|
|
@ -95,7 +95,14 @@ class OpenAI extends BaseLLM {
|
|||
);
|
||||
}
|
||||
|
||||
protected _convertArgs(options: any, messages: ChatMessage[]) {
|
||||
private supportsPrediction(model: string): boolean {
|
||||
return [
|
||||
"gpt-4o-mini",
|
||||
"gpt-4o"
|
||||
].includes(model);
|
||||
}
|
||||
|
||||
protected _convertArgs(options: CompletionOptions, messages: ChatMessage[]) {
|
||||
const url = new URL(this.apiBase!);
|
||||
const finalOptions: any = {
|
||||
messages: messages.map(this._convertMessage),
|
||||
|
|
@ -135,6 +142,18 @@ class OpenAI extends BaseLLM {
|
|||
);
|
||||
}
|
||||
|
||||
if (options.prediction && this.supportsPrediction(options.model)) {
|
||||
if (finalOptions.presence_penalty) { // prediction doesn't support > 0
|
||||
finalOptions.presence_penalty = undefined;
|
||||
}
|
||||
if (finalOptions.frequency_penalty) { // prediction doesn't support > 0
|
||||
finalOptions.frequency_penalty = undefined;
|
||||
}
|
||||
finalOptions.max_completion_tokens = undefined;
|
||||
|
||||
finalOptions.prediction = options.prediction;
|
||||
}
|
||||
|
||||
return finalOptions;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue