Skip to content

Commit

Permalink
Update JSON response format and enhance session management in Vocabul…
Browse files Browse the repository at this point in the history
…aryRepository
  • Loading branch information
chanwit-y committed Nov 26, 2024
1 parent 7537f33 commit 30fc132
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion libs/api/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
],
Expand Down
4 changes: 3 additions & 1 deletion libs/mod/vocabulary/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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("*")
Expand All @@ -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: "" }])
Expand Down
1 change: 1 addition & 0 deletions libs/mod/vocabulary/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export class VocabularyService implements IVocabularyService {
public async findByWord(word: string): Promise<TVocabulary[]> {
try {
const v = await this._repo.findByWord(word);
// console.log("find by word",v);
return v;
} catch (error) {
console.error(error);
Expand Down

0 comments on commit 30fc132

Please sign in to comment.