From 30fc132f3f8f86bc4c45adeebdd68e6fd009a03f Mon Sep 17 00:00:00 2001 From: cy Date: Tue, 26 Nov 2024 11:23:25 +0700 Subject: [PATCH] Update JSON response format and enhance session management in VocabularyRepository --- libs/api/openai.ts | 2 +- libs/mod/vocabulary/repository.ts | 4 +++- libs/mod/vocabulary/service.ts | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/libs/api/openai.ts b/libs/api/openai.ts index b3ec401..cf84617 100644 --- a/libs/api/openai.ts +++ b/libs/api/openai.ts @@ -20,7 +20,7 @@ export class OpenAIAPI { role: "user", content: [ { - text: `ตอบกลับเป็น json\n{\n "word": "${word}",\n "thai": "...", //แปลคำว่า ${word} เป็นภาษาไทยของคำว่า \n "english": "...", //คำอ่านและการออกเสียง ${word} เป็นภาษาไทย\n "types": [...], //ประเภทของคำของคำว่า ${word}\n "examples": [...], //ตัวอย่างการใช้คำว่า ${word} ในประเภทคำต่างๆ\n}`, + text: `ตอบกลับเป็น json\n{\n "word": "${word}",\n "thai": "...", //แปลคำว่า ${word} เป็นภาษาไทยของคำว่า \n "english": "...", //คำอ่านและการออกเสียง ${word} เป็นภาษาไทย\n "types": [...], //ประเภทของคำของคำว่า ${word}\n "examples": [...], //ตัวอย่างการใช้คำว่า ${word} ในประเภทคำต่างๆ แค่ sentence เท่านั้น\n}`, type: "text", }, ], diff --git a/libs/mod/vocabulary/repository.ts b/libs/mod/vocabulary/repository.ts index f44a661..4c9993f 100644 --- a/libs/mod/vocabulary/repository.ts +++ b/libs/mod/vocabulary/repository.ts @@ -56,7 +56,9 @@ export class VocabularyRepository implements IVocabularyRepository { } public async findByWord(word: string) { + console.log("find by word", `${word}`); try { + await this._db.auth.refreshSession(); const { data, error } = await this._db .from(TableName) .select("*") @@ -74,7 +76,7 @@ export class VocabularyRepository implements IVocabularyRepository { public async insert(v: TVocabulary) { try { - await this._db.auth.reauthenticate(); + await this._db.auth.refreshSession(); const { data, error } = await this._db .from(TableName) .insert([{ ...v, type: "", remark: "" }]) diff --git a/libs/mod/vocabulary/service.ts b/libs/mod/vocabulary/service.ts index 5bace4c..183a46d 100644 --- a/libs/mod/vocabulary/service.ts +++ b/libs/mod/vocabulary/service.ts @@ -58,6 +58,7 @@ export class VocabularyService implements IVocabularyService { public async findByWord(word: string): Promise { try { const v = await this._repo.findByWord(word); + // console.log("find by word",v); return v; } catch (error) { console.error(error);