Skip to content
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

πŸ› fix: fix parameter conditions for perplexity #1394

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 18 additions & 9 deletions src/libs/agent-runtime/perplexity/index.ts
Expand Up @@ -24,17 +24,26 @@
this.baseURL = this._llm.baseURL;
}

private buildCompletionsParams(payload: ChatStreamPayload) {
const { presence_penalty, frequency_penalty = 0.1, ...res } = payload;

let param;

// Ensure we are only have one frequency_penalty or frequency_penalty
if (presence_penalty !== 0) {
param = { presence_penalty };
} else {
param = { frequency_penalty };
}

return { ...res, ...param } as unknown as OpenAI.ChatCompletionCreateParamsStreaming;
}

Check warning on line 41 in src/libs/agent-runtime/perplexity/index.ts

View check run for this annotation

Codecov / codecov/patch

src/libs/agent-runtime/perplexity/index.ts#L27-L41

Added lines #L27 - L41 were not covered by tests
async chat(payload: ChatStreamPayload) {
try {
// Set a default frequency penalty value greater than 0
const defaultFrequencyPenalty = 0.1;
const chatPayload = {
...payload,
frequency_penalty: payload.frequency_penalty || defaultFrequencyPenalty,
};
const response = await this._llm.chat.completions.create(
chatPayload as unknown as OpenAI.ChatCompletionCreateParamsStreaming,
);
const params = this.buildCompletionsParams(payload);

const response = await this._llm.chat.completions.create(params);

Check warning on line 46 in src/libs/agent-runtime/perplexity/index.ts

View check run for this annotation

Codecov / codecov/patch

src/libs/agent-runtime/perplexity/index.ts#L44-L46

Added lines #L44 - L46 were not covered by tests

const stream = OpenAIStream(response);

Expand Down