Skip to content

Commit

Permalink
Fix padding and context window errors
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmicoptima committed Oct 2, 2023
1 parent 06cbff8 commit 2c3c45d
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface LoomSettings {

provider: Provider;
model: string;
contextLength: number;
maxTokens: number;
temperature: number;
topP: number;
Expand Down
5 changes: 3 additions & 2 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const DEFAULT_SETTINGS: LoomSettings = {

provider: "ocp",
model: "code-davinci-002",
contextLength: 8000,
maxTokens: 60,
temperature: 1,
topP: 1,
Expand Down Expand Up @@ -1230,7 +1231,7 @@ export default class LoomPlugin extends Plugin {

async completeCohere(prompt: string) {
const tokens = (await cohere.tokenize({ text: prompt })).body.token_strings;
prompt = tokens.slice(-8000).join("");
prompt = tokens.slice(-this.settings.contextLength).join("");

const response = await cohere.generate({
model: this.settings.model,
Expand Down Expand Up @@ -1290,7 +1291,7 @@ export default class LoomPlugin extends Plugin {
else if (p50kModels.includes(this.settings.model)) tokenizer = p50k;
else tokenizer = r50k; // i expect that an unknown model will most likely be r50k

return tokenizer.decode(tokenizer.encode(prompt, { disallowedSpecial: new Set() }).slice(-8000)); // TODO context length depends on model
return tokenizer.decode(tokenizer.encode(prompt, { disallowedSpecial: new Set() }).slice(-(this.settings.contextLength - this.settings.maxTokens)));
}

async completeOCP(prompt: string) {
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "loom",
"name": "Loom",
"version": "1.16.2",
"version": "1.16.3",
"minAppVersion": "0.15.0",
"description": "Loom in Obsidian",
"author": "celeste",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-loom",
"version": "1.16.2",
"version": "1.16.3",
"description": "Loom in Obsidian",
"main": "main.js",
"scripts": {
Expand Down
3 changes: 2 additions & 1 deletion styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ body {

.loom__view {
overflow-y: auto;
padding: 0 0.6em;
}

/* nav buttons */

.loom__nav-buttons {
margin-top: 0.5em;
margin: 0.5em 0 1em;
}

/* alt export field */
Expand Down
1 change: 1 addition & 0 deletions views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ export class LoomView extends ItemView {
}

setting("Model", "model", settings.model, "string");
setting("Context length", "contextLength", String(settings.contextLength), "int");
setting("Length (in tokens)", "maxTokens", String(settings.maxTokens), "int");
setting("Number of completions", "n", String(settings.n), "int");
setting("Temperature", "temperature", String(settings.temperature), "float");
Expand Down

0 comments on commit 2c3c45d

Please sign in to comment.