Skip to content

Commit

Permalink
Add setting for custom API endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorgalvao committed Mar 7, 2024
1 parent 78520ad commit 851f71b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Workflow/chatgpt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function markdownChat(messages, ignoreLastInterrupted = true) {
}, "")
}

function startStream(apiKey, model, systemPrompt, ongoingChat, streamFile, pidStreamFile) {
function startStream(apiEndpoint, apiKey, model, systemPrompt, ongoingChat, streamFile, pidStreamFile) {
$.NSFileManager.defaultManager.createFileAtPathContentsAttributes(streamFile, undefined, undefined) // Create emtpy file

const messages = systemPrompt ?
Expand All @@ -70,7 +70,7 @@ function startStream(apiKey, model, systemPrompt, ongoingChat, streamFile, pidSt

task.executableURL = $.NSURL.fileURLWithPath("/usr/bin/curl")
task.arguments = [
"https://api.openai.com/v1/chat/completions",
`${apiEndpoint}/v1/chat/completions`,
"--speed-limit", "0", "--speed-time", "5", // Abort stalled connection after a few seconds
"--silent", "--no-buffer",
"--header", "Content-Type: application/json",
Expand Down Expand Up @@ -196,6 +196,7 @@ function run(argv) {
const typedQuery = argv[0]
const maxEntries = 100
const apiKey = envVar("openai_api_key")
const apiEndpoint = envVar("chatgpt_api_endpoint")
const systemPrompt = envVar("system_prompt")
const model = envVar("gpt_model")
const pidStreamFile = `${envVar("alfred_workflow_cache")}/pid.txt`
Expand Down Expand Up @@ -229,7 +230,7 @@ function run(argv) {
const ongoingChat = previousChat.concat(appendQuery)

// Make API request, write chat file, and start loop
startStream(apiKey, model, systemPrompt, ongoingChat, streamFile, pidStreamFile)
startStream(apiEndpoint, apiKey, model, systemPrompt, ongoingChat, streamFile, pidStreamFile)
appendChat(chatFile, appendQuery)

return JSON.stringify({
Expand Down
5 changes: 5 additions & 0 deletions Workflow/info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -1522,6 +1522,11 @@ Query DALL·E via the `dalle` keyword.
<string>dalle_image_number</string>
</dict>
</array>
<key>variables</key>
<dict>
<key>chatgpt_api_endpoint</key>
<string>https://api.openai.com</string>
</dict>
<key>version</key>
<string>2024.3</string>
<key>webaddress</key>
Expand Down

0 comments on commit 851f71b

Please sign in to comment.