Skip to content

Commit

Permalink
gpt-4-turbo
Browse files Browse the repository at this point in the history
  • Loading branch information
brianpetro committed Nov 15, 2023
1 parent d34f90d commit 49b1afa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 42 deletions.
51 changes: 12 additions & 39 deletions dist/main.js

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2346,6 +2346,7 @@ class SmartConnectionsSettingsTab extends Obsidian.PluginSettingTab {
dropdown.addOption("gpt-3.5-turbo-16k", "gpt-3.5-turbo-16k");
dropdown.addOption("gpt-4", "gpt-4 (limited access, 8k)");
dropdown.addOption("gpt-3.5-turbo", "gpt-3.5-turbo (4k)");
dropdown.addOption("gpt-4-1106-preview", "gpt-4-turbo (128k)");
dropdown.onChange(async (value) => {
this.plugin.settings.smart_chat_model = value;
await this.plugin.saveSettings();
Expand Down Expand Up @@ -3019,6 +3020,7 @@ class SmartConnectionsChatView extends Obsidian.ItemView {
let max_available_tokens = max_total_tokens - curr_token_est;
// if max_available_tokens is less than 0, set to 200
if(max_available_tokens < 0) max_available_tokens = 200;
else if(max_available_tokens > 4096) max_available_tokens = 4096;
console.log("max_available_tokens", max_available_tokens);
opts = {
model: this.plugin.settings.smart_chat_model,
Expand Down Expand Up @@ -3195,15 +3197,16 @@ class SmartConnectionsChatView extends Obsidian.ItemView {
// get std dev of similarity
const sim = nearest.map((n) => n.similarity);
const mean = sim.reduce((a, b) => a + b) / sim.length;
const std_dev = Math.sqrt(sim.map((x) => Math.pow(x - mean, 2)).reduce((a, b) => a + b) / sim.length);
let std_dev = Math.sqrt(sim.map((x) => Math.pow(x - mean, 2)).reduce((a, b) => a + b) / sim.length);
// slice where next item deviation is greater than std_dev
let slice_i = 0;
while (slice_i < nearest.length) {
const next = nearest[slice_i + 1];
if (next) {
const next_dev = Math.abs(next.similarity - nearest[slice_i].similarity);
if (next_dev > std_dev) {
break;
if(slice_i < 3) std_dev = std_dev * 1.5;
else break;
}
}
slice_i++;
Expand All @@ -3224,7 +3227,7 @@ class SmartConnectionsChatView extends Obsidian.ItemView {

async get_context_for_prompt(nearest) {
let context = [];
const MAX_SOURCES = 20; // 10 * 1000 (max chars) = 10,000 chars (must be under ~16,000 chars or 4K tokens)
const MAX_SOURCES = (this.plugin.settings.smart_chat_model === 'gpt-4-1106-preview') ? 42 : 20;
const MAX_CHARS = get_max_chars(this.plugin.settings.smart_chat_model) / 2;
let char_accum = 0;
for (let i = 0; i < nearest.length; i++) {
Expand Down Expand Up @@ -3272,6 +3275,7 @@ function get_max_chars(model="gpt-3.5-turbo") {
"gpt-3.5-turbo-16k": 48000,
"gpt-4": 24000,
"gpt-3.5-turbo": 12000,
"gpt-4-1106-preview": 200000,
};
return MAX_CHAR_MAP[model];
}
Expand Down

0 comments on commit 49b1afa

Please sign in to comment.