Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tools/podcast_generator): add support for setting openai base url with the podcast_generationor tool #10517

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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