Skip to content

Commit 86253c4

Browse files
committed
LLM friendly examples: in the md version, also add the multi-line str
1 parent c4d5fcd commit 86253c4

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

dashjoin-core/src/test/java/org/dashjoin/util/LLMs.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ static void writeInput() throws Exception {
8383
Charset.defaultCharset());
8484
}
8585

86+
@SuppressWarnings("unchecked")
8687
static void writeWidget() throws Exception {
8788
StringBuffer b = new StringBuffer();
8889
b.append("# Appendix: Form Input Types\n");
@@ -97,6 +98,17 @@ static void writeWidget() throws Exception {
9798
b.append(e.description + "\n");
9899
b.append("```json\n");
99100
b.append(om.writerWithDefaultPrettyPrinter().writeValueAsString(e.code) + "\n```\n");
101+
if (e.code instanceof Map) {
102+
Map<String, Object> map = (Map<String, Object>) e.code;
103+
for (Entry<String, Object> field : map.entrySet())
104+
if (field.getValue() instanceof String)
105+
if (((String) field.getValue()).contains("\n")) {
106+
b.append(field.getKey() + "\n");
107+
b.append("```\n");
108+
b.append(field.getValue() + "\n");
109+
b.append("```\n");
110+
}
111+
}
100112
}
101113

102114
FileUtils.write(new File("../dashjoin-docs/docs/appendix-widgets.md"), b,

dashjoin-docs/docs/appendix-widgets.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,11 +304,21 @@ chat widget that allows you to react to user inputs and file uploads. this examp
304304
chat widget that allows you to react to user inputs and file uploads. this example chats with OpenAI's gpt-4o-mini model. The API key must be provided using the 'openai' credentials in the function catalog. The onChat callback passes messages (the chat history) and the new user query to the $chat function. The widget is configured using 'expression'. This expression specifies the initial messages - in this case the system message containing the system prompt
305305
```json
306306
{
307-
"onChat" : "$chat('https://api.openai.com/v1/chat/completions', query, messages, [], {'model':'gpt-4o-mini'}, {'Authorization': 'openai', 'dj-timeout-seconds': 60})",
308-
"expression" : "{'messages': [{'role': 'system', 'content': 'always answer in a funny way'}]}",
307+
"onChat" : "/* called when a new question is entered in the chat */\n$chat('https://api.openai.com/v1/chat/completions', query, messages, [], {'model':'gpt-4o-mini'}, {'Authorization': 'openai', 'dj-timeout-seconds': 60})",
308+
"expression" : "/* initial chat state with system prompt in messages */\n{'messages': [{'role': 'system', 'content': 'always answer in a funny way'}]}",
309309
"widget" : "aichat"
310310
}
311311
```
312+
onChat
313+
```
314+
/* called when a new question is entered in the chat */
315+
$chat('https://api.openai.com/v1/chat/completions', query, messages, [], {'model':'gpt-4o-mini'}, {'Authorization': 'openai', 'dj-timeout-seconds': 60})
316+
```
317+
expression
318+
```
319+
/* initial chat state with system prompt in messages */
320+
{'messages': [{'role': 'system', 'content': 'always answer in a funny way'}]}
321+
```
312322
## analytics widget
313323
displays the results of a SQL query as a chart or table. Allows placing filters on the widget that the user can set when viewing the widget. The database, table, columns, and filter fields determine the SQL query: in this case, it is 'select user, count(ID) from REQUESTS where submitted >= ?' on the database 'sqlite'. Possible filter input widgets are: text, slider, switch, date, select, and selectmultiple.
314324
```json

dashjoin-docs/llms/widget.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,8 @@
350350
"title": "aichat widget",
351351
"description": "chat widget that allows you to react to user inputs and file uploads. this example chats with OpenAI's gpt-4o-mini model. The API key must be provided using the 'openai' credentials in the function catalog. The onChat callback passes messages (the chat history) and the new user query to the $chat function. The widget is configured using 'expression'. This expression specifies the initial messages - in this case the system message containing the system prompt",
352352
"code": {
353-
"onChat": "$chat('https://api.openai.com/v1/chat/completions', query, messages, [], {'model':'gpt-4o-mini'}, {'Authorization': 'openai', 'dj-timeout-seconds': 60})",
354-
"expression": "{'messages': [{'role': 'system', 'content': 'always answer in a funny way'}]}",
353+
"onChat": "/* called when a new question is entered in the chat */\n$chat('https://api.openai.com/v1/chat/completions', query, messages, [], {'model':'gpt-4o-mini'}, {'Authorization': 'openai', 'dj-timeout-seconds': 60})",
354+
"expression": "/* initial chat state with system prompt in messages */\n{'messages': [{'role': 'system', 'content': 'always answer in a funny way'}]}",
355355
"widget": "aichat"
356356
}
357357
}

llms.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,8 @@ TITLE: aichat widget
310310
DESCRIPTION: chat widget that allows you to react to user inputs and file uploads. this example chats with OpenAI's gpt-4o-mini model. The API key must be provided using the 'openai' credentials in the function catalog. The onChat callback passes messages (the chat history) and the new user query to the $chat function. The widget is configured using 'expression'. This expression specifies the initial messages - in this case the system message containing the system prompt
311311
LANGUAGE: json
312312
CODE: {
313-
"onChat" : "$chat('https://api.openai.com/v1/chat/completions', query, messages, [], {'model':'gpt-4o-mini'}, {'Authorization': 'openai', 'dj-timeout-seconds': 60})",
314-
"expression" : "{'messages': [{'role': 'system', 'content': 'always answer in a funny way'}]}",
313+
"onChat" : "/* called when a new question is entered in the chat */\n$chat('https://api.openai.com/v1/chat/completions', query, messages, [], {'model':'gpt-4o-mini'}, {'Authorization': 'openai', 'dj-timeout-seconds': 60})",
314+
"expression" : "/* initial chat state with system prompt in messages */\n{'messages': [{'role': 'system', 'content': 'always answer in a funny way'}]}",
315315
"widget" : "aichat"
316316
}
317317

0 commit comments

Comments
 (0)