Refactor: Generalize API endpoints to support OpenAI-compatible models via .env#157
Open
3985618547-debug wants to merge 8 commits intoVectifyAI:mainfrom
Open
Refactor: Generalize API endpoints to support OpenAI-compatible models via .env#1573985618547-debug wants to merge 8 commits intoVectifyAI:mainfrom
3985618547-debug wants to merge 8 commits intoVectifyAI:mainfrom
Conversation
从环境变量读取 OPENAI_MODEL 和 OPENAI_BASE_URL,并设置了默认值 更新了三个 API 调用函数(ChatGPT_API_with_finish_reason、ChatGPT_API、ChatGPT_API_async),让它们使用自定义的 base_url
添加了 dotenv 加载支持 将 --model 参数的默认值改为从环境变量的 OPENAI_MODEL 读取
|
Haven't you merged it into the main branch yet? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR refactors the API calling logic to be model-agnostic. By generalizing the ChatGPT-specific naming conventions to a standard OpenAI format and moving configurations to
.env, the project can now seamlessly support any OpenAI-compatible API services (such as DeepSeek).Detailed Changes
1. Configuration (
.env)CHATGPT_API_KEYtoOPENAI_API_KEY.OPENAI_MODEL(defaults togpt-4o-2024-11-20) andOPENAI_BASE_URL(defaults tohttps://api.openai.com/v1).2. Core Utilities (
pageindex/utils.py)ChatGPT_API_with_finish_reason→OpenAI_API_with_finish_reasonChatGPT_API→OpenAI_APIChatGPT_API_async→OpenAI_API_asyncbase_urlparameter fetched from the.envfile.3. PDF Main Workflow (
page_index.py)ChatGPT_API*calls withOpenAI_API*across the entire PDF parsing and TOC generation workflow (e.g.,check_title_appearance,toc_detector_single_page,extract_toc_content,toc_transformer, etc.).4. Markdown Workflow & Entry Scripts (
run_pageindex.py,pageindex/page_index_md.py)load_dotenv()at the top of the entry scripts to ensure environment variables are correctly loaded.--modelargument default value now correctly falls back toos.getenv('OPENAI_MODEL').5. Documentation (
README.md).envsetup examples to reflect the new variable names.Compatibility & Migration Guide
Behavioral Change: Keys, models, and base URLs are no longer hardcoded.
Migration: To use a third-party compatible API (like DeepSeek), simply update the
.envfile: