Skip to content

Commit

Permalink
Remove valtown proxy config for anthropic provider, support native an…
Browse files Browse the repository at this point in the history
…thropic cors header
  • Loading branch information
cephalization committed Sep 5, 2024
1 parent 1c73580 commit 2de6b85
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 98 deletions.
5 changes: 1 addition & 4 deletions packages/cannoli-core/src/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,7 @@ export class LLMProvider {
anthropicApiUrl: url,
clientOptions: {
defaultHeaders: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
"Access-Control-Allow-Headers": "*",
"x-authorization": `${this.valtownApiKey}`
"anthropic-dangerous-direct-browser-access": "true",
},
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,95 +3,74 @@ import Cannoli from "src/main";
import { DEFAULT_SETTINGS } from "src/settings/settings";

export function createAnthropicSettings(containerEl: HTMLElement, plugin: Cannoli, display: () => void): void {
new Setting(containerEl)
.setName("Create proxy server on Val Town")
.setDesc("Anthropic requests currently require a proxy server. This button will use your Val Town API key to create a new HTTP val on your Val Town account which will handle all Anthropic requests.")
.addButton((button) =>
button
.setButtonText("Create proxy server")
.onClick(async () => {
// If they don't have a valtown API key, give a notice
if (!plugin.settings.valTownAPIKey) {
alert("You don't have a Val Town API key. Please enter one in the settings.");
return;
}

// call the create proxy server function
await plugin.createProxyServer();

await plugin.saveSettings();
display();
})
);

new Setting(containerEl)
.setName("Anthropic base URL")
.setDesc("This base URL will be used to make all Anthropic LLM calls.")
.addText((text) =>
text
.setValue(plugin.settings.anthropicBaseURL)
.setPlaceholder("https://api.anthropic.com/v1/")
.onChange(async (value) => {
plugin.settings.anthropicBaseURL = value;
await plugin.saveSettings();
})
);

// anthropic api key setting
new Setting(containerEl)
.setName("Anthropic API key")
.setDesc(
"This key will be used to make all Anthropic LLM calls. Be aware that complex cannolis, can be expensive to run."
)
.addText((text) =>
text
.setValue(plugin.settings.anthropicAPIKey)
.setPlaceholder("sk-...")
.onChange(async (value) => {
plugin.settings.anthropicAPIKey = value;
await plugin.saveSettings();
}).inputEl.setAttribute("type", "password")
);
// anthropic model setting
new Setting(containerEl)
.setName("Anthropic model")
.setDesc(
"This model will be used for all LLM nodes unless overridden with a config arrow."
)
.addText((text) =>
text
.setValue(plugin.settings.anthropicModel)
.onChange(async (value) => {
plugin.settings.anthropicModel = value;
await plugin.saveSettings();
})
);
// Default LLM temperature setting
new Setting(containerEl)
.setName("Default LLM temperature")
.setDesc(
"This temperature will be used for all LLM nodes unless overridden with a config arrow."
)
.addText((text) =>
text
.setValue(
!isNaN(plugin.settings.anthropicTemperature) &&
plugin.settings.anthropicTemperature
? plugin.settings.anthropicTemperature.toString()
: DEFAULT_SETTINGS.anthropicTemperature.toString()
)
.onChange(async (value) => {
// If it's not empty and it's a number, save it
if (!isNaN(parseFloat(value))) {
plugin.settings.anthropicTemperature =
parseFloat(value);
await plugin.saveSettings();
} else {
// Otherwise, reset it to the default
plugin.settings.anthropicTemperature =
DEFAULT_SETTINGS.anthropicTemperature;
await plugin.saveSettings();
}
})
);
}
new Setting(containerEl)
.setName("Anthropic base URL")
.setDesc("(Optional) This base URL will be used to make all Anthropic LLM calls. If you are using the former ValTown proxy workaround, please clear this field.")
.addText((text) =>
text
.setValue(plugin.settings.anthropicBaseURL)
.setPlaceholder("https://api.anthropic.com/v1/")
.onChange(async (value) => {
plugin.settings.anthropicBaseURL = value;
await plugin.saveSettings();
})
);
// anthropic api key setting
new Setting(containerEl)
.setName("Anthropic API key")
.setDesc(
"This key will be used to make all Anthropic LLM calls. Be aware that complex cannolis, can be expensive to run."
)
.addText((text) =>
text
.setValue(plugin.settings.anthropicAPIKey)
.setPlaceholder("sk-...")
.onChange(async (value) => {
plugin.settings.anthropicAPIKey = value;
await plugin.saveSettings();
}).inputEl.setAttribute("type", "password")
);
// anthropic model setting
new Setting(containerEl)
.setName("Anthropic model")
.setDesc(
"This model will be used for all LLM nodes unless overridden with a config arrow."
)
.addText((text) =>
text
.setValue(plugin.settings.anthropicModel)
.setPlaceholder("claude-3-5-sonnet-20240620")
.onChange(async (value) => {
plugin.settings.anthropicModel = value;
await plugin.saveSettings();
})
);
// Default LLM temperature setting
new Setting(containerEl)
.setName("Default LLM temperature")
.setDesc(
"This temperature will be used for all LLM nodes unless overridden with a config arrow."
)
.addText((text) =>
text
.setValue(
!isNaN(plugin.settings.anthropicTemperature) &&
plugin.settings.anthropicTemperature
? plugin.settings.anthropicTemperature.toString()
: DEFAULT_SETTINGS.anthropicTemperature.toString()
)
.onChange(async (value) => {
// If it's not empty and it's a number, save it
if (!isNaN(parseFloat(value))) {
plugin.settings.anthropicTemperature =
parseFloat(value);
await plugin.saveSettings();
} else {
// Otherwise, reset it to the default
plugin.settings.anthropicTemperature =
DEFAULT_SETTINGS.anthropicTemperature;
await plugin.saveSettings();
}
})
);
}
4 changes: 2 additions & 2 deletions packages/cannoli-plugin/src/settings/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const DEFAULT_SETTINGS: CannoliSettings = {
geminiModel: "gemini-1.0-pro-latest",
geminiAPIKey: "",
geminiTemperature: 1,
anthropicModel: "claude-3-opus-20240229",
anthropicModel: "claude-3-5-sonnet-20240620",
anthropicAPIKey: "",
anthropicTemperature: 1,
anthropicBaseURL: "",
Expand Down Expand Up @@ -93,4 +93,4 @@ export const DEFAULT_SETTINGS: CannoliSettings = {
bakeIndent: "2",
seenVersion2Modal: false,
secrets: [],
};
};

0 comments on commit 2de6b85

Please sign in to comment.