Skip to content

Commit

Permalink
feat(tools/podcast_generator): add support for setting openai base ur…
Browse files Browse the repository at this point in the history
…l with the podcast_generationor tool (#10517)
  • Loading branch information
XiaoLey authored Nov 11, 2024
1 parent 5656f81 commit 451ccb7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,15 @@ credentials_for_provider:
placeholder:
en_US: Enter your TTS service API key
zh_Hans: 输入您的 TTS 服务 API 密钥
openai_base_url:
type: text-input
required: false
label:
en_US: OpenAI base URL
zh_Hans: OpenAI base URL
help:
en_US: Please input your OpenAI base URL
zh_Hans: 请输入你的 OpenAI base URL
placeholder:
en_US: Please input your OpenAI base URL
zh_Hans: 请输入你的 OpenAI base URL
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import Any, Literal, Optional, Union

import openai
from yarl import URL

from core.tools.entities.tool_entities import ToolInvokeMessage
from core.tools.errors import ToolParameterValidationError, ToolProviderCredentialValidationError
Expand Down Expand Up @@ -53,15 +54,24 @@ def _invoke(
if not host1_voice or not host2_voice:
raise ToolParameterValidationError("Host voices are required")

# Get OpenAI API key from credentials
# Ensure runtime and credentials
if not self.runtime or not self.runtime.credentials:
raise ToolProviderCredentialValidationError("Tool runtime or credentials are missing")

# Get OpenAI API key from credentials
api_key = self.runtime.credentials.get("api_key")
if not api_key:
raise ToolProviderCredentialValidationError("OpenAI API key is missing")

# Get OpenAI base URL
openai_base_url = self.runtime.credentials.get("openai_base_url", None)
openai_base_url = str(URL(openai_base_url) / "v1") if openai_base_url else None

# Initialize OpenAI client
client = openai.OpenAI(api_key=api_key)
client = openai.OpenAI(
api_key=api_key,
base_url=openai_base_url,
)

# Create a thread pool
max_workers = 5
Expand Down

0 comments on commit 451ccb7

Please sign in to comment.