Skip to content

Commit

Permalink
Merge pull request #43 from askorama/feat/add-custom-prompts-prop
Browse files Browse the repository at this point in the history
Feat: add custom prompt configuration
  • Loading branch information
niltonheck authored Sep 19, 2024
2 parents c57ecee + cfeb12f commit 3d5d211
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/answerSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ export class AnswerSession {
requestBody.append('interactionId', interactionId)
requestBody.append('alias', this.oramaClient.getAlias() ?? '')

const systemPromptConfiguration = this.oramaClient.getSystemPromptConfiguration()
if (systemPromptConfiguration) {
requestBody.append('systemPrompts', JSON.stringify(systemPromptConfiguration))
}

if (this.userContext) {
requestBody.append('userContext', serializeUserContext(this.userContext))
}
Expand Down
18 changes: 18 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export class OramaClient {
private readonly collector?: Collector
private readonly cache?: Cache<Results<AnyDocument>>
private readonly profile: Profile
private systemPrompts?: string[]
private searchDebounceTimer?: any // NodeJS.Timer
private searchRequestCounter = 0
private blockSearchTillAuth = false
Expand Down Expand Up @@ -430,4 +431,21 @@ export class OramaClient {
public reset(): void {
this.profile.reset()
}

/**
* Methods associated with custom system prompts
*/
public setSystemPromptConfiguration(config: { systemPrompts: string[] }): void {
if (Array.isArray(config.systemPrompts)) {
if (!config.systemPrompts.every((prompt) => typeof prompt === 'string')) {
throw new Error('Invalid system prompt configuration')
}

this.systemPrompts = config.systemPrompts
}
}

public getSystemPromptConfiguration(): string[] | undefined {
return this.systemPrompts
}
}

0 comments on commit 3d5d211

Please sign in to comment.