Skip to content
This repository has been archived by the owner on Aug 12, 2024. It is now read-only.

OpenRouter Integration #50

Merged
merged 7 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
mistral,
octoai,
openai,
openrouter,
perplexity,
prem,
replicate,
Expand Down Expand Up @@ -75,6 +76,7 @@ def run_single_connector(connector_name: str) -> None:
"deepinfra": (openai.OpenAIConnector, "DEEP_INFRA_API_KEY"),
"perplexity": (perplexity.PerplexityAIConnector, "PERPLEXITY_API_KEY"),
"anyscale": (anyscale.AnyscaleEndpointsConnector, "ANYSCALE_API_KEY"),
"openrouter": (openrouter.OpenRouterConnector, "OPENROUTER_API_KEY"),
}

if connector_name == "deepinfra":
Expand Down
70 changes: 70 additions & 0 deletions prem_utils/connectors/openrouter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
from collections.abc import Sequence
from typing import Any

from prem_utils.connectors.openai import OpenAIConnector


class OpenRouterConnector(OpenAIConnector):
def __init__(
self, api_key: str, base_url: str = "https://openrouter.ai/api/v1/", 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 = 512,
frequency_penalty: float = 0.1,
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,
):
return super().chat_completion(
model=model,
messages=messages,
tools=tools,
tool_choice=tool_choice,
stream=stream,
max_tokens=max_tokens,
frequency_penalty=frequency_penalty,
presence_penalty=presence_penalty,
seed=seed,
stop=stop,
temperature=temperature,
top_p=top_p,
)

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
125 changes: 125 additions & 0 deletions prem_utils/models.json
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,131 @@
}
]
},
{
"provider": "openrouter",
"models": [
{
"slug": "openrouter/auto",
"model_type": "text2text",
"context_tokens": 128000
},
{
"slug": "nousresearch/nous-capybara-7b:free",
"model_type": "text2text",
"context_tokens": 4096
},
{
"slug": "mistralai/mistral-7b-instruct:free",
"model_type": "text2text",
"context_tokens": 8192
},
{
"slug": "gryphe/mythomist-7b:free",
"model_type": "text2text",
"context_tokens": 32768
},
{
"slug": "undi95/toppy-m-7b:free",
"model_type": "text2text",
"context_tokens": 4096
},
{
"slug": "openrouter/cinematika-7b:free",
"model_type": "text2text",
"context_tokens": 8000
},
{
"slug": "google/gemma-7b-it:free",
"model_type": "text2text",
"context_tokens": 8000
},
{
"slug": "jondurbin/bagel-34b",
"model_type": "text2text",
"context_tokens": 8000
},
{
"slug": "jebcarter/psyfighter-13b",
"model_type": "text2text",
"context_tokens": 4096
},
{
"slug": "koboldai/psyfighter-13b-2",
"model_type": "text2text",
"context_tokens": 4096
},
{
"slug": "neversleep/noromaid-mixtral-8x7b-instruct",
"model_type": "text2text",
"context_tokens": 8000
},
{
"slug": "nousresearch/nous-hermes-llama2-13b",
"model_type": "text2text",
"context_tokens": 4096
},
{
"slug": "meta-llama/codellama-34b-instruct",
"model_type": "text2text",
"context_tokens": 8192
},
{
"slug": "phind/phind-codellama-34b",
"model_type": "text2text",
"context_tokens": 4096
},
{
"slug": "intel/neural-chat-7b",
"model_type": "text2text",
"context_tokens": 4096
},
{
"slug": "openai/creativity-unlocked-prompts-dpr-32b",
"model_type": "text2text",
"context_tokens": 4096
},
{
"slug": "piiezzo/chatcoder-13b-instruct",
"model_type": "text2text",
"context_tokens": 8192
},
{
"slug": "alephai/decoder-40b-0.125",
"model_type": "text2text",
"context_tokens": 4096
},
{
"slug": "alephai/generator-40b-0.125",
"model_type": "text2text",
"context_tokens": 4096
},
{
"slug": "genestephen/mythwriter-10b-instruct",
"model_type": "text2text",
"context_tokens": 8192
},
{
"slug": "gothinker/cinima-9b-instruct",
"model_type": "text2text",
"context_tokens": 8192
},
{
"slug": "hanghangq/nr2-2048-8x8",
"model_type": "text2text",
"context_tokens": 4096
},
{
"slug": "maxschatzow/parrot-40b-instruct",
"model_type": "text2text",
"context_tokens": 8192
},
{
"slug": "tworivers/pegasus-24b-1",
"model_type": "text2text",
"context_tokens": 8192
}
]
},

{
"provider": "perplexity",
Expand Down
Loading