Ошибка инициализации функции from_config() в пакете embedchain. ⇐ Python

Программы на Python
Anonymous
Ошибка инициализации функции from_config() в пакете embedchain.

Сообщение Anonymous »

У меня возникла проблема при инициализации функции from_config() пакета embedchain:
Вот мой код:

Код: Выделить всё

from embedchain import App
from openai import OpenAI
import yaml

def initialize_bots(config_filename='config.json'):
global news_bot, email_bot, link_inserter_bot, image_inserter_bot, article_bot

# Load the JSON configuration directly

# Determine the base directory based on whether the script is running as a standalone executable or as a script
if getattr(sys, 'frozen', False):
# Running as an executable
base_directory = sys._MEIPASS  # Temporary folder where the executable's data is unpacked
else:
# Running as a script
base_directory = os.path.dirname(os.path.abspath(__file__))

config_file_path = os.path.join(base_directory, config_filename)

# Debug statement:
if os.path.exists(config_file_path):
print(f"{config_filename} is present in the base directory.")
else:
print(f"{config_filename} is NOT present in the base directory.")

# Check if the configuration file exists
if not os.path.exists(config_file_path):
raise FileNotFoundError(f"The configuration file {config_file_path} does not exist.")

# Load the configuration file
with open(config_file_path, 'r') as file:
config_data = json.load(file)

# Retrieve models and selected option from the configuration
models = config_data.get('Models', {}).get('models', None)
selected_option = config_data.get('Settings', {}).get('selected_ai_option', None)

# Ensure models is not None
if models is None:
raise ValueError("Models configuration is missing or incorrectly set in the configuration file.")

# Initialize news_bot
config_path = os.path.join(base_directory, 'config', 'openai.yaml')

# -------- Debug statement -------------

# Debug statement:
if os.path.exists(config_path):
print(f"{config_path} is present in the base directory. 1010101010101010 ")
else:
print(f"{config_path} is NOT present in the base directory. 1010101010101010 ")

# -------- Debug statement ------------

if not os.path.exists(config_path):
raise FileNotFoundError(f"The configuration file {config_path} does not exist.")

# (1) News bot
try:

with open(config_path, 'r') as file:
news_bot_data = yaml.safe_load(file)

print("news_bot_data:                      ", news_bot_data)

news_bot = App.from_config(config = news_bot_data)  # Error loading Bots in Exe (embedchain)
print("What is inside the News Bot:                                     ", news_bot)
except Exception as e:
error_info = traceback.print_exc()
print("something went wrong when loading the news bot. Exception is:    ", e)
print("something went wrong and error info:    ", error_info)
print("What is inside the News Bot:                                     ", news_bot)

# (2) Initialize email_bot
try:

with open(os.path.join(base_directory, "config", "email_openai.yaml"), 'r') as file:

email_bot_data = yaml.safe_load(file)

print("email_bot_data:                      ", email_bot_data)

email_bot = App.from_config(config = email_bot_data)
print("What is inside the Email Bot:                                     ", email_bot)
except Exception as e:
error_info = traceback.print_exc()
print("something went wrong when loading the Email bot.  Exception is:    ", e)
print("something went wrong and error info:    ", error_info)

print("What is inside the Email Bot:                                     ", email_bot)

# (3) Initialize link_inserter_bot
try:

with open(os.path.join(base_directory, "config", "link_inserter_openai.yaml"), 'r') as file:

link_insertion_bot_data = yaml.safe_load(file)

print("link_insertion_bot_data:                     ", link_insertion_bot_data)

link_inserter_bot = App.from_config(config = link_insertion_bot_data)
print("What is inside the Link Inserted Bot:                                     ", link_inserter_bot)
except Exception as e:
error_info = traceback.print_exc()
print("something went wrong when loading the link_inserter_bot Exception is:    ", e)
print("something went wrong and error info:    ", error_info)

print("What is inside the link inserter bot:                                     ", link_inserter_bot)

# (4) Initialize image_inserter_bot
try:

with open(os.path.join(base_directory, "config", "image_insertion_openai_gpt-4o.yaml"), 'r') as file:
image_insrtion_bot_data = yaml.safe_load(file)
print("image_insrtion_bot_data:                     ", image_insrtion_bot_data)

image_inserter_bot = App.from_config(config = image_insrtion_bot_data)
except Exception as e:

error_info = traceback.print_exc()

print("something went wrong when loading the image_inserter_bot Exception is:    ", e)
print("something went wrong and error info:    ", error_info)
print("What is inside the image inserter bot:                                     ", image_inserter_bot)

# Reset article_bot
article_bot = None

# Iterate through models to find the selected option

for model in models:
if selected_option == model:
config_file = f"article_writer_{model.lower().replace(' ', '_')}.yaml"
config_path = os.path.join(base_directory, 'config', config_file)

if not os.path.exists(config_path):
raise FileNotFoundError(f"The configuration file {config_path} does not exist.")

article_bot = App.from_config(config_path)
break

if article_bot is None:
print("No Model Selected")

Код работает нормально в моей локальной настройке.
Я использую pyinstaller для создания .exe. Но я получаю сообщение об ошибке:
Мультиплексный путь должен содержать хотя бы один тьфу.
Вот моя консоль:Мультиплексный путь должен содержать хотя бы один путь.
Ошибка в этой строке
news_bot = App.from_config(config = news_bot_data)
В этой функции, где я использую from_config(), я получаю ошибку во всех этих строках. данные конфигурации загружены правильно. Я не знаю, почему все та же ошибка.
Я пытался загрузить всех ботов в свой код с помощью функции from_config(). Но получаю ошибку, о которой я упоминал

Подробнее здесь: https://stackoverflow.com/questions/790 ... in-package

Вернуться в «Python»