Skip to content

Commit 081be0f

Browse files
committed
initial
1 parent 4598b71 commit 081be0f

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

patchwork/common/client/llm/aio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from typing_extensions import AsyncIterator, Dict, Iterable, List, Optional, Union
1818

1919
from patchwork.common.client.llm.anthropic import AnthropicLlmClient
20-
from patchwork.common.client.llm.google import GoogleLlmClient
20+
from patchwork.common.client.llm.google_ import GoogleLlmClient
2121
from patchwork.common.client.llm.openai_ import OpenAiLlmClient
2222
from patchwork.common.client.llm.protocol import NOT_GIVEN, LlmClient, NotGiven
2323
from patchwork.common.constants import DEFAULT_PATCH_URL
Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import magic
88
from google import genai
9+
from google.auth.credentials import Credentials
910
from google.genai import types
1011
from google.genai.types import (
1112
CountTokensConfig,
@@ -26,7 +27,8 @@
2627
from openai.types.chat.chat_completion import ChatCompletion, Choice
2728
from pydantic import BaseModel
2829
from pydantic_ai.messages import ModelMessage, ModelResponse
29-
from pydantic_ai.models import Model, ModelRequestParameters, StreamedResponse
30+
from pydantic_ai.models import Model as PydanticAiModel
31+
from pydantic_ai.models import ModelRequestParameters, StreamedResponse
3032
from pydantic_ai.models.gemini import GeminiModel
3133
from pydantic_ai.settings import ModelSettings
3234
from pydantic_ai.usage import Usage
@@ -54,27 +56,29 @@ class GoogleLlmClient(LlmClient):
5456
]
5557
__MODEL_PREFIX = "models/"
5658

57-
def __init__(self, api_key: str, location: Optional[str] = None):
59+
def __init__(self, api_key: str, is_gcp: bool = False):
5860
self.__api_key = api_key
59-
self.__location = location
60-
self.client = genai.Client(api_key=api_key, location=location)
61+
self.__is_gcp = is_gcp
62+
if not is_gcp:
63+
self.client = genai.Client(api_key=api_key)
64+
else:
65+
self.client = genai.Client(api_key=api_key, vertexai=True, credentials=Credentials())
6166

6267
@lru_cache(maxsize=1)
6368
def __get_models_info(self) -> list[Model]:
6469
return list(self.client.models.list())
6570

66-
def __get_pydantic_model(self, model_settings: ModelSettings | None) -> Model:
71+
def __get_pydantic_model(self, model_settings: ModelSettings | None) -> PydanticAiModel:
6772
if model_settings is None:
6873
raise ValueError("Model settings cannot be None")
6974
model_name = model_settings.get("model")
7075
if model_name is None:
7176
raise ValueError("Model must be set cannot be None")
7277

73-
if self.__location is None:
78+
if not self.__is_gcp:
7479
return GeminiModel(model_name, api_key=self.__api_key)
75-
76-
url_template = f"https://{self.__location}-generativelanguage.googleapis.com/v1beta/models/{{model}}:"
77-
return GeminiModel(model_name, api_key=self.__api_key, url_template=url_template)
80+
else:
81+
return GeminiModel(model_name, provider="google-vertex")
7882

7983
async def request(
8084
self,

patchwork/common/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from patchwork.common.client.llm.aio import AioLlmClient
77
from patchwork.common.client.llm.anthropic import AnthropicLlmClient
8-
from patchwork.common.client.llm.google import GoogleLlmClient
8+
from patchwork.common.client.llm.google_ import GoogleLlmClient
99
from patchwork.common.client.llm.openai_ import OpenAiLlmClient
1010

1111
app = FastAPI()

0 commit comments

Comments
 (0)