This repository has been archived by the owner on Aug 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from premAI-io/perplexity
Perplexity Provider.
- Loading branch information
Showing
3 changed files
with
132 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
from collections.abc import Sequence | ||
from typing import Any | ||
|
||
from prem_utils.connectors.openai import OpenAIConnector | ||
|
||
|
||
class PerplexityAIConnector(OpenAIConnector): | ||
def __init__(self, api_key: str, base_url: str = "https://api.perplexity.ai", prompt_template: str = None) -> None: | ||
super().__init__(prompt_template=prompt_template, base_url=base_url, api_key=api_key) | ||
|
||
def chat_completion( | ||
self, | ||
model: str, | ||
messages: list[dict[str, Any]], | ||
max_tokens: int = None, | ||
frequency_penalty: float = 0.1, | ||
log_probs: int = None, | ||
logit_bias: dict[str, float] = None, | ||
presence_penalty: float = 0, | ||
seed: int | None = None, | ||
stop: str | list[str] = None, | ||
stream: bool = False, | ||
temperature: float = 1, | ||
top_p: float = 1, | ||
tools: list[dict[str, Any]] = None, | ||
tool_choice: dict = None, | ||
): | ||
if "perplexity" in model: | ||
model = model.replace("perplexity/", "", 1) | ||
|
||
return super().chat_completion( | ||
model, | ||
messages, | ||
max_tokens, | ||
frequency_penalty, | ||
log_probs, | ||
logit_bias, | ||
presence_penalty, | ||
seed, | ||
stop, | ||
stream, | ||
temperature, | ||
top_p, | ||
tools, | ||
tool_choice, | ||
) | ||
|
||
def embeddings( | ||
self, | ||
model: str, | ||
input: str | Sequence[str] | Sequence[int] | Sequence[Sequence[int]], | ||
encoding_format: str = "float", | ||
user: str = None, | ||
): | ||
raise NotImplementedError | ||
|
||
def finetuning( | ||
self, model: str, training_data: list[dict], validation_data: list[dict] | None = None, num_epochs: int = 3 | ||
) -> str: | ||
raise NotImplementedError | ||
|
||
def get_finetuning_job(self, job_id) -> dict[str, Any]: | ||
raise NotImplementedError | ||
|
||
def generate_image( | ||
self, | ||
model: str, | ||
prompt: str, | ||
size: str = "1024x1024", | ||
n: int = 1, | ||
quality: str = "standard", | ||
style: str = "vivid", | ||
response_format: str = "url", | ||
): | ||
raise NotImplementedError |
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