mirror of
https://github.com/cosmicoptima/loom.git
synced 2026-07-22 07:40:25 +00:00
Compare commits
5 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
afbb3519f1 | ||
|
|
53ef92e076 | ||
|
|
518a90f587 | ||
|
|
93599ed192 | ||
|
|
788d91b2b1 |
3 changed files with 276 additions and 140 deletions
412
main.ts
412
main.ts
|
|
@ -113,18 +113,6 @@ export default class LoomPlugin extends Plugin {
|
||||||
return callback(file);
|
return callback(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
saveAndRender() {
|
|
||||||
this.save();
|
|
||||||
|
|
||||||
if (this.rendering) return;
|
|
||||||
this.rendering = true;
|
|
||||||
|
|
||||||
this.renderLoomViews();
|
|
||||||
this.renderLoomSiblingsViews();
|
|
||||||
|
|
||||||
this.rendering = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
thenSaveAndRender(callback: () => void) {
|
thenSaveAndRender(callback: () => void) {
|
||||||
callback();
|
callback();
|
||||||
this.saveAndRender();
|
this.saveAndRender();
|
||||||
|
|
@ -136,20 +124,6 @@ export default class LoomPlugin extends Plugin {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
renderLoomViews() {
|
|
||||||
const views = this.app.workspace
|
|
||||||
.getLeavesOfType("loom")
|
|
||||||
.map((leaf) => leaf.view) as LoomView[];
|
|
||||||
views.forEach((view) => view.render());
|
|
||||||
}
|
|
||||||
|
|
||||||
renderLoomSiblingsViews() {
|
|
||||||
const views = this.app.workspace
|
|
||||||
.getLeavesOfType("loom-siblings")
|
|
||||||
.map((leaf) => leaf.view) as LoomSiblingsView[];
|
|
||||||
views.forEach((view) => view.render());
|
|
||||||
}
|
|
||||||
|
|
||||||
initializeProviders() {
|
initializeProviders() {
|
||||||
const preset = getPreset(this.settings);
|
const preset = getPreset(this.settings);
|
||||||
if (preset === undefined) return;
|
if (preset === undefined) return;
|
||||||
|
|
@ -815,6 +789,7 @@ export default class LoomPlugin extends Plugin {
|
||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
// this.editor.setCursor(cursor);
|
// this.editor.setCursor(cursor);
|
||||||
|
this.saveAndRender(); // Add explicit view refresh
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
@ -1219,8 +1194,7 @@ export default class LoomPlugin extends Plugin {
|
||||||
};
|
};
|
||||||
plugin.update();
|
plugin.update();
|
||||||
|
|
||||||
this.renderLoomViews();
|
this.refreshViews();
|
||||||
this.renderLoomSiblingsViews();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.registerEvent(
|
this.registerEvent(
|
||||||
|
|
@ -1237,8 +1211,7 @@ export default class LoomPlugin extends Plugin {
|
||||||
|
|
||||||
this.registerEvent(
|
this.registerEvent(
|
||||||
this.app.workspace.on("resize", () => {
|
this.app.workspace.on("resize", () => {
|
||||||
this.renderLoomViews();
|
this.refreshViews();
|
||||||
this.renderLoomSiblingsViews();
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -1294,7 +1267,7 @@ export default class LoomPlugin extends Plugin {
|
||||||
this.state[file.path].generating = rootNode;
|
this.state[file.path].generating = rootNode;
|
||||||
|
|
||||||
// show the "Generating..." indicator in the loom view
|
// show the "Generating..." indicator in the loom view
|
||||||
this.renderLoomViews();
|
this.refreshViews();
|
||||||
|
|
||||||
let prompt = `${this.settings.prepend}${this.fullText(file, rootNode)}`;
|
let prompt = `${this.settings.prepend}${this.fullText(file, rootNode)}`;
|
||||||
|
|
||||||
|
|
@ -1401,6 +1374,19 @@ export default class LoomPlugin extends Plugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
async completeCohere(prompt: string) {
|
async completeCohere(prompt: string) {
|
||||||
|
if (this.settings.logApiCalls) {
|
||||||
|
console.log("Cohere request:", {
|
||||||
|
model: getPreset(this.settings).model,
|
||||||
|
prompt,
|
||||||
|
max_tokens: this.settings.maxTokens,
|
||||||
|
num_generations: this.settings.n,
|
||||||
|
temperature: this.settings.temperature,
|
||||||
|
p: this.settings.topP,
|
||||||
|
frequency_penalty: this.settings.frequencyPenalty,
|
||||||
|
presence_penalty: this.settings.presencePenalty,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const tokens = (await cohere.tokenize({ text: prompt })).body.token_strings;
|
const tokens = (await cohere.tokenize({ text: prompt })).body.token_strings;
|
||||||
prompt = tokens.slice(-getPreset(this.settings).contextLength).join("");
|
prompt = tokens.slice(-getPreset(this.settings).contextLength).join("");
|
||||||
|
|
||||||
|
|
@ -1415,6 +1401,10 @@ export default class LoomPlugin extends Plugin {
|
||||||
presence_penalty: this.settings.presencePenalty,
|
presence_penalty: this.settings.presencePenalty,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (this.settings.logApiCalls) {
|
||||||
|
console.log("Cohere response:", response);
|
||||||
|
}
|
||||||
|
|
||||||
const result: CompletionResult =
|
const result: CompletionResult =
|
||||||
response.statusCode === 200
|
response.statusCode === 200
|
||||||
? {
|
? {
|
||||||
|
|
@ -1423,17 +1413,30 @@ export default class LoomPlugin extends Plugin {
|
||||||
(generation) => generation.text
|
(generation) => generation.text
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
:
|
: {
|
||||||
{
|
|
||||||
ok: false,
|
ok: false,
|
||||||
status: response.statusCode!,
|
status: response.statusCode!,
|
||||||
// @ts-expect-error
|
message: "",
|
||||||
message: response.body.message,
|
|
||||||
};
|
};
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
async completeTextSynth(prompt: string) {
|
async completeTextSynth(prompt: string) {
|
||||||
|
const body = {
|
||||||
|
prompt,
|
||||||
|
max_tokens: this.settings.maxTokens,
|
||||||
|
best_of: this.settings.bestOf,
|
||||||
|
n: this.settings.n,
|
||||||
|
temperature: this.settings.temperature,
|
||||||
|
top_p: this.settings.topP,
|
||||||
|
frequency_penalty: this.settings.frequencyPenalty,
|
||||||
|
presence_penalty: this.settings.presencePenalty,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (this.settings.logApiCalls) {
|
||||||
|
console.log("TextSynth request:", body);
|
||||||
|
}
|
||||||
|
|
||||||
const response = await requestUrl({
|
const response = await requestUrl({
|
||||||
url: `https://api.textsynth.com/v1/engines/${
|
url: `https://api.textsynth.com/v1/engines/${
|
||||||
getPreset(this.settings).model
|
getPreset(this.settings).model
|
||||||
|
|
@ -1444,18 +1447,13 @@ export default class LoomPlugin extends Plugin {
|
||||||
Authorization: `Bearer ${getPreset(this.settings).apiKey}`,
|
Authorization: `Bearer ${getPreset(this.settings).apiKey}`,
|
||||||
},
|
},
|
||||||
throw: false,
|
throw: false,
|
||||||
body: JSON.stringify({
|
body: JSON.stringify(body),
|
||||||
prompt,
|
|
||||||
max_tokens: this.settings.maxTokens,
|
|
||||||
best_of: this.settings.bestOf,
|
|
||||||
n: this.settings.n,
|
|
||||||
temperature: this.settings.temperature,
|
|
||||||
top_p: this.settings.topP,
|
|
||||||
frequency_penalty: this.settings.frequencyPenalty,
|
|
||||||
presence_penalty: this.settings.presencePenalty,
|
|
||||||
}),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (this.settings.logApiCalls) {
|
||||||
|
console.log("TextSynth response:", response);
|
||||||
|
}
|
||||||
|
|
||||||
let result: CompletionResult;
|
let result: CompletionResult;
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
const completions =
|
const completions =
|
||||||
|
|
@ -1465,7 +1463,7 @@ export default class LoomPlugin extends Plugin {
|
||||||
result = {
|
result = {
|
||||||
ok: false,
|
ok: false,
|
||||||
status: response.status,
|
status: response.status,
|
||||||
message: response.json.error,
|
message: response.json.error || "Unknown error",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
@ -1479,6 +1477,15 @@ export default class LoomPlugin extends Plugin {
|
||||||
"gpt-3.5-turbo",
|
"gpt-3.5-turbo",
|
||||||
"gpt-3.5-turbo-0301",
|
"gpt-3.5-turbo-0301",
|
||||||
"gpt-4-base",
|
"gpt-4-base",
|
||||||
|
// TODO: llama 3.1 has "28k additional multilingual tokens", so cl100k is not exactly right
|
||||||
|
"meta-llama/llama-3.1-8b",
|
||||||
|
"meta-llama/llama-3.1-70b",
|
||||||
|
"meta-llama/llama-3.1-405b",
|
||||||
|
"meta-llama/llama-3.1-8b-instruct",
|
||||||
|
"meta-llama/llama-3.1-70b-instruct",
|
||||||
|
"meta-llama/llama-3.1-405b-instruct",
|
||||||
|
"meta-llama/Meta-Llama-3.1-405B",
|
||||||
|
"meta-llama/Meta-Llama-3.1-405B-FP8",
|
||||||
];
|
];
|
||||||
const p50kModels = [
|
const p50kModels = [
|
||||||
"text-davinci-003",
|
"text-davinci-003",
|
||||||
|
|
@ -1519,6 +1526,7 @@ export default class LoomPlugin extends Plugin {
|
||||||
if (!url.endsWith("/")) url += "/";
|
if (!url.endsWith("/")) url += "/";
|
||||||
url = url.replace(/v1\//, "");
|
url = url.replace(/v1\//, "");
|
||||||
url += "v1/completions";
|
url += "v1/completions";
|
||||||
|
|
||||||
let body: any = {
|
let body: any = {
|
||||||
prompt,
|
prompt,
|
||||||
model: getPreset(this.settings).model,
|
model: getPreset(this.settings).model,
|
||||||
|
|
@ -1526,16 +1534,22 @@ export default class LoomPlugin extends Plugin {
|
||||||
n: this.settings.n,
|
n: this.settings.n,
|
||||||
temperature: this.settings.temperature,
|
temperature: this.settings.temperature,
|
||||||
top_p: this.settings.topP,
|
top_p: this.settings.topP,
|
||||||
best_of:
|
|
||||||
this.settings.bestOf > this.settings.n
|
|
||||||
? this.settings.bestOf
|
|
||||||
: this.settings.n,
|
|
||||||
};
|
};
|
||||||
|
if (this.settings.bestOf > this.settings.n) {
|
||||||
|
body.best_of = this.settings.bestOf;
|
||||||
|
}
|
||||||
if (this.settings.frequencyPenalty !== 0)
|
if (this.settings.frequencyPenalty !== 0)
|
||||||
body.frequency_penalty = this.settings.frequencyPenalty;
|
body.frequency_penalty = this.settings.frequencyPenalty;
|
||||||
if (this.settings.presencePenalty !== 0)
|
if (this.settings.presencePenalty !== 0)
|
||||||
body.presence_penalty = this.settings.presencePenalty;
|
body.presence_penalty = this.settings.presencePenalty;
|
||||||
|
|
||||||
|
if (this.settings.logApiCalls) {
|
||||||
|
console.log("OpenAI-compatible API request:", {
|
||||||
|
url,
|
||||||
|
body
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const response = await requestUrl({
|
const response = await requestUrl({
|
||||||
url,
|
url,
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
|
@ -1547,6 +1561,10 @@ export default class LoomPlugin extends Plugin {
|
||||||
body: JSON.stringify(body),
|
body: JSON.stringify(body),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (this.settings.logApiCalls) {
|
||||||
|
console.log("OpenAI-compatible API response:", response);
|
||||||
|
}
|
||||||
|
|
||||||
const result: CompletionResult =
|
const result: CompletionResult =
|
||||||
response.status === 200
|
response.status === 200
|
||||||
? {
|
? {
|
||||||
|
|
@ -1555,7 +1573,16 @@ export default class LoomPlugin extends Plugin {
|
||||||
(choice: any) => choice.text
|
(choice: any) => choice.text
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
: { ok: false, status: response.status, message: "" };
|
: {
|
||||||
|
ok: false,
|
||||||
|
status: response.status,
|
||||||
|
message: response.json?.error?.message || "Unknown error"
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!result.ok && this.settings.logApiCalls) {
|
||||||
|
console.error("OpenAI-compatible error:", response);
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1580,6 +1607,10 @@ export default class LoomPlugin extends Plugin {
|
||||||
if (this.settings.presencePenalty !== 0)
|
if (this.settings.presencePenalty !== 0)
|
||||||
body.presence_penalty = this.settings.presencePenalty;
|
body.presence_penalty = this.settings.presencePenalty;
|
||||||
|
|
||||||
|
if (this.settings.logApiCalls) {
|
||||||
|
console.log("OpenRouter request:", body);
|
||||||
|
}
|
||||||
|
|
||||||
const requests = Array(this.settings.n).fill(null).map(() =>
|
const requests = Array(this.settings.n).fill(null).map(() =>
|
||||||
requestUrl({
|
requestUrl({
|
||||||
url: "https://openrouter.ai/api/v1/completions",
|
url: "https://openrouter.ai/api/v1/completions",
|
||||||
|
|
@ -1597,42 +1628,58 @@ export default class LoomPlugin extends Plugin {
|
||||||
|
|
||||||
const responses = await Promise.all(requests);
|
const responses = await Promise.all(requests);
|
||||||
|
|
||||||
const result: CompletionResult = responses.every(response => response.status === 200)
|
if (this.settings.logApiCalls) {
|
||||||
|
console.log("OpenRouter responses:", responses);
|
||||||
|
}
|
||||||
|
|
||||||
|
const result: CompletionResult = responses.every(response => !response.json.hasOwnProperty('error'))
|
||||||
? {
|
? {
|
||||||
ok: true,
|
ok: true,
|
||||||
completions: responses.map(response => response.json.choices[0].text),
|
completions: responses.map(response => response.json.choices[0].text),
|
||||||
}
|
}
|
||||||
: {
|
: {
|
||||||
ok: false,
|
ok: false,
|
||||||
status: responses[0].status,
|
status: responses[0].json.error.code,
|
||||||
message: responses[0].text,
|
message: responses[0].json.error.message,
|
||||||
};
|
};
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
async completeOpenAI(prompt: string) {
|
async completeOpenAI(prompt: string) {
|
||||||
prompt = this.trimOpenAIPrompt(prompt);
|
prompt = this.trimOpenAIPrompt(prompt);
|
||||||
|
const body = {
|
||||||
|
model: getPreset(this.settings).model,
|
||||||
|
prompt,
|
||||||
|
max_tokens: this.settings.maxTokens,
|
||||||
|
n: this.settings.n,
|
||||||
|
temperature: this.settings.temperature,
|
||||||
|
top_p: this.settings.topP,
|
||||||
|
frequency_penalty: this.settings.frequencyPenalty,
|
||||||
|
presence_penalty: this.settings.presencePenalty,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (this.settings.logApiCalls) {
|
||||||
|
console.log("OpenAI request:", body);
|
||||||
|
}
|
||||||
|
|
||||||
let result: CompletionResult;
|
let result: CompletionResult;
|
||||||
try {
|
try {
|
||||||
const response = await this.openai.createCompletion({
|
const response = await this.openai.createCompletion(body);
|
||||||
model: getPreset(this.settings).model,
|
if (this.settings.logApiCalls) {
|
||||||
prompt,
|
console.log("OpenAI response:", response);
|
||||||
max_tokens: this.settings.maxTokens,
|
}
|
||||||
n: this.settings.n,
|
|
||||||
temperature: this.settings.temperature,
|
|
||||||
top_p: this.settings.topP,
|
|
||||||
frequency_penalty: this.settings.frequencyPenalty,
|
|
||||||
presence_penalty: this.settings.presencePenalty,
|
|
||||||
});
|
|
||||||
result = {
|
result = {
|
||||||
ok: true,
|
ok: true,
|
||||||
completions: response.data.choices.map((choice) => choice.text || ""),
|
completions: response.data.choices.map((choice) => choice.text || ""),
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
if (this.settings.logApiCalls) {
|
||||||
|
console.error("OpenAI error:", e);
|
||||||
|
}
|
||||||
result = {
|
result = {
|
||||||
ok: false,
|
ok: false,
|
||||||
status: e.response.status,
|
status: e.response.status,
|
||||||
message: e.response.data.error.message,
|
message: e.response.data.error.message || "Unknown error",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
@ -1640,18 +1687,27 @@ export default class LoomPlugin extends Plugin {
|
||||||
|
|
||||||
async completeOpenAIChat(prompt: string) {
|
async completeOpenAIChat(prompt: string) {
|
||||||
prompt = this.trimOpenAIPrompt(prompt);
|
prompt = this.trimOpenAIPrompt(prompt);
|
||||||
|
const body = {
|
||||||
|
model: getPreset(this.settings).model,
|
||||||
|
messages: [{ role: "assistant" as const, content: prompt }],
|
||||||
|
max_tokens: this.settings.maxTokens,
|
||||||
|
n: this.settings.n,
|
||||||
|
temperature: this.settings.temperature,
|
||||||
|
top_p: this.settings.topP,
|
||||||
|
frequency_penalty: this.settings.frequencyPenalty,
|
||||||
|
presence_penalty: this.settings.presencePenalty,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (this.settings.logApiCalls) {
|
||||||
|
console.log("OpenAI Chat request:", body);
|
||||||
|
}
|
||||||
|
|
||||||
let result: CompletionResult;
|
let result: CompletionResult;
|
||||||
try {
|
try {
|
||||||
const response = await this.openai.createChatCompletion({
|
const response = await this.openai.createChatCompletion(body);
|
||||||
model: getPreset(this.settings).model,
|
if (this.settings.logApiCalls) {
|
||||||
messages: [{ role: "assistant", content: prompt }],
|
console.log("OpenAI Chat response:", response);
|
||||||
max_tokens: this.settings.maxTokens,
|
}
|
||||||
n: this.settings.n,
|
|
||||||
temperature: this.settings.temperature,
|
|
||||||
top_p: this.settings.topP,
|
|
||||||
frequency_penalty: this.settings.frequencyPenalty,
|
|
||||||
presence_penalty: this.settings.presencePenalty,
|
|
||||||
});
|
|
||||||
result = {
|
result = {
|
||||||
ok: true,
|
ok: true,
|
||||||
completions: response.data.choices.map(
|
completions: response.data.choices.map(
|
||||||
|
|
@ -1659,10 +1715,13 @@ export default class LoomPlugin extends Plugin {
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
if (this.settings.logApiCalls) {
|
||||||
|
console.error("OpenAI Chat error:", e);
|
||||||
|
}
|
||||||
result = {
|
result = {
|
||||||
ok: false,
|
ok: false,
|
||||||
status: e.response.status,
|
status: e.response.status,
|
||||||
message: e.response.data.error.message,
|
message: e.response.data.error.message || "Unknown error",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
@ -1670,27 +1729,39 @@ export default class LoomPlugin extends Plugin {
|
||||||
|
|
||||||
async completeAzure(prompt: string) {
|
async completeAzure(prompt: string) {
|
||||||
prompt = this.trimOpenAIPrompt(prompt);
|
prompt = this.trimOpenAIPrompt(prompt);
|
||||||
|
const body = {
|
||||||
|
model: getPreset(this.settings).model,
|
||||||
|
prompt,
|
||||||
|
max_tokens: this.settings.maxTokens,
|
||||||
|
n: this.settings.n,
|
||||||
|
temperature: this.settings.temperature,
|
||||||
|
top_p: this.settings.topP,
|
||||||
|
frequency_penalty: this.settings.frequencyPenalty,
|
||||||
|
presence_penalty: this.settings.presencePenalty,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (this.settings.logApiCalls) {
|
||||||
|
console.log("Azure request:", body);
|
||||||
|
}
|
||||||
|
|
||||||
let result: CompletionResult;
|
let result: CompletionResult;
|
||||||
try {
|
try {
|
||||||
const response = await this.azure.createCompletion({
|
const response = await this.azure.createCompletion(body);
|
||||||
model: getPreset(this.settings).model,
|
if (this.settings.logApiCalls) {
|
||||||
prompt,
|
console.log("Azure response:", response);
|
||||||
max_tokens: this.settings.maxTokens,
|
}
|
||||||
n: this.settings.n,
|
|
||||||
temperature: this.settings.temperature,
|
|
||||||
top_p: this.settings.topP,
|
|
||||||
frequency_penalty: this.settings.frequencyPenalty,
|
|
||||||
presence_penalty: this.settings.presencePenalty,
|
|
||||||
});
|
|
||||||
result = {
|
result = {
|
||||||
ok: true,
|
ok: true,
|
||||||
completions: response.data.choices.map((choice) => choice.text || ""),
|
completions: response.data.choices.map((choice) => choice.text || ""),
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
if (this.settings.logApiCalls) {
|
||||||
|
console.error("Azure error:", e);
|
||||||
|
}
|
||||||
result = {
|
result = {
|
||||||
ok: false,
|
ok: false,
|
||||||
status: e.response.status,
|
status: e.response.status,
|
||||||
message: e.response.data.error.message,
|
message: e.response.data.error.message || "Unknown error",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
@ -1698,18 +1769,27 @@ export default class LoomPlugin extends Plugin {
|
||||||
|
|
||||||
async completeAzureChat(prompt: string) {
|
async completeAzureChat(prompt: string) {
|
||||||
prompt = this.trimOpenAIPrompt(prompt);
|
prompt = this.trimOpenAIPrompt(prompt);
|
||||||
|
const body = {
|
||||||
|
model: getPreset(this.settings).model,
|
||||||
|
messages: [{ role: "assistant" as const, content: prompt }],
|
||||||
|
max_tokens: this.settings.maxTokens,
|
||||||
|
n: this.settings.n,
|
||||||
|
temperature: this.settings.temperature,
|
||||||
|
top_p: this.settings.topP,
|
||||||
|
frequency_penalty: this.settings.frequencyPenalty,
|
||||||
|
presence_penalty: this.settings.presencePenalty,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (this.settings.logApiCalls) {
|
||||||
|
console.log("Azure Chat request:", body);
|
||||||
|
}
|
||||||
|
|
||||||
let result: CompletionResult;
|
let result: CompletionResult;
|
||||||
try {
|
try {
|
||||||
const response = await this.azure.createChatCompletion({
|
const response = await this.azure.createChatCompletion(body);
|
||||||
model: getPreset(this.settings).model,
|
if (this.settings.logApiCalls) {
|
||||||
messages: [{ role: "assistant", content: prompt }],
|
console.log("Azure Chat response:", response);
|
||||||
max_tokens: this.settings.maxTokens,
|
}
|
||||||
n: this.settings.n,
|
|
||||||
temperature: this.settings.temperature,
|
|
||||||
top_p: this.settings.topP,
|
|
||||||
frequency_penalty: this.settings.frequencyPenalty,
|
|
||||||
presence_penalty: this.settings.presencePenalty,
|
|
||||||
});
|
|
||||||
result = {
|
result = {
|
||||||
ok: true,
|
ok: true,
|
||||||
completions: response.data.choices.map(
|
completions: response.data.choices.map(
|
||||||
|
|
@ -1717,10 +1797,13 @@ export default class LoomPlugin extends Plugin {
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
if (this.settings.logApiCalls) {
|
||||||
|
console.error("Azure Chat error:", e);
|
||||||
|
}
|
||||||
result = {
|
result = {
|
||||||
ok: false,
|
ok: false,
|
||||||
status: e.response.status,
|
status: e.response.status,
|
||||||
message: e.response.data.error.message,
|
message: e.response.data.error.message || "Unknown error",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
@ -1803,6 +1886,35 @@ export default class LoomPlugin extends Plugin {
|
||||||
await this.saveData({ settings: this.settings, state: this.state });
|
await this.saveData({ settings: this.settings, state: this.state });
|
||||||
this.initializeProviders();
|
this.initializeProviders();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add this new method to properly refresh all views
|
||||||
|
private refreshViews() {
|
||||||
|
// Refresh Loom views
|
||||||
|
this.app.workspace.getLeavesOfType("loom").forEach((leaf) => {
|
||||||
|
if (leaf.view instanceof LoomView) {
|
||||||
|
leaf.view.render();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Refresh Loom siblings views
|
||||||
|
this.app.workspace.getLeavesOfType("loom-siblings").forEach((leaf) => {
|
||||||
|
if (leaf.view instanceof LoomSiblingsView) {
|
||||||
|
leaf.view.render();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update saveAndRender to use the new refresh method
|
||||||
|
async saveAndRender() {
|
||||||
|
await this.save();
|
||||||
|
|
||||||
|
if (this.rendering) return;
|
||||||
|
this.rendering = true;
|
||||||
|
|
||||||
|
this.refreshViews();
|
||||||
|
|
||||||
|
this.rendering = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// this relies on `LoomPlugin`, so it's here, not in `views.ts`
|
// this relies on `LoomPlugin`, so it's here, not in `views.ts`
|
||||||
|
|
@ -1902,63 +2014,87 @@ class LoomSettingTab extends PluginSettingTab {
|
||||||
});
|
});
|
||||||
|
|
||||||
fillInModelDropdown.createEl("option", {
|
fillInModelDropdown.createEl("option", {
|
||||||
text: "davinci-002",
|
text: "Llama 3.1 405B (Hyperbolic)",
|
||||||
attr: { value: "davinci-002" },
|
attr: { value: "llama-3.1-405b-hyperbolic" },
|
||||||
});
|
});
|
||||||
fillInModelDropdown.createEl("option", {
|
fillInModelDropdown.createEl("option", {
|
||||||
text: "code-davinci-002",
|
text: "Llama 3.1 405B (OpenRouter)",
|
||||||
attr: { value: "code-davinci-002" },
|
attr: { value: "llama-3.1-405b-openrouter" },
|
||||||
});
|
});
|
||||||
fillInModelDropdown.createEl("option", {
|
fillInModelDropdown.createEl("option", {
|
||||||
text: "code-davinci-002 (Proxy)",
|
text: "Claude 3 Opus",
|
||||||
attr: { value: "code-davinci-002-proxy" },
|
attr: { value: "claude-3-opus" },
|
||||||
});
|
});
|
||||||
fillInModelDropdown.createEl("option", {
|
fillInModelDropdown.createEl("option", {
|
||||||
text: "gpt-4-base",
|
text: "Claude 3.5 Sonnet",
|
||||||
|
attr: { value: "claude-3.5-sonnet" },
|
||||||
|
});
|
||||||
|
fillInModelDropdown.createEl("option", {
|
||||||
|
text: "GPT-4 base",
|
||||||
attr: { value: "gpt-4-base" },
|
attr: { value: "gpt-4-base" },
|
||||||
});
|
});
|
||||||
fillInModelDropdown.createEl("option", {
|
fillInModelDropdown.createEl("option", {
|
||||||
text: "claude-3-opus",
|
text: "davinci-002",
|
||||||
attr: { value: "claude-3-opus" },
|
attr: { value: "davinci-002" },
|
||||||
});
|
});
|
||||||
|
|
||||||
fillInModelDropdown.addEventListener("change", (event) => {
|
fillInModelDropdown.addEventListener("change", (event) => {
|
||||||
const value = (event.target as HTMLSelectElement).value;
|
const value = (event.target as HTMLSelectElement).value;
|
||||||
switch (value) {
|
switch (value) {
|
||||||
case "davinci-002": {
|
case "llama-3.1-405b-hyperbolic": {
|
||||||
this.plugin.settings.modelPresets[
|
|
||||||
this.plugin.settings.modelPreset
|
|
||||||
].provider = "openai";
|
|
||||||
this.plugin.settings.modelPresets[
|
|
||||||
this.plugin.settings.modelPreset
|
|
||||||
].model = "davinci-002";
|
|
||||||
this.plugin.settings.modelPresets[
|
|
||||||
this.plugin.settings.modelPreset
|
|
||||||
].contextLength = 16384;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "code-davinci-002": {
|
|
||||||
this.plugin.settings.modelPresets[
|
|
||||||
this.plugin.settings.modelPreset
|
|
||||||
].provider = "openai";
|
|
||||||
this.plugin.settings.modelPresets[
|
|
||||||
this.plugin.settings.modelPreset
|
|
||||||
].model = "code-davinci-002";
|
|
||||||
this.plugin.settings.modelPresets[
|
|
||||||
this.plugin.settings.modelPreset
|
|
||||||
].contextLength = 8001;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "code-davinci-002-proxy": {
|
|
||||||
this.plugin.settings.modelPresets[
|
this.plugin.settings.modelPresets[
|
||||||
this.plugin.settings.modelPreset
|
this.plugin.settings.modelPreset
|
||||||
].provider = "openai-compat";
|
].provider = "openai-compat";
|
||||||
this.plugin.settings.modelPresets[
|
this.plugin.settings.modelPresets[
|
||||||
this.plugin.settings.modelPreset
|
this.plugin.settings.modelPreset
|
||||||
].model = "code-davinci-002";
|
// @ts-expect-error
|
||||||
|
].url = "https://api.hyperbolic.xyz";
|
||||||
this.plugin.settings.modelPresets[
|
this.plugin.settings.modelPresets[
|
||||||
this.plugin.settings.modelPreset
|
this.plugin.settings.modelPreset
|
||||||
].contextLength = 8001;
|
].model = "meta-llama/Meta-Llama-3.1-405B";
|
||||||
|
this.plugin.settings.modelPresets[
|
||||||
|
this.plugin.settings.modelPreset
|
||||||
|
].contextLength = 32768;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "llama-3.1-405b-openrouter": {
|
||||||
|
this.plugin.settings.modelPresets[
|
||||||
|
this.plugin.settings.modelPreset
|
||||||
|
].provider = "openrouter";
|
||||||
|
this.plugin.settings.modelPresets[
|
||||||
|
this.plugin.settings.modelPreset
|
||||||
|
// @ts-expect-error
|
||||||
|
].quantization = "bf16";
|
||||||
|
this.plugin.settings.modelPresets[
|
||||||
|
this.plugin.settings.modelPreset
|
||||||
|
].model = "meta-llama/llama-3.1-405b";
|
||||||
|
this.plugin.settings.modelPresets[
|
||||||
|
this.plugin.settings.modelPreset
|
||||||
|
].contextLength = 32768;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "claude-3-opus": {
|
||||||
|
this.plugin.settings.modelPresets[
|
||||||
|
this.plugin.settings.modelPreset
|
||||||
|
].provider = "anthropic";
|
||||||
|
this.plugin.settings.modelPresets[
|
||||||
|
this.plugin.settings.modelPreset
|
||||||
|
].model = "claude-3-opus-20240229";
|
||||||
|
this.plugin.settings.modelPresets[
|
||||||
|
this.plugin.settings.modelPreset
|
||||||
|
].contextLength = 50000;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "claude-3.5-sonnet": {
|
||||||
|
this.plugin.settings.modelPresets[
|
||||||
|
this.plugin.settings.modelPreset
|
||||||
|
].provider = "anthropic";
|
||||||
|
this.plugin.settings.modelPresets[
|
||||||
|
this.plugin.settings.modelPreset
|
||||||
|
].model = "claude-3-5-sonnet-20240620";
|
||||||
|
this.plugin.settings.modelPresets[
|
||||||
|
this.plugin.settings.modelPreset
|
||||||
|
].contextLength = 50000;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "gpt-4-base": {
|
case "gpt-4-base": {
|
||||||
|
|
@ -1973,16 +2109,16 @@ class LoomSettingTab extends PluginSettingTab {
|
||||||
].contextLength = 8192;
|
].contextLength = 8192;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "claude-3-opus": {
|
case "davinci-002": {
|
||||||
this.plugin.settings.modelPresets[
|
this.plugin.settings.modelPresets[
|
||||||
this.plugin.settings.modelPreset
|
this.plugin.settings.modelPreset
|
||||||
].provider = "anthropic";
|
].provider = "openai";
|
||||||
this.plugin.settings.modelPresets[
|
this.plugin.settings.modelPresets[
|
||||||
this.plugin.settings.modelPreset
|
this.plugin.settings.modelPreset
|
||||||
].model = "claude-3-opus-20240229";
|
].model = "davinci-002";
|
||||||
this.plugin.settings.modelPresets[
|
this.plugin.settings.modelPresets[
|
||||||
this.plugin.settings.modelPreset
|
this.plugin.settings.modelPreset
|
||||||
].contextLength = 20000;
|
].contextLength = 16384;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"id": "loom",
|
"id": "loom",
|
||||||
"name": "Loom",
|
"name": "Loom",
|
||||||
"version": "1.22.1",
|
"version": "1.22.6",
|
||||||
"minAppVersion": "0.15.0",
|
"minAppVersion": "0.15.0",
|
||||||
"description": "Loom in Obsidian",
|
"description": "Loom in Obsidian",
|
||||||
"author": "celeste",
|
"author": "celeste",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "obsidian-loom",
|
"name": "obsidian-loom",
|
||||||
"version": "1.22.1",
|
"version": "1.22.6",
|
||||||
"description": "Loom in Obsidian",
|
"description": "Loom in Obsidian",
|
||||||
"main": "main.js",
|
"main": "main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue