Skip to content

Commit

Permalink
openrouter
Browse files Browse the repository at this point in the history
  • Loading branch information
vprelovac committed Oct 18, 2024
1 parent 86c3df1 commit e01a64c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
1 change: 1 addition & 0 deletions llms/providers/bedrock_anthropic.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class BedrockAnthropicProvider(AnthropicProvider):
"anthropic.claude-v2": {"prompt": 11.02, "completion": 32.68, "token_limit": 100_000},
"anthropic.claude-3-haiku-20240307-v1:0": {"prompt": 0.25, "completion": 1.25, "token_limit": 200_000, "output_limit": 4_096},
"anthropic.claude-3-sonnet-20240229-v1:0": {"prompt": 3.00, "completion": 15, "token_limit": 200_000, "output_limit": 4_096},
"anthropic.claude-3-5-sonnet-20240620-v1:0": {"prompt": 3.00, "completion": 15, "token_limit": 200_000, "output_limit": 4_096},
}

def __init__(
Expand Down
22 changes: 12 additions & 10 deletions llms/providers/google_genai.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os, math
from typing import Dict

import google.generativeai as palm
import google.generativeai as genai

from ..results.result import Result
from .base_provider import BaseProvider
Expand All @@ -17,7 +17,10 @@ class GoogleGenAIProvider(BaseProvider):
"chat-bison-genai": {"prompt": 0.5, "completion": 0.5, "token_limit": 0, "uses_characters": True},
"text-bison-genai": {"prompt": 1.0, "completion": 1.0, "token_limit": 0, "uses_characters": True},
"gemini-1.5-pro": {"prompt": 3.5, "completion": 10.5, "token_limit": 128000, "uses_characters": True},
"gemini-1.5-flash": {"prompt": 0.35, "completion": 1.05, "token_limit": 128000, "uses_characters": True},
"gemini-1.5-pro-latest": {"prompt": 3.5, "completion": 10.5, "token_limit": 128000, "uses_characters": True},
"gemini-1.5-flash": {"prompt": 0.075, "completion": 0.3, "token_limit": 128000, "uses_characters": True},
"gemini-1.5-flash-latest": {"prompt": 0.075, "completion": 0.3, "token_limit": 128000, "uses_characters": True},
"gemini-1.5-pro-exp-0801" : {"prompt": 3.5, "completion": 10.5, "token_limit": 128000, "uses_characters": True},
}

def __init__(self, api_key=None, model=None, **kwargs):
Expand All @@ -27,15 +30,14 @@ def __init__(self, api_key=None, model=None, **kwargs):
if api_key is None:
api_key = os.getenv("GOOGLE_API_KEY")

self.client = palm.configure(api_key=api_key)
self.client = genai.configure(api_key=api_key)

self.model = model
if model.startswith('text-'):
self.client = palm.generate_text
self.client = genai.generate_text
self.mode = 'text'
else:
self.client = palm.chat
self.async_client = palm.chat_async
self.client = genai.GenerativeModel(model)
self.mode = 'chat'


Expand All @@ -52,8 +54,8 @@ def _prepare_model_inputs(
messages=kwargs.pop("messages", [])
messages=messages + [prompt]
model_inputs = {
"messages": messages,
"temperature": temperature,
#"messages": messages,
#"temperature": temperature,
**kwargs,
}
else:
Expand All @@ -80,10 +82,10 @@ def complete(
**kwargs,
)
with self.track_latency():
response = self.client(**model_inputs)
response = self.client.generate_content(prompt)

if self.mode == 'chat':
completion = response.last
completion = response.text
else:
completion = response.result

Expand Down
2 changes: 1 addition & 1 deletion llms/providers/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class OpenAIProvider(BaseProvider):
"gpt-4-1106-preview": {"prompt": 10.0, "completion": 30.0, "token_limit": 128000, "is_chat": True, "output_limit": 4_096},
"gpt-4-turbo-preview": {"prompt": 10.0, "completion": 30.0, "token_limit": 128000, "is_chat": True, "output_limit": 4_096},
"gpt-4-turbo": {"prompt": 10.0, "completion": 30.0, "token_limit": 128000, "is_chat": True, "output_limit": 4_096},
"gpt-4o": {"prompt": 5.0, "completion": 15.0, "token_limit": 128000, "is_chat": True, "output_limit": 4_096},
"gpt-4o": {"prompt": 2.5, "completion": 10.0, "token_limit": 128000, "is_chat": True, "output_limit": 4_096},
"gpt-4o-mini": {"prompt": 0.15, "completion": 0.60, "token_limit": 128000, "is_chat": True, "output_limit": 4_096},
"gpt-4o-2024-08-06": {"prompt": 2.50, "completion": 10.0, "token_limit": 128000, "is_chat": True, "output_limit": 4_096},
"o1-preview": {"prompt": 15.0, "completion": 60.0, "token_limit": 128000, "is_chat": True, "output_limit": 4_096, "use_max_completion_tokens": True},
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ protobuf
grpcio~=1.54.2
google-generativeai
ollama
reka-api
reka-api
together
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

setup(
name="pyllms",
version="0.5.2",
description="Minimal Python library to connect to LLMs (OpenAI, Anthropic, Google Palm2/Vertex, Mistral, Ollama, AI21, Cohere, Aleph-Alpha, HuggingfaceHub), with a built-in model performance benchmark.",
version="0.6.0",
description="Minimal Python library to connect to LLMs (OpenAI, Anthropic, Google,, Mistral, Reka, Groq, Together, Ollama, AI21, Cohere, Aleph-Alpha, HuggingfaceHub), with a built-in model performance benchmark.",
long_description=long_description,
long_description_content_type="text/markdown",
author="Vladimir Prelovac",
Expand Down

0 comments on commit e01a64c

Please sign in to comment.