Skip to content

Commit

Permalink
Make both system and user prompt optional in customPrompt return
Browse files Browse the repository at this point in the history
  • Loading branch information
arshad-yaseen committed Sep 10, 2024
1 parent 6769cb4 commit d04cef2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/helpers/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ export const createRequestBody = (
provider: CompletionProvider,
customPrompt: CustomPrompt | undefined,
): PickChatCompletionCreateParams<CompletionProvider> => {
const {system: systemPrompt, user: userPrompt} = customPrompt
? customPrompt(completionMetadata)
: generatePrompt(completionMetadata);
const defaultPrompts = generatePrompt(completionMetadata);
const customPrompts = customPrompt ? customPrompt(completionMetadata) : {};

const systemPrompt = customPrompts.system ?? defaultPrompts.system;
const userPrompt = customPrompts.user ?? defaultPrompts.user;

const commonParams = {
model: getModelId(model),
Expand Down
4 changes: 2 additions & 2 deletions src/types/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ export interface CompletionRequestOptions {
}

export type CustomPrompt = (completionMetadata: CompletionMetadata) => {
system: string;
user: string;
system?: string;
user?: string;
};

export interface CompletionResponse {
Expand Down

0 comments on commit d04cef2

Please sign in to comment.