Skip to content

Commit

Permalink
API URL setting, system prompt override
Browse files Browse the repository at this point in the history
  • Loading branch information
rpggio committed Sep 19, 2023
1 parent 5b831a7 commit b373618
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/ChatStreamPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ export class ChatStreamPlugin extends Plugin {
try {
const generated = await getChatGPTCompletion(
settings.apiKey,
settings.apiUrl,
settings.apiModel,
messages,
{
Expand Down
4 changes: 3 additions & 1 deletion src/openai/chatGPT.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { request, RequestUrlParam } from "obsidian"
import { openai } from './chatGPT-types'

export const OPENAI_COMPLETIONS_URL = `https://api.openai.com/v1/chat/completions`

export const CHAT_MODELS = {
GPT35: {
name: 'gpt-3.5-turbo',
Expand Down Expand Up @@ -40,11 +42,11 @@ export const defaultChatGPTSettings: Partial<openai.CreateChatCompletionRequest>

export async function getChatGPTCompletion(
apiKey: string,
apiUrl: string,
model: openai.CreateChatCompletionRequest['model'],
messages: openai.CreateChatCompletionRequest['messages'],
settings?: Partial<Omit<openai.CreateChatCompletionRequest, 'messages' | 'model'>>
): Promise<string | undefined> {
const apiUrl = `https://api.openai.com/v1/chat/completions`
const headers = {
Authorization: `Bearer ${apiKey}`,
"Content-Type": "application/json",
Expand Down
8 changes: 7 additions & 1 deletion src/settings/ChatStreamSettings.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { CHAT_MODELS } from 'src/openai/chatGPT'
import { CHAT_MODELS, OPENAI_COMPLETIONS_URL } from 'src/openai/chatGPT'

export interface ChatStreamSettings {
/**
* The API key to use when making requests
*/
apiKey: string

/**
* The URL endpoint for chat
*/
apiUrl: string

/**
* The GPT model to use
*/
Expand Down Expand Up @@ -53,6 +58,7 @@ Use step-by-step reasoning. Be brief.

export const DEFAULT_SETTINGS: ChatStreamSettings = {
apiKey: '',
apiUrl: OPENAI_COMPLETIONS_URL,
apiModel: CHAT_MODELS.GPT35.name,
temperature: 1,
systemPrompt: DEFAULT_SYSTEM_PROMPT,
Expand Down
19 changes: 18 additions & 1 deletion src/settings/SettingsTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class SettingsTab extends PluginSettingTab {

new Setting(containerEl)
.setName('System prompt')
.setDesc('The system prompt sent with each request to the API.')
.setDesc(`The system prompt sent with each request to the API. \n(Note: you can override this by beginning a note stream with a note starting 'SYSTEM PROMPT'. The remaining content of that note will be used as system prompt.)`)
.addTextArea((component) => {
component.inputEl.rows = 6
component.inputEl.style.width = '300px'
Expand Down Expand Up @@ -120,6 +120,23 @@ export class SettingsTab extends PluginSettingTab {
})
)

new Setting(containerEl)
.setName("API URL")
.setDesc(
"The chat completions URL to use. You probably won't need to change this."
)
.addText((text) => {
text.inputEl.style.width = '300px'
text
.setPlaceholder("API URL")
.setValue(this.plugin.settings.apiUrl)
.onChange(async (value) => {
this.plugin.settings.apiUrl = value
await this.plugin.saveSettings()
})
}
)

new Setting(containerEl)
.setName("Debug output")
.setDesc(
Expand Down

0 comments on commit b373618

Please sign in to comment.