Skip to content

Commit

Permalink
兼容Azure OpenAI
Browse files Browse the repository at this point in the history
  • Loading branch information
CosmosShadow committed Jul 2, 2024
1 parent e1fb8f0 commit 68826e5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ parse pdf file to markdown file, and return markdown content and all image paths

- **base_url**: OpenAI Base URL. (optional). If not provided, Use OPENAI_BASE_URL environment variable.

- **model**: OpenAI Vision Large Model, default is 'gpt-4o'. You also can use [qwen-vl-max](https://help.aliyun.com/zh/dashscope/developer-reference/vl-plus-quick-start), [GLM-4V](https://open.bigmodel.cn/dev/api#glm-4v) by change the `OPENAI_BASE_URL` or specify `base_url`.
- **model**: OpenAI Vision Large Model, default is 'gpt-4o'.
You also can use [qwen-vl-max](https://help.aliyun.com/zh/dashscope/developer-reference/vl-plus-quick-start) (not tested yet)
[GLM-4V](https://open.bigmodel.cn/dev/api#glm-4v) by change the `OPENAI_BASE_URL` or specify `base_url`.
Also you can use Azure OpenAI by specify `base_url` to `https://xxxx.openai.azure.com/`, api_key is Azure API Key, model is like 'azure_xxxx' where xxxx is the deployed model name (not openai model name)

- **verbose**: verbose mode

Expand Down
7 changes: 6 additions & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ print(content)

- **base_url**:OpenAI 基本 URL。(可选)。如果未提供,则使用 OPENAI_BASE_URL 环境变量。

- **model**:OpenAI API格式的多模态大模型,默认为 “gpt-4o”。如果您需要使用其他模型,例如 [qwen-vl-max](https://help.aliyun.com/zh/dashscope/developer-reference/vl-plus-quick-start), [GLM-4V](https://open.bigmodel.cn/dev/api#glm-4v), 可以通过修改环境变量 `OPENAI_BASE_URL` 或 指定API参数 `base_url` 来使用。
- **model**:OpenAI API格式的多模态大模型,默认为 “gpt-4o”。
如果您需要使用其他模型,例如 [qwen-vl-max](https://help.aliyun.com/zh/dashscope/developer-reference/vl-plus-quick-start) (尚未测试)

[GLM-4V](https://open.bigmodel.cn/dev/api#glm-4v), 可以通过修改环境变量 `OPENAI_BASE_URL` 或 指定API参数 `base_url` 来使用。 (已经测试)

您也可以通过将 `base_url` 指定为 `https://xxxx.openai.azure.com/` 来使用 Azure OpenAI,api_key 是 Azure API 密钥,模型类似于 'azure_xxxx',其中 xxxx 是部署的模型名称(不是 openai 模型名称)(已经测试)

- **verbose**:详细模式

Expand Down
20 changes: 18 additions & 2 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,23 @@ def test_use_env():
print(image_paths)
# also output_dir/output.md is generated

def test_azure():
from gptpdf import parse_pdf
api_key = '8ef0b4df45e444079cd5a4xxxxx' # Azure API Key
base_url = 'https://xxx.openai.azure.com/' # Azure API Base URL
model = 'azure_xxxx' # azure_ with deploy ID name (not open ai model name), e.g. azure_cpgpt4

pdf_path = '../examples/attention_is_all_you_need.pdf'
output_dir = '../examples/attention_is_all_you_need/'
# Use OPENAI_API_KEY and OPENAI_API_BASE from environment variables
content, image_paths = parse_pdf(pdf_path, output_dir=output_dir, api_key=api_key, base_url=base_url, model=model, verbose=True)
print(content)
print(image_paths)




if __name__ == '__main__':
test_use_api_key()
# test_use_env()
# test_use_api_key()
# test_use_env()
test_azure()

0 comments on commit 68826e5

Please sign in to comment.