From c3fe086b7800a42988dbdd61f2c12bcc1f0669e5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 2 Jun 2025 20:23:21 +0000 Subject: [PATCH 1/7] Initial plan for issue From 05b0d9cd5f1e0072ebb10abdbd2f810dd334e72a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 2 Jun 2025 20:36:45 +0000 Subject: [PATCH 2/7] Add load_dotenv() to missing entry points Co-authored-by: MSDNAndi <6744335+MSDNAndi@users.noreply.github.com> --- Paper2Poster-eval/create_paper_questions.py | 3 +++ PosterAgent/new_pipeline.py | 3 +++ PosterAgent/poster_gen_pipeline.py | 3 +++ 3 files changed, 9 insertions(+) diff --git a/Paper2Poster-eval/create_paper_questions.py b/Paper2Poster-eval/create_paper_questions.py index bda1d9a..37a3c0e 100644 --- a/Paper2Poster-eval/create_paper_questions.py +++ b/Paper2Poster-eval/create_paper_questions.py @@ -1,8 +1,11 @@ +from dotenv import load_dotenv from utils.poster_eval_utils import * import argparse import os import json +load_dotenv() + if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--paper_folder', type=str, default=None) diff --git a/PosterAgent/new_pipeline.py b/PosterAgent/new_pipeline.py index e90cb61..eee1d19 100644 --- a/PosterAgent/new_pipeline.py +++ b/PosterAgent/new_pipeline.py @@ -1,3 +1,4 @@ +from dotenv import load_dotenv from PosterAgent.parse_raw import parse_raw, gen_image_and_table from PosterAgent.gen_outline_layout import filter_image_table, gen_outline_layout_v2 from utils.wei_utils import get_agent_config, utils_functions, run_code, style_bullet_content, scale_to_target_area @@ -12,6 +13,8 @@ import os import time +load_dotenv() + units_per_inch = 25 # Create your theme profile here diff --git a/PosterAgent/poster_gen_pipeline.py b/PosterAgent/poster_gen_pipeline.py index e1b0ee8..bcf8497 100644 --- a/PosterAgent/poster_gen_pipeline.py +++ b/PosterAgent/poster_gen_pipeline.py @@ -1,3 +1,4 @@ +from dotenv import load_dotenv import argparse import time @@ -9,6 +10,8 @@ from PosterAgent.deoverflow import deoverflow from PosterAgent.apply_theme import poster_apply_theme +load_dotenv() + if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--poster_name', type=str, default=None) From 350c676fd24e0efcc0c6a210453c80024127a71b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 2 Jun 2025 20:54:55 +0000 Subject: [PATCH 3/7] Centralize environment loading in parse_raw.py and poster_eval_utils.py Co-authored-by: MSDNAndi <6744335+MSDNAndi@users.noreply.github.com> --- Paper2Poster-eval/create_paper_questions.py | 3 --- PosterAgent/new_pipeline.py | 3 --- PosterAgent/parse_raw.py | 17 ++++++++++++++++- PosterAgent/poster_gen_pipeline.py | 3 --- utils/poster_eval_utils.py | 15 ++++++++++++++- 5 files changed, 30 insertions(+), 11 deletions(-) diff --git a/Paper2Poster-eval/create_paper_questions.py b/Paper2Poster-eval/create_paper_questions.py index 37a3c0e..bda1d9a 100644 --- a/Paper2Poster-eval/create_paper_questions.py +++ b/Paper2Poster-eval/create_paper_questions.py @@ -1,11 +1,8 @@ -from dotenv import load_dotenv from utils.poster_eval_utils import * import argparse import os import json -load_dotenv() - if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--paper_folder', type=str, default=None) diff --git a/PosterAgent/new_pipeline.py b/PosterAgent/new_pipeline.py index eee1d19..e90cb61 100644 --- a/PosterAgent/new_pipeline.py +++ b/PosterAgent/new_pipeline.py @@ -1,4 +1,3 @@ -from dotenv import load_dotenv from PosterAgent.parse_raw import parse_raw, gen_image_and_table from PosterAgent.gen_outline_layout import filter_image_table, gen_outline_layout_v2 from utils.wei_utils import get_agent_config, utils_functions, run_code, style_bullet_content, scale_to_target_area @@ -13,8 +12,6 @@ import os import time -load_dotenv() - units_per_inch = 25 # Create your theme profile here diff --git a/PosterAgent/parse_raw.py b/PosterAgent/parse_raw.py index 8d30a4e..fad5dea 100644 --- a/PosterAgent/parse_raw.py +++ b/PosterAgent/parse_raw.py @@ -3,6 +3,7 @@ from utils.src.model_utils import parse_pdf import json import random +import os from camel.models import ModelFactory from camel.agents import ChatAgent @@ -28,7 +29,21 @@ import re import argparse -load_dotenv() +# Load environment variables - look for .env file in project root +from dotenv import load_dotenv +from pathlib import Path + +# Find the project root (look for files that indicate project root) +def find_project_root(): + current = Path(__file__).resolve() + for parent in current.parents: + if (parent / 'requirements.txt').exists() and (parent / 'PosterAgent').exists(): + return parent + return current.parent + +project_root = find_project_root() +dotenv_path = project_root / '.env' +load_dotenv(dotenv_path) IMAGE_RESOLUTION_SCALE = 5.0 pipeline_options = PdfPipelineOptions() diff --git a/PosterAgent/poster_gen_pipeline.py b/PosterAgent/poster_gen_pipeline.py index bcf8497..e1b0ee8 100644 --- a/PosterAgent/poster_gen_pipeline.py +++ b/PosterAgent/poster_gen_pipeline.py @@ -1,4 +1,3 @@ -from dotenv import load_dotenv import argparse import time @@ -10,8 +9,6 @@ from PosterAgent.deoverflow import deoverflow from PosterAgent.apply_theme import poster_apply_theme -load_dotenv() - if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--poster_name', type=str, default=None) diff --git a/utils/poster_eval_utils.py b/utils/poster_eval_utils.py index 953edd2..151819b 100644 --- a/utils/poster_eval_utils.py +++ b/utils/poster_eval_utils.py @@ -1182,7 +1182,20 @@ def replace_with_caption(match): def get_questions(paper_text, mode, model_type): from dotenv import load_dotenv - load_dotenv() + from pathlib import Path + + # Find the project root and load .env file + def find_project_root(): + current = Path(__file__).resolve() + for parent in current.parents: + if (parent / 'requirements.txt').exists() and (parent / 'PosterAgent').exists(): + return parent + return current.parent + + project_root = find_project_root() + dotenv_path = project_root / '.env' + load_dotenv(dotenv_path) + agent_name = f'generate_question_{mode}' with open(f"utils/prompt_templates/{agent_name}.yaml", "r") as f: config = yaml.safe_load(f) From 5c4ff49cb878c24763f98eafd77dbfc61eb61c5e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 2 Jun 2025 21:32:59 +0000 Subject: [PATCH 4/7] Fix Azure OpenAI platform detection and environment variable support Co-authored-by: MSDNAndi <6744335+MSDNAndi@users.noreply.github.com> --- PosterAgent/parse_raw.py | 1 - camel/models/azure_openai_model.py | 6 +-- utils/wei_utils.py | 79 +++++++++++++++++++++--------- 3 files changed, 60 insertions(+), 26 deletions(-) diff --git a/PosterAgent/parse_raw.py b/PosterAgent/parse_raw.py index fad5dea..3c52b68 100644 --- a/PosterAgent/parse_raw.py +++ b/PosterAgent/parse_raw.py @@ -1,4 +1,3 @@ -from dotenv import load_dotenv from utils.src.utils import get_json_from_response from utils.src.model_utils import parse_pdf import json diff --git a/camel/models/azure_openai_model.py b/camel/models/azure_openai_model.py index 1a87b4b..c9a2ab7 100644 --- a/camel/models/azure_openai_model.py +++ b/camel/models/azure_openai_model.py @@ -66,15 +66,15 @@ def __init__( if model_config_dict is None: model_config_dict = ChatGPTConfig().as_dict() api_key = api_key or os.environ.get("AZURE_OPENAI_API_KEY") - url = url or os.environ.get("AZURE_OPENAI_BASE_URL") + url = url or os.environ.get("AZURE_OPENAI_BASE_URL") or os.environ.get("AZURE_OPENAI_ENDPOINT") super().__init__( model_type, model_config_dict, api_key, url, token_counter ) - self.api_version = api_version or os.environ.get("AZURE_API_VERSION") + self.api_version = api_version or os.environ.get("AZURE_API_VERSION") or os.environ.get("AZURE_OPENAI_API_VERSION") self.azure_deployment_name = azure_deployment_name or os.environ.get( "AZURE_DEPLOYMENT_NAME" - ) + ) or os.environ.get("AZURE_OPENAI_DEPLOYMENT_NAME") if self.api_version is None: raise ValueError( "Must provide either the `api_version` argument " diff --git a/utils/wei_utils.py b/utils/wei_utils.py index f33bafd..564b8d6 100644 --- a/utils/wei_utils.py +++ b/utils/wei_utils.py @@ -24,6 +24,9 @@ from utils.critic_utils import * def get_agent_config(model_type): + # Check environment variables for platform override + model_platform_env = os.environ.get('MODEL_PLATFORM', '').lower() + agent_config = {} if model_type == 'qwen': agent_config = { @@ -117,31 +120,63 @@ def get_agent_config(model_type): "model_platform": ModelPlatformType.OPENAI, } elif model_type == '4o': - agent_config = { - "model_type": ModelType.GPT_4O, - "model_config": ChatGPTConfig().as_dict(), - "model_platform": ModelPlatformType.OPENAI, - # "model_name": '4o' - } + # Check if Azure platform is requested via environment variable + if model_platform_env == 'azure': + agent_config = { + "model_type": ModelType.GPT_4O, + "model_config": ChatGPTConfig().as_dict(), + "model_platform": ModelPlatformType.AZURE, + } + else: + agent_config = { + "model_type": ModelType.GPT_4O, + "model_config": ChatGPTConfig().as_dict(), + "model_platform": ModelPlatformType.OPENAI, + # "model_name": '4o' + } elif model_type == '4o-mini': - agent_config = { - "model_type": ModelType.GPT_4O_MINI, - "model_config": ChatGPTConfig().as_dict(), - "model_platform": ModelPlatformType.OPENAI, - } + # Check if Azure platform is requested via environment variable + if model_platform_env == 'azure': + agent_config = { + "model_type": ModelType.GPT_4O_MINI, + "model_config": ChatGPTConfig().as_dict(), + "model_platform": ModelPlatformType.AZURE, + } + else: + agent_config = { + "model_type": ModelType.GPT_4O_MINI, + "model_config": ChatGPTConfig().as_dict(), + "model_platform": ModelPlatformType.OPENAI, + } elif model_type == 'o1': - agent_config = { - "model_type": ModelType.O1, - "model_config": ChatGPTConfig().as_dict(), - "model_platform": ModelPlatformType.OPENAI, - # "model_name": 'o1' - } + # Check if Azure platform is requested via environment variable + if model_platform_env == 'azure': + agent_config = { + "model_type": ModelType.O1, + "model_config": ChatGPTConfig().as_dict(), + "model_platform": ModelPlatformType.AZURE, + } + else: + agent_config = { + "model_type": ModelType.O1, + "model_config": ChatGPTConfig().as_dict(), + "model_platform": ModelPlatformType.OPENAI, + # "model_name": 'o1' + } elif model_type == 'o3': - agent_config = { - "model_type": ModelType.O3, - "model_config": ChatGPTConfig().as_dict(), - "model_platform": ModelPlatformType.OPENAI, - } + # Check if Azure platform is requested via environment variable + if model_platform_env == 'azure': + agent_config = { + "model_type": ModelType.O3, + "model_config": ChatGPTConfig().as_dict(), + "model_platform": ModelPlatformType.AZURE, + } + else: + agent_config = { + "model_type": ModelType.O3, + "model_config": ChatGPTConfig().as_dict(), + "model_platform": ModelPlatformType.OPENAI, + } elif model_type == 'vllm_qwen_vl': agent_config = { "model_type": "Qwen/Qwen2.5-VL-7B-Instruct", From 55ce07db7969448a33220e374357dafea440d7a1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 3 Jun 2025 06:15:09 +0000 Subject: [PATCH 5/7] Fix Azure OpenAI client initialization by removing invalid azure_deployment parameter Co-authored-by: MSDNAndi <6744335+MSDNAndi@users.noreply.github.com> --- camel/models/azure_openai_model.py | 1 - 1 file changed, 1 deletion(-) diff --git a/camel/models/azure_openai_model.py b/camel/models/azure_openai_model.py index c9a2ab7..f022b3e 100644 --- a/camel/models/azure_openai_model.py +++ b/camel/models/azure_openai_model.py @@ -88,7 +88,6 @@ def __init__( self._client = AzureOpenAI( azure_endpoint=str(self._url), - azure_deployment=self.azure_deployment_name, api_version=self.api_version, api_key=self._api_key, timeout=180, From 33574ad25d43bf9011a9e952da4127044de02c21 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 3 Jun 2025 06:31:10 +0000 Subject: [PATCH 6/7] Add MODEL_CONFIG environment variable support for custom model parameters Co-authored-by: MSDNAndi <6744335+MSDNAndi@users.noreply.github.com> --- utils/wei_utils.py | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/utils/wei_utils.py b/utils/wei_utils.py index 564b8d6..bdbb7f7 100644 --- a/utils/wei_utils.py +++ b/utils/wei_utils.py @@ -14,6 +14,7 @@ from PIL import Image import os import copy +import json import io from utils.src.utils import ppt_to_images from playwright.sync_api import sync_playwright @@ -23,6 +24,23 @@ from utils.pptx_utils import * from utils.critic_utils import * +def get_model_config_with_overrides(config_class): + """Get model config with custom overrides from MODEL_CONFIG environment variable""" + base_config = config_class().as_dict() + + # Check for custom model configuration in environment variable + model_config_env = os.environ.get('MODEL_CONFIG', '').strip() + if model_config_env: + try: + custom_config = json.loads(model_config_env) + # Merge custom config with base config + base_config.update(custom_config) + except json.JSONDecodeError as e: + print(f"Warning: Failed to parse MODEL_CONFIG environment variable: {e}") + print(f"Using default model configuration.") + + return base_config + def get_agent_config(model_type): # Check environment variables for platform override model_platform_env = os.environ.get('MODEL_PLATFORM', '').lower() @@ -31,7 +49,7 @@ def get_agent_config(model_type): if model_type == 'qwen': agent_config = { "model_type": ModelType.DEEPINFRA_QWEN_2_5_72B, - "model_config": QwenConfig().as_dict(), + "model_config": get_model_config_with_overrides(QwenConfig), "model_platform": ModelPlatformType.DEEPINFRA, } elif model_type == 'gemini': @@ -104,19 +122,19 @@ def get_agent_config(model_type): elif model_type == 'o3-mini': agent_config = { "model_type": ModelType.O3_MINI, - "model_config": ChatGPTConfig().as_dict(), + "model_config": get_model_config_with_overrides(ChatGPTConfig), "model_platform": ModelPlatformType.OPENAI, } elif model_type == 'gpt-4.1': agent_config = { "model_type": ModelType.GPT_4_1, - "model_config": ChatGPTConfig().as_dict(), + "model_config": get_model_config_with_overrides(ChatGPTConfig), "model_platform": ModelPlatformType.OPENAI, } elif model_type == 'gpt-4.1-mini': agent_config = { "model_type": ModelType.GPT_4_1_MINI, - "model_config": ChatGPTConfig().as_dict(), + "model_config": get_model_config_with_overrides(ChatGPTConfig), "model_platform": ModelPlatformType.OPENAI, } elif model_type == '4o': @@ -124,13 +142,13 @@ def get_agent_config(model_type): if model_platform_env == 'azure': agent_config = { "model_type": ModelType.GPT_4O, - "model_config": ChatGPTConfig().as_dict(), + "model_config": get_model_config_with_overrides(ChatGPTConfig), "model_platform": ModelPlatformType.AZURE, } else: agent_config = { "model_type": ModelType.GPT_4O, - "model_config": ChatGPTConfig().as_dict(), + "model_config": get_model_config_with_overrides(ChatGPTConfig), "model_platform": ModelPlatformType.OPENAI, # "model_name": '4o' } @@ -139,13 +157,13 @@ def get_agent_config(model_type): if model_platform_env == 'azure': agent_config = { "model_type": ModelType.GPT_4O_MINI, - "model_config": ChatGPTConfig().as_dict(), + "model_config": get_model_config_with_overrides(ChatGPTConfig), "model_platform": ModelPlatformType.AZURE, } else: agent_config = { "model_type": ModelType.GPT_4O_MINI, - "model_config": ChatGPTConfig().as_dict(), + "model_config": get_model_config_with_overrides(ChatGPTConfig), "model_platform": ModelPlatformType.OPENAI, } elif model_type == 'o1': @@ -153,13 +171,13 @@ def get_agent_config(model_type): if model_platform_env == 'azure': agent_config = { "model_type": ModelType.O1, - "model_config": ChatGPTConfig().as_dict(), + "model_config": get_model_config_with_overrides(ChatGPTConfig), "model_platform": ModelPlatformType.AZURE, } else: agent_config = { "model_type": ModelType.O1, - "model_config": ChatGPTConfig().as_dict(), + "model_config": get_model_config_with_overrides(ChatGPTConfig), "model_platform": ModelPlatformType.OPENAI, # "model_name": 'o1' } @@ -168,13 +186,13 @@ def get_agent_config(model_type): if model_platform_env == 'azure': agent_config = { "model_type": ModelType.O3, - "model_config": ChatGPTConfig().as_dict(), + "model_config": get_model_config_with_overrides(ChatGPTConfig), "model_platform": ModelPlatformType.AZURE, } else: agent_config = { "model_type": ModelType.O3, - "model_config": ChatGPTConfig().as_dict(), + "model_config": get_model_config_with_overrides(ChatGPTConfig), "model_platform": ModelPlatformType.OPENAI, } elif model_type == 'vllm_qwen_vl': From 83fd448e21382c00207caf223307f468bcb59cfb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 3 Jun 2025 10:50:16 +0000 Subject: [PATCH 7/7] Fix MODEL_CONFIG to use complete replacement instead of merging with defaults Co-authored-by: MSDNAndi <6744335+MSDNAndi@users.noreply.github.com> --- utils/wei_utils.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/utils/wei_utils.py b/utils/wei_utils.py index bdbb7f7..c430d03 100644 --- a/utils/wei_utils.py +++ b/utils/wei_utils.py @@ -26,20 +26,19 @@ def get_model_config_with_overrides(config_class): """Get model config with custom overrides from MODEL_CONFIG environment variable""" - base_config = config_class().as_dict() - # Check for custom model configuration in environment variable model_config_env = os.environ.get('MODEL_CONFIG', '').strip() if model_config_env: try: custom_config = json.loads(model_config_env) - # Merge custom config with base config - base_config.update(custom_config) + # Use only the custom config when present, don't merge with defaults + return custom_config except json.JSONDecodeError as e: print(f"Warning: Failed to parse MODEL_CONFIG environment variable: {e}") print(f"Using default model configuration.") - return base_config + # Only use default config if no MODEL_CONFIG is specified + return config_class().as_dict() def get_agent_config(model_type): # Check environment variables for platform override