Skip to content

Commit 5aa089e

Browse files
authored
Merge pull request #1298 from WolframResearch/feature/prompt-improvements
Minor context improvements
2 parents 28677ae + a47a7b2 commit 5aa089e

File tree

3 files changed

+57
-5
lines changed

3 files changed

+57
-5
lines changed

Source/Chatbook/PromptGenerators/RelatedWolframAlphaResults.wl

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,8 +1048,10 @@ formatNaturalLanguageInput // endDefinition;
10481048
(*makeInterpretationCode*)
10491049
makeInterpretationCode // beginDefinition;
10501050

1051-
makeInterpretationCode[ query0_String, code_String ] := Enclose[
1052-
Module[ { query, input },
1051+
makeInterpretationCode[ query0_String, code0_String ] := Enclose[
1052+
Module[ { code, query, input },
1053+
1054+
code = ConfirmBy[ rewriteEntityValueCode @ code0, StringQ, "Code" ];
10531055

10541056
query = StringRiffle @ DeleteCases[ StringTrim @ StringSplit[ query0, { "\\|", "\n" } ], "" ];
10551057

@@ -1079,6 +1081,35 @@ In[1]:= %%Input%%
10791081
During evaluation of In[1]:= [INFO] Interpreted \"%%Query%%\" as: %%Code%%
10801082
```", Delimiters -> "%%" ];
10811083

1084+
(* ::**************************************************************************************************************:: *)
1085+
(* ::Subsubsection::Closed:: *)
1086+
(*rewriteEntityValueCode*)
1087+
rewriteEntityValueCode // beginDefinition;
1088+
1089+
rewriteEntityValueCode[ code_String ] :=
1090+
If[ StringContainsQ[ code, "Entity[" ],
1091+
rewriteEntityValueCode[ code, Quiet @ ToExpression[ code, InputForm, HoldComplete ] ],
1092+
code
1093+
];
1094+
1095+
rewriteEntityValueCode[ code_, held_HoldComplete ] := Enclose[
1096+
Catch @ Module[ { replaced },
1097+
replaced = held /. HoldPattern[ (e_Entity)[ p: _EntityProperty | _String ] ] :> EntityValue[ e, p ];
1098+
If[ replaced === held, Throw @ code ];
1099+
ConfirmBy[
1100+
Replace[ replaced, HoldComplete[ e_ ] :> ToString[ Unevaluated @ e, InputForm ] ],
1101+
StringQ,
1102+
"Result"
1103+
]
1104+
],
1105+
throwInternalFailure
1106+
];
1107+
1108+
rewriteEntityValueCode[ code_, _ ] :=
1109+
code;
1110+
1111+
rewriteEntityValueCode // endDefinition;
1112+
10821113
(* ::**************************************************************************************************************:: *)
10831114
(* ::Subsubsection::Closed:: *)
10841115
(*inputInterpretation*)

Source/Chatbook/PromptGenerators/VectorDatabases.wl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,19 @@ EntityValue[\[FreeformPrompt][\"entity or entity group name(s)\", \"entity type\
7171
{\"property canonical name\", ...}, \"Association\"]
7272
```
7373
74+
The full set of valid values for the third argument of `EntityValue` are:
75+
76+
| Value | Description |
77+
| ----- | --- |
78+
| \"EntityAssociation\" | an association of entities and entity-property values |
79+
| \"PropertyAssociation\" | an association of properties and entity-property values |
80+
| \"EntityPropertyAssociation\" | an association in which the specified entities are keys, and values are a nested association of properties and entity-property values |
81+
| \"PropertyEntityAssociation\" | an association in which the specified properties are keys, and values are a nested association of entities and entity-property values |
82+
| \"Dataset\" | a dataset in which the specified entities are keys, and values are an association of property names and entity-property values |
83+
| \"Association\" | a nested association with entity keys on the first level and property keys on the second level |
84+
| \"NonMissingPropertyAssociation\" | an association of properties and entity-property values with the missing values dropped |
85+
| \"NonMissingEntityAssociation\" | an association of entities and entity-property values with the missing values dropped |
86+
7487
# Filtering entities by property values
7588
7689
If an `EntityProperty` can be used to perform an `EntityClass` lookup, use this syntax with specified patterns for \

Source/Chatbook/Prompting.wl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,18 @@ $basePromptDependencies = Append[ "GeneralInstructionsHeader" ] /@ <|
122122
(*Base Prompt Components*)
123123
$basePromptComponents = <| |>;
124124

125-
$basePromptComponents[ "AgentOnePersona" ] = "\
126-
You are a helpful assistant named \"Wolfram Agent One\" that utilizes Wolfram Language and Wolfram|Alpha to help the user.
125+
$basePromptComponents[ "AgentOnePersona" ] :=
126+
If[ TrueQ @ toolSelectedQ[ "WolframLanguageEvaluator" ],
127+
"You are a helpful assistant named \"Wolfram Agent One\" that utilizes Wolfram Language and Wolfram|Alpha to help the user.
127128
Assume the user does not have access to Wolfram Language unless it's clear from the context that they do.
128-
You specialize in Wolfram Language and Wolfram|Alpha, but you can help with any topic.";
129+
This means that you should evaluate code for them using the wolfram_language_evaluator tool instead of just writing code for them.
130+
ALWAYS use `\[FreeformPrompt][\"query\"]` syntax to obtain Entity, EntityClass, Quantity, etc.
131+
You specialize in Wolfram Language and Wolfram|Alpha, but you can help with any topic."
132+
,
133+
"You are a helpful assistant named \"Wolfram Agent One\" that utilizes Wolfram Language and Wolfram|Alpha to help the user.
134+
Assume the user does not have access to Wolfram Language unless it's clear from the context that they do.
135+
You specialize in Wolfram Language and Wolfram|Alpha, but you can help with any topic."
136+
];
129137

130138
$basePromptComponents[ "AgentOneCoderPersona" ] = "\
131139
You are a helpful assistant named \"Wolfram Agent One Coder\" that utilizes Wolfram Language to help the user.

0 commit comments

Comments
 (0)