Use default google creds as fallback when not provided in llm_vertex,stt, and tts
This commit is contained in:
@@ -17,6 +17,8 @@ from loguru import logger
|
|||||||
from pipecat.services.openai.llm import OpenAILLMService
|
from pipecat.services.openai.llm import OpenAILLMService
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
from google.auth import default
|
||||||
|
from google.auth.exceptions import GoogleAuthError
|
||||||
from google.auth.transport.requests import Request
|
from google.auth.transport.requests import Request
|
||||||
from google.oauth2 import service_account
|
from google.oauth2 import service_account
|
||||||
|
|
||||||
@@ -98,6 +100,13 @@ class GoogleVertexLLMService(OpenAILLMService):
|
|||||||
creds = service_account.Credentials.from_service_account_file(
|
creds = service_account.Credentials.from_service_account_file(
|
||||||
credentials_path, scopes=["https://www.googleapis.com/auth/cloud-platform"]
|
credentials_path, scopes=["https://www.googleapis.com/auth/cloud-platform"]
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
creds, project_id = default(
|
||||||
|
scopes=["https://www.googleapis.com/auth/cloud-platform"]
|
||||||
|
)
|
||||||
|
except GoogleAuthError:
|
||||||
|
pass
|
||||||
|
|
||||||
if not creds:
|
if not creds:
|
||||||
raise ValueError("No valid credentials provided.")
|
raise ValueError("No valid credentials provided.")
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ from pipecat.utils.time import time_now_iso8601
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
from google.api_core.client_options import ClientOptions
|
from google.api_core.client_options import ClientOptions
|
||||||
|
from google.auth import default
|
||||||
|
from google.auth.exceptions import GoogleAuthError
|
||||||
from google.cloud import speech_v2
|
from google.cloud import speech_v2
|
||||||
from google.cloud.speech_v2.types import cloud_speech
|
from google.cloud.speech_v2.types import cloud_speech
|
||||||
from google.oauth2 import service_account
|
from google.oauth2 import service_account
|
||||||
@@ -451,6 +453,7 @@ class GoogleSTTService(STTService):
|
|||||||
client_options = ClientOptions(api_endpoint=f"{self._location}-speech.googleapis.com")
|
client_options = ClientOptions(api_endpoint=f"{self._location}-speech.googleapis.com")
|
||||||
|
|
||||||
# Extract project ID and create client
|
# Extract project ID and create client
|
||||||
|
creds: Optional[service_account.Credentials] = None
|
||||||
if credentials:
|
if credentials:
|
||||||
json_account_info = json.loads(credentials)
|
json_account_info = json.loads(credentials)
|
||||||
self._project_id = json_account_info.get("project_id")
|
self._project_id = json_account_info.get("project_id")
|
||||||
@@ -461,7 +464,16 @@ class GoogleSTTService(STTService):
|
|||||||
self._project_id = json_account_info.get("project_id")
|
self._project_id = json_account_info.get("project_id")
|
||||||
creds = service_account.Credentials.from_service_account_file(credentials_path)
|
creds = service_account.Credentials.from_service_account_file(credentials_path)
|
||||||
else:
|
else:
|
||||||
raise ValueError("Either credentials or credentials_path must be provided")
|
try:
|
||||||
|
creds, project_id = default(
|
||||||
|
scopes=["https://www.googleapis.com/auth/cloud-platform"]
|
||||||
|
)
|
||||||
|
self._project_id = project_id
|
||||||
|
except GoogleAuthError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if not creds:
|
||||||
|
raise ValueError("No valid credentials provided.")
|
||||||
|
|
||||||
if not self._project_id:
|
if not self._project_id:
|
||||||
raise ValueError("Project ID not found in credentials")
|
raise ValueError("Project ID not found in credentials")
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ from pipecat.services.tts_service import TTSService
|
|||||||
from pipecat.transcriptions.language import Language
|
from pipecat.transcriptions.language import Language
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
from google.auth import default
|
||||||
|
from google.auth.exceptions import GoogleAuthError
|
||||||
from google.cloud import texttospeech_v1
|
from google.cloud import texttospeech_v1
|
||||||
from google.oauth2 import service_account
|
from google.oauth2 import service_account
|
||||||
|
|
||||||
@@ -251,6 +253,16 @@ class GoogleTTSService(TTSService):
|
|||||||
elif credentials_path:
|
elif credentials_path:
|
||||||
# Use service account JSON file if provided
|
# Use service account JSON file if provided
|
||||||
creds = service_account.Credentials.from_service_account_file(credentials_path)
|
creds = service_account.Credentials.from_service_account_file(credentials_path)
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
creds, project_id = default(
|
||||||
|
scopes=["https://www.googleapis.com/auth/cloud-platform"]
|
||||||
|
)
|
||||||
|
except GoogleAuthError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if not creds:
|
||||||
|
raise ValueError("No valid credentials provided.")
|
||||||
|
|
||||||
return texttospeech_v1.TextToSpeechAsyncClient(credentials=creds)
|
return texttospeech_v1.TextToSpeechAsyncClient(credentials=creds)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user