From c973f6cd3ae29029551acf0156f057bd6ab458b0 Mon Sep 17 00:00:00 2001 From: rezawr Date: Fri, 22 Nov 2024 09:21:39 +0700 Subject: [PATCH 1/2] add encoding to avoid error in windows --- py_zerox/pyzerox/core/zerox.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py_zerox/pyzerox/core/zerox.py b/py_zerox/pyzerox/core/zerox.py index 70c21086..c17bba8d 100644 --- a/py_zerox/pyzerox/core/zerox.py +++ b/py_zerox/pyzerox/core/zerox.py @@ -165,7 +165,7 @@ async def zerox( # Write the aggregated markdown to a file if output_dir: result_file_path = os.path.join(output_dir, f"{file_name}.md") - async with aiofiles.open(result_file_path, "w") as f: + async with aiofiles.open(result_file_path, "w", encoding="utf-8") as f: await f.write("\n\n".join(aggregated_markdown)) # Cleanup the downloaded PDF file From f799e1b1cc308ef4df0dc0822b80aee0e8ff85b8 Mon Sep 17 00:00:00 2001 From: reza Date: Fri, 16 May 2025 14:52:56 +0700 Subject: [PATCH 2/2] feat: add base url to openai so local llm could be implemented --- node-zerox/src/models/index.ts | 2 +- node-zerox/src/models/openAI.ts | 4 +++- node-zerox/src/types.ts | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/node-zerox/src/models/index.ts b/node-zerox/src/models/index.ts index 193042e8..479f7dd3 100644 --- a/node-zerox/src/models/index.ts +++ b/node-zerox/src/models/index.ts @@ -42,7 +42,7 @@ const isGoogleCredentials = ( const isOpenAICredentials = ( credentials: any ): credentials is OpenAICredentials => { - return credentials && typeof credentials.apiKey === "string"; + return credentials && typeof credentials.apiKey === "string" && credentials.baseUrl; }; export const createModel = ({ diff --git a/node-zerox/src/models/openAI.ts b/node-zerox/src/models/openAI.ts index a2b65ec2..1b5bf053 100644 --- a/node-zerox/src/models/openAI.ts +++ b/node-zerox/src/models/openAI.ts @@ -22,6 +22,7 @@ import fs from "fs-extra"; export default class OpenAIModel implements ModelInterface { private apiKey: string; private model: string; + private baseUrl: string; private llmParams?: Partial; constructor( @@ -30,6 +31,7 @@ export default class OpenAIModel implements ModelInterface { llmParams?: Partial ) { this.apiKey = credentials.apiKey; + this.baseUrl = credentials.baseUrl ?? 'https://api.openai.com/v1' this.model = model; this.llmParams = llmParams; } @@ -121,7 +123,7 @@ export default class OpenAIModel implements ModelInterface { try { const response = await axios.post( - "https://api.openai.com/v1/chat/completions", + `${this.baseUrl}/chat/completions`, { messages, model: this.model, diff --git a/node-zerox/src/types.ts b/node-zerox/src/types.ts index 2f466863..3f7f3a1b 100644 --- a/node-zerox/src/types.ts +++ b/node-zerox/src/types.ts @@ -70,6 +70,7 @@ export interface GoogleCredentials { } export interface OpenAICredentials { + baseUrl: string; apiKey: string; }