Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions libs/lang/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export const messages: LanguageMessages ={
"address-error": "Please set your OpenAI proxy address in the plugin configuration.",
"generateAdvancedQuery-description": "The prompt for generating advanced query code in Logseq, which can be customized.",
"isTextQuery-description": "Whether to enable word selection query. When enabled, it will query other related blocks. Note that this may affect your usage experience.",
"isStreamingOutput-description": "Is stream output enabled for GPT? If enabled, there is a possibility of output failure."
"isStreamingOutput-description": "Is stream output enabled for GPT? If enabled, there is a possibility of output failure.",
"isHideThinking-description": "Whether to hide the thinking process when inserting blocks. If enabled, only the final result will be displayed."
},
"zh-CN": {
"openaiKey-description": "您的 OpenAI key. 您可从网站获取 https://platform.openai.com/account/api-keys.",
Expand All @@ -23,6 +24,7 @@ export const messages: LanguageMessages ={
"address-error": "请在插件配置中先设置您的 OpenAI 代理地址",
"generateAdvancedQuery-description": "生成 logseq 高级查询代码的提示词,可自行定义.",
"isTextQuery-description": "是否开启划词查询,当开启后,将会查询其他关联的块。注意可能会影响使用体验。",
"isStreamingOutput-description": "是否为 gpt 开启流式输出,如果开启,可能会出现输出失败的情况。"
"isStreamingOutput-description": "是否为 gpt 开启流式输出,如果开启,可能会出现输出失败的情况。",
"isHideThinking-description": "插入 block 时是否隐藏思考过程。如果开启,仅显示最终结果。"
},
}
25 changes: 23 additions & 2 deletions libs/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ export class OpenAI {

public chat = async(
messages: OpenAIMessage[],
is_stream: boolean = true
is_stream = true
) => {
try {
const url: string = `${this.address}/v1/chat/completions`;
const url = `${this.address}/v1/chat/completions`;
const response = await fetch(`${url}`, {
method: 'POST',
headers: {
Expand Down Expand Up @@ -69,4 +69,25 @@ export class OpenAI {
throw new Error(err.message);
}
}

public getModels = async() => {
try {
const url = `${this.address}/v1/models`;
const response = await fetch(`${url}`, {
method: 'GET',
headers: {
'Authorization': `Bearer ${this.apiKey}`
}
});

const data = await response.json();
if (response.ok) {
return data.data.map((model: any) => model.id);
} else {
throw new Error(data.message);
}
} catch (err: any) {
throw new Error(err.message);
}
}
}
Loading