Skip to content

Commit

Permalink
b
Browse files Browse the repository at this point in the history
  • Loading branch information
polterguy committed Dec 24, 2023
1 parent 3167852 commit 968c0fd
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 1 deletion.
82 changes: 82 additions & 0 deletions backend/files/misc/workflows/actions/chatgpt-instructions.hl
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@

/*
* Invokes ChatGPT with the specified [prompt], [model] and [max_tokens].
*
* Will use the default API key found from configurations.
*/
.arguments
model
type:enum
mandatory:bool:true
default:gpt-4-1106-preview
values
.:gpt-3.5-turbo
.:gpt-3.5-turbo-16k
.:gpt-4
.:gpt-4-1106-preview
max_tokens
type:int
mandatory:bool:true
default:int:1500
instruction
type:textarea
mandatory:bool:true
prompt
type:textarea
mandatory:bool:true
.icon:chat_bubble

// Sanity checking invocation.
validators.mandatory:x:@.arguments/*/model
validators.mandatory:x:@.arguments/*/prompt
validators.mandatory:x:@.arguments/*/max_tokens

// Retrieving OpenAI API token from configuration settings.
.token
set-value:x:@.token
strings.concat
.:"Bearer "
config.get:"magic:openai:key"

// Invokes OpenAI.
http.post:"https://api.openai.com/v1/chat/completions"
convert:bool:true
headers
Authorization:x:@.token
Content-Type:application/json
payload
model:x:@.arguments/*/model
max_tokens:x:@.arguments/*/max_tokens
temperature:decimal:0.3
messages
.
role:system
content:x:@.arguments/*/instruction
.
role:user
content:x:@.arguments/*/prompt

// Sanity checking above invocation.
if
not
and
mte:x:@http.post
.:int:200
lt:x:@http.post
.:int:300
.lambda

// Oops, error - Logging error and returning status 500 to caller.
lambda2hyper:x:@http.post
log.error:Something went wrong while invoking OpenAI
message:x:@http.post/*/content/*/error/*/message
status:x:@http.post
error:x:@lambda2hyper
throw:Something went wrong while invoking OpenAI
message:x:@http.post/*/content/*/error/*/message
status:x:@http.post
error:x:@lambda2hyper

// Returning result to caller.
yield
result:x:@http.post/*/content/*/choices/0/*/message/*/content
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

/*
* Invokes ChatGPT with the specified [messages].
* Invokes ChatGPT with the specified [prompt], [model] and [max_tokens].
*
* Will use the default API key found from configurations.
*/
Expand Down

0 comments on commit 968c0fd

Please sign in to comment.