-
-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
83 additions
and
1 deletion.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
backend/files/misc/workflows/actions/chatgpt-instructions.hl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
2 changes: 1 addition & 1 deletion
2
...c/workflows/actions/invoke-openai-chat.hl → ...d/files/misc/workflows/actions/chatgpt.hl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters