Skip to content

Commit

Permalink
v0.0.16 - google genai
Browse files Browse the repository at this point in the history
  • Loading branch information
MadcowD committed Feb 20, 2025
1 parent 8d9fe5b commit 21dff4b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
3 changes: 1 addition & 2 deletions examples/providers/gemini_ex.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
ell.init(verbose=True)

# custom client
client = genai.Client()

from PIL import Image, ImageDraw

Expand All @@ -25,7 +24,7 @@
fill='red')


@ell.simple(model='gemini-2.0-flash', client=client, max_tokens=10000)
@ell.simple(model='gemini-2.0-flash', max_tokens=10000)
def chat(prompt: str):
return [ell.user([prompt + " what is in this image", img])]

Expand Down
18 changes: 13 additions & 5 deletions src/ell/models/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"""

import os
from typing import Optional
from ell.configurator import config
import openai

Expand All @@ -29,7 +30,7 @@

logger = logging.getLogger(__name__)

def register(client: openai.Client):
def register(client: Optional[openai.Client] = None):
"""
Register OpenAI models with the provided client.
Expand All @@ -46,7 +47,8 @@ def register(client: openai.Client):
configuration with the registered models.
"""
standard_models = [
'gemini-2.0-flash-exp'
'gemini-2.0-flash-exp',
'gemini-2.0-flash',
'gemini-1.5-flash',
'gemini-1.5-flash-8b',
'gemini-1.5-pro',
Expand All @@ -58,10 +60,16 @@ def register(client: openai.Client):

default_client = None
try:
gemini_api_key = os.environ.get("GEMINI_API_KEY")
gemini_api_key = os.environ.get("GEMINI_API_KEY") or os.environ.get("GOOGLE_API_KEY")
if not gemini_api_key:
raise openai.OpenAIError("GEMINI_API_KEY not found in environment variables")
default_client = openai.Client(base_url="https://generativelanguage.googleapis.com/v1beta/openai/", api_key=gemini_api_key)
raise openai.OpenAIError("Neither GEMINI_API_KEY nor GOOGLE_API_KEY found in environment variables")
try:
from google import genai
default_client = genai.Client()
except ImportError:
logger.debug(f"{colorama.Fore.YELLOW}google.genai not found - using openai proxy for google models {colorama.Style.RESET_ALL}")
default_client = openai.Client(base_url="https://generativelanguage.googleapis.com/v1beta/openai/", api_key=gemini_api_key)

except openai.OpenAIError as e:
pass

Expand Down
2 changes: 1 addition & 1 deletion src/ell/util/_warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def {fn.__name__}(...):
ell.simple(model, client=my_client)(...)
```
{Style.RESET_ALL}""")
elif (client_to_use := config.registry[model].default_client) is None or not client_to_use.api_key:
elif (client_to_use := config.registry[model].default_client) is None or (hasattr(client_to_use, "api_key") and not client_to_use.api_key):
logger.warning(_no_api_key_warning(model, fn.__name__, client_to_use, long=False))


Expand Down

0 comments on commit 21dff4b

Please sign in to comment.