Skip to content

Commit 7ac2509

Browse files
authored
refactor: use gpt-4.1 as the default translate model (#7389)
1 parent ec17863 commit 7ac2509

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

.changeset/funny-eels-wonder.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"@logto/translate": patch
3+
---
4+
5+
allow empty file when syncing keys
6+
7+
The previous behavior was to throw an error if any of the `import` files was empty. This caused issues when we needed to remove files and resync keys, as it would lead to manual intervention to delete the `import` clauses.
8+
9+
With this change, missing or empty `import` files are treated as empty by default, allowing the sync process to continue without errors.

.changeset/moody-turtles-bake.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@logto/translate": patch
3+
---
4+
5+
use `gpt-4.1` as the default model
6+
7+
As it's newer and cheaper than `gpt-4o-2024-08-06`.

packages/translate/src/openai.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
} from './utils.js';
2020

2121
// The full list of OPENAI model can be found at https://platform.openai.com/docs/models.
22-
export const getModel = () => process.env.OPENAI_MODEL_NAME ?? 'gpt-4o-2024-08-06';
22+
export const getModel = () => process.env.OPENAI_MODEL_NAME ?? 'gpt-4.1';
2323

2424
export const createOpenaiApi = () => {
2525
const proxy = getProxy();

packages/translate/src/sync-keys/utils.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { readFileSync, existsSync } from 'node:fs';
1+
import { readFileSync, existsSync, statSync } from 'node:fs';
22
import fs from 'node:fs/promises';
33
import path from 'node:path';
44

5-
import { tryThat } from '@silverhand/essentials';
5+
import { trySafe, tryThat } from '@silverhand/essentials';
66
import ts from 'typescript';
77

88
import { consoleLog } from '../utils.js';
@@ -94,6 +94,12 @@ type ParsedTuple = readonly [NestedPhraseObject, FileStructure];
9494
*
9595
*/
9696
export const parseLocaleFiles = (filePath: string): ParsedTuple => {
97+
const fileStat = trySafe(() => statSync(filePath));
98+
99+
if (!fileStat?.isFile()) {
100+
return [{}, {}];
101+
}
102+
97103
const content = readFileSync(filePath, 'utf8');
98104
const ast = ts.createSourceFile(filePath, content, ts.ScriptTarget.Latest, true);
99105
const importIdentifierPath = new Map<string, string>();

0 commit comments

Comments
 (0)