diff --git a/plugins/tiddlywiki/ai-tools/globals.tid b/plugins/tiddlywiki/ai-tools/globals.tid index 411da6136..b3d2fc550 100644 --- a/plugins/tiddlywiki/ai-tools/globals.tid +++ b/plugins/tiddlywiki/ai-tools/globals.tid @@ -7,13 +7,13 @@ tags: $:/tags/Global -\procedure get-llm-completion(payload,resultTitlePrefix,resultTags,statusTitle,completionServer) +\procedure get-llm-completion(conversationTitle,resultTitlePrefix,resultTags,statusTitle,completionServer) @@ -42,19 +42,21 @@ completionServer - Optional URL of server <$let completionServer={{{ [!is[blank]else] }}} > - <$action-log message="get-llm-completion"/> - <$action-log/> - <$action-sendmessage - $message="tm-http-request" - url={{{ [get[url]addsuffix[/v1/chat/completions]] }}} - body=<> - header-content-type="application/json" - bearer-auth-token-from-store="openai-secret-key" - method="POST" - oncompletion=<> - bind-status=<> - var-resultTitlePrefix=<> - var-resultTags=<> - /> + <$wikify name="json" text={{{ [get[text]] }}}> + <$action-log message="get-llm-completion"/> + <$action-log/> + <$action-sendmessage + $message="tm-http-request" + url={{{ [get[url]addsuffix[/v1/chat/completions]] }}} + body=<> + header-content-type="application/json" + bearer-auth-token-from-store="openai-secret-key" + method="POST" + oncompletion=<> + bind-status=<> + var-resultTitlePrefix=<> + var-resultTags=<> + /> + \end get-llm-completion diff --git a/plugins/tiddlywiki/ai-tools/page-menu/new-conversation.tid b/plugins/tiddlywiki/ai-tools/page-menu/new-conversation.tid index 1e7464de5..5438ae2b9 100644 --- a/plugins/tiddlywiki/ai-tools/page-menu/new-conversation.tid +++ b/plugins/tiddlywiki/ai-tools/page-menu/new-conversation.tid @@ -6,7 +6,7 @@ tags: $:/tags/AI/PageMenu $basetitle="AI Conversation" tags="$:/tags/AI/Conversation" system-prompt="You are a helpful assistant." - current-response-text="Please describe this picture" + current-response-text="Please list the 10 most important things that happened in South East Asia in the Twentieth Century" > <$action-navigate $to=<>/> diff --git a/plugins/tiddlywiki/ai-tools/servers/local-llamafile.tid b/plugins/tiddlywiki/ai-tools/servers/local-llamafile.tid index cd52bd9fe..4348507d6 100644 --- a/plugins/tiddlywiki/ai-tools/servers/local-llamafile.tid +++ b/plugins/tiddlywiki/ai-tools/servers/local-llamafile.tid @@ -2,3 +2,23 @@ title: $:/plugins/tiddlywiki/ai-tools/servers/local-llamafile tags: $:/tags/AI/CompletionServer url: http://127.0.0.1:8080 caption: Locally running Llamafile server + +\rules only filteredtranscludeinline transcludeinline macrodef macrocallinline html conditional commentblock commentinline +{ + "model": "gpt-4o", + "messages": [ + { + "role": "system", + "content": "<$text text={{{ [get[system-prompt]jsonstringify[]] }}}/>" + } + + <$list filter="[all[shadows+tiddlers]tag!is[draft]sort[created]]"> + , + { + + "role": "<$text text={{{ [get[role]jsonstringify[]] }}}/>", + "content": "<$text text={{{ [get[text]jsonstringify[]] }}}/>" + } + + ] +} \ No newline at end of file diff --git a/plugins/tiddlywiki/ai-tools/servers/openai.tid b/plugins/tiddlywiki/ai-tools/servers/openai.tid index a1bc1c787..ae9c19a03 100644 --- a/plugins/tiddlywiki/ai-tools/servers/openai.tid +++ b/plugins/tiddlywiki/ai-tools/servers/openai.tid @@ -2,3 +2,38 @@ title: $:/plugins/tiddlywiki/ai-tools/servers/openai tags: $:/tags/AI/CompletionServer url: https://api.openai.com caption: OpenAI Service + +\rules only filteredtranscludeinline transcludeinline macrodef macrocallinline html conditional commentblock commentinline +{ + "model": "gpt-4o", + "messages": [ + { + "role": "system", + "content": "<$text text={{{ [get[system-prompt]jsonstringify[]] }}}/>" + } + + <$list filter="[all[shadows+tiddlers]tag!is[draft]sort[created]]"> + , + { + + "role": "<$text text={{{ [get[role]jsonstringify[]] }}}/>", + "content": [ + { + "type": "text", + "text": "<$text text={{{ [get[text]jsonstringify[]] }}}/>" + } + <%if [get[image]else[]!match[]] %> + , + { + "type": "image_url", + "image_url": { + "url": "<$text text={{{ [[data:]] [get[image]get[type]] [[;base64,]] [get[image]get[text]jsonstringify[]] +[join[]] }}}/>" + } + } + <%endif%> + ] + + } + + ] +} \ No newline at end of file diff --git a/plugins/tiddlywiki/ai-tools/view-templates/conversation.tid b/plugins/tiddlywiki/ai-tools/view-templates/conversation.tid index 5e7adab00..7c99de705 100644 --- a/plugins/tiddlywiki/ai-tools/view-templates/conversation.tid +++ b/plugins/tiddlywiki/ai-tools/view-templates/conversation.tid @@ -65,46 +65,6 @@ Procedure to display a message from an AI conversation. Current tiddler is the c \end ai-message - -\procedure payload() -\rules only filteredtranscludeinline transcludeinline macrodef macrocallinline html conditional commentblock commentinline -{ - "model": "gpt-4o", - "messages": [ - { - "role": "system", - "content": "<$text text={{{ [get[system-prompt]jsonstringify[]] }}}/>" - } - - <$list filter="[all[shadows+tiddlers]tag!is[draft]sort[created]]"> - , - { - - "role": "<$text text={{{ [get[role]jsonstringify[]] }}}/>", - "content": [ - { - "type": "text", - "text": "<$text text={{{ [get[text]jsonstringify[]] }}}/>" - } - <%if [get[image]else[]!match[]] %> - , - { - "type": "image_url", - "image_url": { - "url": "<$text text={{{ [[data:]] [get[image]get[type]] [[;base64,]] [get[image]get[text]jsonstringify[]] +[join[]] }}}/>" - } - } - <%endif%> - ] - - } - - ] -} -\end payload - @@ -123,16 +83,14 @@ Action procedure to get the next response from the LLM > <$action-deletefield $tiddler=<> $field="current-response-text"/> <$action-deletefield $tiddler=<> $field="current-response-image"/> - <$wikify name="json" text=<>> - <$transclude - $variable="get-llm-completion" - payload=<> - completionServer={{!!completion-server}} - resultTitlePrefix=<> - resultTags=<> - statusTitle=<> - /> - + <$transclude + $variable="get-llm-completion" + conversationTitle=<> + completionServer={{!!completion-server}} + resultTitlePrefix=<> + resultTags=<> + statusTitle=<> + /> \end action-get-response