writer 0.8.3rc21__py3-none-any.whl → 1.25.1rc1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- writer/ai/__init__.py +277 -28
- writer/app_runner.py +236 -32
- writer/app_templates/default/.wf/components-blueprints_blueprint-0-0decp3w5erhvl0nw.jsonl +11 -0
- writer/app_templates/default/.wf/components-page-0-c0f99a9e-5004-4e75-a6c6-36f17490b134.jsonl +22 -10
- writer/app_templates/default/.wf/components-root.jsonl +1 -1
- writer/app_templates/default/.wf/components-workflows_root.jsonl +1 -0
- writer/app_templates/default/.wf/components-workflows_workflow-0-lfltcky7l1fsm6j2.jsonl +1 -0
- writer/app_templates/default/.wf/metadata.json +1 -1
- writer/app_templates/default/README.md +3 -0
- writer/app_templates/default/main.py +8 -5
- writer/app_templates/default/requirements.txt +1 -0
- writer/app_templates/default/static/agent_builder_demo.png +0 -0
- writer/app_templates/hello/main.py +3 -0
- writer/auth.py +7 -2
- writer/autogen.py +26 -9
- writer/blocks/__init__.py +21 -1
- writer/blocks/addtostatelist.py +5 -4
- writer/blocks/apitrigger.py +45 -0
- writer/blocks/base_block.py +134 -14
- writer/blocks/changepage.py +1 -1
- writer/blocks/code.py +27 -11
- writer/blocks/crontrigger.py +49 -0
- writer/blocks/foreach.py +3 -3
- writer/blocks/httprequest.py +8 -24
- writer/blocks/ifelse.py +71 -0
- writer/blocks/logmessage.py +2 -2
- writer/blocks/returnvalue.py +2 -2
- writer/blocks/runblueprint.py +2 -2
- writer/blocks/setstate.py +5 -5
- writer/blocks/sharedblueprint.py +86 -0
- writer/blocks/writeraddchatmessage.py +45 -7
- writer/blocks/writeraddtokg.py +31 -4
- writer/blocks/writeraskkg.py +27 -34
- writer/blocks/writerchat.py +14 -9
- writer/blocks/writerchatreply.py +279 -0
- writer/blocks/writerchatreplywithtoolconfig.py +393 -0
- writer/blocks/writerclassification.py +42 -5
- writer/blocks/writercompletion.py +4 -4
- writer/blocks/writerfileapi.py +4 -4
- writer/blocks/writerinitchat.py +5 -4
- writer/blocks/writerkeyvaluestorage.py +106 -0
- writer/blocks/writernocodeapp.py +4 -4
- writer/blocks/writerparsepdf.py +8 -6
- writer/blocks/writerstructuredoutput.py +105 -0
- writer/blocks/writertoolcalling.py +106 -51
- writer/blocks/writervision.py +141 -0
- writer/blocks/writerwebsearch.py +175 -0
- writer/blueprints.py +715 -251
- writer/command_line.py +52 -16
- writer/core.py +200 -35
- writer/core_ui.py +4 -0
- writer/evaluator.py +38 -24
- writer/journal.py +227 -0
- writer/keyvalue_storage.py +93 -0
- writer/logs.py +277 -0
- writer/serve.py +402 -198
- writer/ss_types.py +41 -0
- writer/static/assets/BaseMarkdown-Wrvby5J8.js +1 -0
- writer/static/assets/BlueprintToolbar-BuXNRxWT.js +1 -0
- writer/static/assets/BlueprintToolbar-wpfX0jo_.css +1 -0
- writer/static/assets/BuilderApp-PTOI76jZ.js +8 -0
- writer/static/assets/BuilderApp-WimUfNZr.css +1 -0
- writer/static/assets/BuilderApplicationSelect-DXzy4e_h.js +7 -0
- writer/static/assets/BuilderApplicationSelect-XaM1D5fv.css +1 -0
- writer/static/assets/BuilderBlueprintLibraryPanel-Ckrhknlh.css +1 -0
- writer/static/assets/BuilderBlueprintLibraryPanel-DBDzhTlc.js +1 -0
- writer/static/assets/{BuilderEmbeddedCodeEditor-DiDqfWdt.css → BuilderEmbeddedCodeEditor-B0bcjlhk.css} +1 -1
- writer/static/assets/{BuilderEmbeddedCodeEditor-CbK-r9w6.js → BuilderEmbeddedCodeEditor-Dn7eDICN.js} +7 -7
- writer/static/assets/BuilderGraphSelect-C-LRsO8W.js +7 -0
- writer/static/assets/BuilderGraphSelect-D7B61d5s.css +1 -0
- writer/static/assets/{BuilderInsertionLabel-CDlWX-mE.js → BuilderInsertionLabel-BhyL9wgn.js} +1 -1
- writer/static/assets/{BuilderInsertionOverlay-B7-TsHNC.js → BuilderInsertionOverlay-MkAIVruY.js} +1 -1
- writer/static/assets/BuilderJournal-A0LcEwGI.js +7 -0
- writer/static/assets/BuilderJournal-DHv3Pvvm.css +1 -0
- writer/static/assets/BuilderModelSelect-CdSo_sih.js +7 -0
- writer/static/assets/BuilderModelSelect-Dc4IPLp2.css +1 -0
- writer/static/assets/BuilderSettings-BDwZBveu.js +16 -0
- writer/static/assets/BuilderSettings-lZkOXEYw.css +1 -0
- writer/static/assets/BuilderSettingsArtifactAPITriggerDetails-3O6jKBXD.js +4 -0
- writer/static/assets/BuilderSettingsArtifactAPITriggerDetails-DnX66iRg.css +1 -0
- writer/static/assets/BuilderSettingsDeploySharedBlueprint-BR_3ptsd.js +1 -0
- writer/static/assets/BuilderSettingsDeploySharedBlueprint-KJTl8gxP.css +1 -0
- writer/static/assets/BuilderSettingsHandlers-CBtEQFSo.js +1 -0
- writer/static/assets/BuilderSettingsHandlers-DJPeASfz.css +1 -0
- writer/static/assets/BuilderSidebarComponentTree-DLltgas5.js +1 -0
- writer/static/assets/BuilderSidebarComponentTree-DYu1F793.css +1 -0
- writer/static/assets/BuilderSidebarToolkit-CApZNTAq.js +7 -0
- writer/static/assets/BuilderSidebarToolkit-CwqbjRv8.css +1 -0
- writer/static/assets/BuilderTemplateEditor-CYSDeWgV.css +1 -0
- writer/static/assets/BuilderTemplateEditor-DnRDRcA0.js +87 -0
- writer/static/assets/BuilderVault-2vGoV0sx.js +1 -0
- writer/static/assets/BuilderVault-Cx6oQSES.css +1 -0
- writer/static/assets/ComponentRenderer-72hqvEvI.css +1 -0
- writer/static/assets/ComponentRenderer-D4Pj1i3s.js +1 -0
- writer/static/assets/SharedCopyClipboardButton-BipJKGtz.css +1 -0
- writer/static/assets/SharedCopyClipboardButton-DNI9kLe6.js +1 -0
- writer/static/assets/WdsCheckbox-DKvpPA4D.css +1 -0
- writer/static/assets/WdsCheckbox-edQcn1cf.js +1 -0
- writer/static/assets/WdsDropdownMenu-CzzPN9Wg.css +1 -0
- writer/static/assets/WdsDropdownMenu-DQnrRBNV.js +1 -0
- writer/static/assets/WdsFieldWrapper-Cmufx5Nj.js +1 -0
- writer/static/assets/WdsFieldWrapper-CsemOh8D.css +1 -0
- writer/static/assets/WdsTabs-DKj7BqI0.css +1 -0
- writer/static/assets/WdsTabs-DcfY_zn5.js +1 -0
- writer/static/assets/{art-paper-WsD9P5Lu.svg → art-paper-D70v1WMA.svg} +0 -1
- writer/static/assets/{cssMode-6B7VrieQ.js → cssMode-BYq4oZGq.js} +1 -1
- writer/static/assets/{freemarker2-Dy54TNCQ.js → freemarker2-CnNourkO.js} +1 -1
- writer/static/assets/{handlebars-BnWqX2x5.js → handlebars-Bm22yapJ.js} +1 -1
- writer/static/assets/{html-CIuj_eOg.js → html-CAKAfoZF.js} +1 -1
- writer/static/assets/{htmlMode-5fUQN2xJ.js → htmlMode-BGZ97n-V.js} +1 -1
- writer/static/assets/index-BKNuk68o.css +1 -0
- writer/static/assets/index-BQNXU3IR.js +17 -0
- writer/static/assets/index-DHXAd5Yn.js +4 -0
- writer/static/assets/index-Zki-pfO-.js +8525 -0
- writer/static/assets/index.esm-B1ZQtduY.js +17 -0
- writer/static/assets/{javascript-PLzaI1wY.js → javascript-X1f02eyK.js} +1 -1
- writer/static/assets/{jsonMode-CzZfZ4-D.js → jsonMode-hT0bNgT8.js} +1 -1
- writer/static/assets/{liquid-Cy21vWLb.js → liquid-KmCCiJw2.js} +1 -1
- writer/static/assets/{mapbox-gl-BjXsUCYi.js → mapbox-gl-C0cyFYYW.js} +1 -1
- writer/static/assets/{mdx-Cgik3q5p.js → mdx-DtRFauUw.js} +1 -1
- writer/static/assets/pdf-B6-yWJ-Y.js +12 -0
- writer/static/assets/pdf.worker.min-CyUfim15.mjs +21 -0
- writer/static/assets/{plotly.min-Dk-1ahEu.js → plotly.min-DutuuatZ.js} +1 -1
- writer/static/assets/{python-h6gjz_bN.js → python-DVhxg746.js} +1 -1
- writer/static/assets/{razor-BQ1k9241.js → razor-DR5Ns_BC.js} +1 -1
- writer/static/assets/{tsMode-BaBWt05D.js → tsMode-BNUEZzir.js} +1 -1
- writer/static/assets/{typescript-B42-gYGT.js → typescript-CRVt7Hx0.js} +1 -1
- writer/static/assets/useBlueprintRun-C00bCxh-.js +1 -0
- writer/static/assets/useKeyValueEditor-nDmI7cTJ.js +1 -0
- writer/static/assets/useListResources-DLkZhRSJ.js +1 -0
- writer/static/assets/{xml-BOez4Prd.js → xml-C_6-t1tb.js} +1 -1
- writer/static/assets/{yaml-BQhoEOIz.js → yaml-DIw8G7jk.js} +1 -1
- writer/static/components/annotatedtext.svg +3 -3
- writer/static/components/avatar.svg +3 -3
- writer/static/components/blueprints_addtostatelist.svg +3 -3
- writer/static/components/blueprints_apitrigger.svg +4 -0
- writer/static/components/blueprints_category_Logic.svg +3 -3
- writer/static/components/blueprints_category_Other.svg +3 -3
- writer/static/components/blueprints_category_Writer.svg +24 -5
- writer/static/components/blueprints_code.svg +6 -6
- writer/static/components/blueprints_crontrigger.svg +6 -0
- writer/static/components/blueprints_foreach.svg +3 -3
- writer/static/components/blueprints_httprequest.svg +6 -6
- writer/static/components/blueprints_logmessage.svg +10 -3
- writer/static/components/blueprints_parsejson.svg +3 -3
- writer/static/components/blueprints_returnvalue.svg +3 -3
- writer/static/components/blueprints_runblueprint.svg +3 -3
- writer/static/components/blueprints_setstate.svg +3 -3
- writer/static/components/blueprints_writeraddchatmessage.svg +14 -6
- writer/static/components/blueprints_writeraddtokg.svg +14 -6
- writer/static/components/blueprints_writerchatreply.svg +19 -0
- writer/static/components/blueprints_writerclassification.svg +23 -8
- writer/static/components/blueprints_writercompletion.svg +13 -5
- writer/static/components/blueprints_writernocodeapp.svg +13 -3
- writer/static/components/button.svg +3 -3
- writer/static/components/category_Content.svg +3 -3
- writer/static/components/category_Embed.svg +3 -3
- writer/static/components/category_Input.svg +4 -4
- writer/static/components/category_Layout.svg +6 -6
- writer/static/components/category_Other.svg +3 -3
- writer/static/components/chatbot.svg +3 -3
- writer/static/components/checkboxinput.svg +3 -3
- writer/static/components/colorinput.svg +6 -6
- writer/static/components/column.svg +3 -3
- writer/static/components/columns.svg +3 -3
- writer/static/components/dataframe.svg +3 -3
- writer/static/components/dateinput.svg +3 -3
- writer/static/components/dropdowninput.svg +4 -4
- writer/static/components/fileinput.svg +3 -3
- writer/static/components/googlemaps.svg +3 -3
- writer/static/components/heading.svg +6 -6
- writer/static/components/horizontalstack.svg +3 -3
- writer/static/components/html.svg +6 -6
- writer/static/components/icon.svg +3 -3
- writer/static/components/iframe.svg +3 -3
- writer/static/components/image.svg +10 -3
- writer/static/components/jsonviewer.svg +3 -3
- writer/static/components/link.svg +7 -7
- writer/static/components/mapbox.svg +3 -3
- writer/static/components/message.svg +3 -3
- writer/static/components/metric.svg +3 -3
- writer/static/components/multiselectinput.svg +3 -3
- writer/static/components/numberinput.svg +3 -3
- writer/static/components/pagination.svg +3 -3
- writer/static/components/pdf.svg +3 -3
- writer/static/components/plotlygraph.svg +6 -6
- writer/static/components/progressbar.svg +4 -4
- writer/static/components/radioinput.svg +3 -3
- writer/static/components/rangeinput.svg +3 -3
- writer/static/components/ratinginput.svg +3 -3
- writer/static/components/repeater.svg +3 -3
- writer/static/components/reuse.svg +3 -3
- writer/static/components/section.svg +3 -3
- writer/static/components/selectinput.svg +4 -4
- writer/static/components/separator.svg +3 -3
- writer/static/components/sidebar.svg +3 -3
- writer/static/components/sliderinput.svg +3 -3
- writer/static/components/step.svg +3 -3
- writer/static/components/steps.svg +3 -3
- writer/static/components/switchinput.svg +3 -3
- writer/static/components/tab.svg +3 -3
- writer/static/components/tabs.svg +3 -3
- writer/static/components/tags.svg +10 -3
- writer/static/components/text.svg +3 -3
- writer/static/components/textareainput.svg +10 -3
- writer/static/components/textinput.svg +3 -3
- writer/static/components/timeinput.svg +3 -3
- writer/static/components/timer.svg +3 -3
- writer/static/components/videoplayer.svg +10 -3
- writer/static/components/webcamcapture.svg +3 -3
- writer/static/index.html +3 -11
- writer/static/status/cancelled.svg +5 -0
- writer/static/status/skipped.svg +4 -0
- writer/static/status/stopped.svg +4 -0
- writer/sync.py +431 -0
- writer/ui.py +49 -41
- writer/vault.py +48 -0
- writer/wf_project.py +5 -5
- writer-1.25.1rc1.dist-info/METADATA +92 -0
- writer-1.25.1rc1.dist-info/RECORD +382 -0
- {writer-0.8.3rc21.dist-info → writer-1.25.1rc1.dist-info}/WHEEL +1 -1
- writer/app_templates/default/.wf/components-blueprints_blueprint-0-t84xyhxau9ej3823.jsonl +0 -18
- writer/app_templates/default/static/welcome.svg +0 -40
- writer/static/assets/BaseMarkdown-BH_nSq9H.js +0 -1
- writer/static/assets/BlueprintToolbar-BO-WERxH.css +0 -1
- writer/static/assets/BlueprintToolbar-CHWL-rTm.js +0 -1
- writer/static/assets/BuilderApp-0XXiQ2l7.js +0 -7
- writer/static/assets/BuilderApp-CAhvLO4a.css +0 -1
- writer/static/assets/BuilderApplicationSelect-CwzU4F1-.js +0 -7
- writer/static/assets/BuilderApplicationSelect-DYYFtqjx.css +0 -1
- writer/static/assets/BuilderGraphSelect-CVO4gzts.css +0 -1
- writer/static/assets/BuilderGraphSelect-DV5Xy0HK.js +0 -7
- writer/static/assets/BuilderInstanceTracker-BECcXNnW.css +0 -1
- writer/static/assets/BuilderInstanceTracker-Dr0XhpSH.js +0 -1
- writer/static/assets/BuilderModelSelect-QHUGd86u.css +0 -1
- writer/static/assets/BuilderModelSelect-ow0XEf2t.js +0 -7
- writer/static/assets/BuilderSettings-C2WRfSor.css +0 -1
- writer/static/assets/BuilderSettings-D5bjbcWj.js +0 -24
- writer/static/assets/BuilderSettingsHandlers-1QLaHR8J.css +0 -1
- writer/static/assets/BuilderSettingsHandlers-j1aMAV4J.js +0 -1
- writer/static/assets/BuilderSidebarComponentTree-0YajaJke.css +0 -1
- writer/static/assets/BuilderSidebarComponentTree-CtaOZfpV.js +0 -1
- writer/static/assets/BuilderSidebarPanel-BMJVzhd3.js +0 -1
- writer/static/assets/BuilderSidebarPanel-BrLsNxVM.css +0 -1
- writer/static/assets/BuilderSidebarToolkit-BbjOOp8E.js +0 -1
- writer/static/assets/BuilderSidebarToolkit-BvZDShKD.css +0 -1
- writer/static/assets/ComponentRenderer-B76bKRZO.css +0 -1
- writer/static/assets/ComponentRenderer-CZs4z773.js +0 -1
- writer/static/assets/SharedMoreDropdown-BWKlox8E.css +0 -1
- writer/static/assets/SharedMoreDropdown-DKv_HNef.js +0 -7
- writer/static/assets/WdsDropdownMenu-C1UyKOJR.css +0 -1
- writer/static/assets/WdsDropdownMenu-CGiATY2E.js +0 -1
- writer/static/assets/WdsLoaderDots-qdyk2N-2.js +0 -1
- writer/static/assets/index-BJMAe9SN.js +0 -8
- writer/static/assets/index-CPCeQU9V.css +0 -1
- writer/static/assets/index-ChWW_c_j.js +0 -439
- writer/static/assets/instancePath-BsbOTTI8.js +0 -1
- writer/static/assets/material-symbols-outlined-latin-wght-normal-DuE-q1Ez.woff2 +0 -0
- writer/static/assets/useBlueprintRun-CBOvzWTA.js +0 -1
- writer/static/assets/useComponentDescription-FHKxu8gg.js +0 -1
- writer/static/assets/useListResources-BpMgq7XI.js +0 -1
- writer-0.8.3rc21.dist-info/METADATA +0 -117
- writer-0.8.3rc21.dist-info/RECORD +0 -342
- {writer-0.8.3rc21.dist-info → writer-1.25.1rc1.dist-info}/entry_points.txt +0 -0
- {writer-0.8.3rc21.dist-info → writer-1.25.1rc1.dist-info/licenses}/LICENSE.txt +0 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import json
|
|
2
|
+
import re
|
|
2
3
|
|
|
3
4
|
from writer.abstract import register_abstract_template
|
|
4
5
|
from writer.blocks.base_block import WriterBlock
|
|
@@ -27,7 +28,7 @@ class WriterClassification(WriterBlock):
|
|
|
27
28
|
"name": "Categories",
|
|
28
29
|
"type": "Key-Value",
|
|
29
30
|
"default": "{}",
|
|
30
|
-
"desc": "The keys should be the categories you want to classify the text
|
|
31
|
+
"desc": "The keys should be the categories you want to classify the text into, for example 'valid' and 'invalid', and the values are the criteria for each category. Category names should contain only letters of the English alphabet, digits, underscores, and spaces.",
|
|
31
32
|
},
|
|
32
33
|
"additionalContext": {
|
|
33
34
|
"name": "Additional context",
|
|
@@ -40,7 +41,7 @@ class WriterClassification(WriterBlock):
|
|
|
40
41
|
"category": {"field": "categories", "style": "dynamic"},
|
|
41
42
|
"error": {
|
|
42
43
|
"name": "Error",
|
|
43
|
-
"description": "
|
|
44
|
+
"description": "There was an error classifying the text.",
|
|
44
45
|
"style": "error",
|
|
45
46
|
},
|
|
46
47
|
},
|
|
@@ -55,6 +56,12 @@ class WriterClassification(WriterBlock):
|
|
|
55
56
|
text = self._get_field("text", required=True)
|
|
56
57
|
additional_context = self._get_field("additionalContext")
|
|
57
58
|
categories = self._get_field("categories", as_json=True, required=True)
|
|
59
|
+
conversation = writer.ai.Conversation()
|
|
60
|
+
|
|
61
|
+
invalid_categories = [category for category in categories if not re.fullmatch(r"[\w ]+", category, flags=re.ASCII)]
|
|
62
|
+
if invalid_categories:
|
|
63
|
+
self.outcome = "error"
|
|
64
|
+
raise ValueError(f"Category names should contain only letters of the English alphabet, digits, underscores and spaces. Invalid categories: {', '.join(invalid_categories)}")
|
|
58
65
|
|
|
59
66
|
config = {}
|
|
60
67
|
|
|
@@ -73,9 +80,39 @@ CONTENT:
|
|
|
73
80
|
------
|
|
74
81
|
{ text }
|
|
75
82
|
"""
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
83
|
+
|
|
84
|
+
response_format = {
|
|
85
|
+
"type": "json_schema",
|
|
86
|
+
"json_schema": {
|
|
87
|
+
"schema": {
|
|
88
|
+
"type": "string",
|
|
89
|
+
"enum": list(categories.keys())
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
conversation += {
|
|
95
|
+
"role": "user",
|
|
96
|
+
"content": prompt,
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
msg = conversation.complete(response_format=response_format, config=config)
|
|
100
|
+
raw_content = msg.get("content")
|
|
101
|
+
if not raw_content:
|
|
102
|
+
self.outcome = "error"
|
|
103
|
+
raise RuntimeError("No content returned from the model. Please validate the prompt and model configuration.")
|
|
104
|
+
|
|
105
|
+
try:
|
|
106
|
+
# Attempt to parse the raw content as JSON
|
|
107
|
+
category_result = json.loads(raw_content)
|
|
108
|
+
except json.JSONDecodeError:
|
|
109
|
+
self.outcome = "error"
|
|
110
|
+
raise RuntimeError(
|
|
111
|
+
f"Failed to decode JSON content. The raw content was: {raw_content}. Please validate the prompt and model configuration."
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
self.result = category_result
|
|
115
|
+
self.outcome = f"category_{category_result}"
|
|
79
116
|
except BaseException as e:
|
|
80
117
|
self.outcome = "error"
|
|
81
118
|
raise e
|
|
@@ -2,7 +2,7 @@ from writer.abstract import register_abstract_template
|
|
|
2
2
|
from writer.blocks.base_block import WriterBlock
|
|
3
3
|
from writer.ss_types import AbstractTemplate
|
|
4
4
|
|
|
5
|
-
DEFAULT_MODEL = "palmyra-
|
|
5
|
+
DEFAULT_MODEL = "palmyra-x5"
|
|
6
6
|
|
|
7
7
|
class WriterCompletion(WriterBlock):
|
|
8
8
|
@classmethod
|
|
@@ -36,19 +36,19 @@ class WriterCompletion(WriterBlock):
|
|
|
36
36
|
"validator": {
|
|
37
37
|
"type": "number",
|
|
38
38
|
"minimum": 1,
|
|
39
|
-
"maximum":
|
|
39
|
+
"maximum": 16384,
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
},
|
|
43
43
|
"outs": {
|
|
44
44
|
"success": {
|
|
45
45
|
"name": "Success",
|
|
46
|
-
"description": "
|
|
46
|
+
"description": "Text was generated successfully.",
|
|
47
47
|
"style": "success",
|
|
48
48
|
},
|
|
49
49
|
"error": {
|
|
50
50
|
"name": "Error",
|
|
51
|
-
"description": "
|
|
51
|
+
"description": "There was an error generating text.",
|
|
52
52
|
"style": "error",
|
|
53
53
|
},
|
|
54
54
|
},
|
writer/blocks/writerfileapi.py
CHANGED
|
@@ -13,7 +13,7 @@ class WriterUploadFile(WriterBlock):
|
|
|
13
13
|
register_abstract_template(type, AbstractTemplate(
|
|
14
14
|
baseType="blueprints_node",
|
|
15
15
|
writer={
|
|
16
|
-
"name": "Add files to Writer
|
|
16
|
+
"name": "Add files to Writer cloud",
|
|
17
17
|
"description": "Uploads files to the Writer platform.",
|
|
18
18
|
"category": "Writer",
|
|
19
19
|
"fields": {
|
|
@@ -21,7 +21,7 @@ class WriterUploadFile(WriterBlock):
|
|
|
21
21
|
"name": "Files",
|
|
22
22
|
"type": "Object",
|
|
23
23
|
"default": "[]",
|
|
24
|
-
"desc": "A list of files to be uploaded
|
|
24
|
+
"desc": "A list of files to be uploaded to the Writer platform. You can use files uploaded via the File input component or specify dictionaries with data, type and name.",
|
|
25
25
|
"validator": {
|
|
26
26
|
"type": "array"
|
|
27
27
|
}
|
|
@@ -35,7 +35,7 @@ class WriterUploadFile(WriterBlock):
|
|
|
35
35
|
},
|
|
36
36
|
"error": {
|
|
37
37
|
"name": "Error",
|
|
38
|
-
"description": "
|
|
38
|
+
"description": "There was an error uploading the files.",
|
|
39
39
|
"style": "error"
|
|
40
40
|
}
|
|
41
41
|
}
|
|
@@ -73,7 +73,7 @@ class WriterUploadFile(WriterBlock):
|
|
|
73
73
|
"id": file.id,
|
|
74
74
|
"name": file.name,
|
|
75
75
|
"status": file.status,
|
|
76
|
-
"created_at": file.created_at,
|
|
76
|
+
"created_at": file.created_at.isoformat(),
|
|
77
77
|
"graph_ids": file.graph_ids
|
|
78
78
|
})
|
|
79
79
|
if len(outputs) == 0:
|
writer/blocks/writerinitchat.py
CHANGED
|
@@ -2,7 +2,7 @@ from writer.abstract import register_abstract_template
|
|
|
2
2
|
from writer.blocks.base_block import WriterBlock
|
|
3
3
|
from writer.ss_types import AbstractTemplate, WriterConfigurationError
|
|
4
4
|
|
|
5
|
-
DEFAULT_MODEL = "palmyra-
|
|
5
|
+
DEFAULT_MODEL = "palmyra-x5"
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
class WriterInitChat(WriterBlock):
|
|
@@ -16,6 +16,7 @@ class WriterInitChat(WriterBlock):
|
|
|
16
16
|
"name": "Start chat conversation",
|
|
17
17
|
"description": "Starts a new chat conversation. Use to initialize context for AI interactions.",
|
|
18
18
|
"category": "Writer",
|
|
19
|
+
"deprecated": True,
|
|
19
20
|
"fields": {
|
|
20
21
|
"conversationStateElement": {
|
|
21
22
|
"name": "Conversation state element",
|
|
@@ -44,19 +45,19 @@ class WriterInitChat(WriterBlock):
|
|
|
44
45
|
"validator": {
|
|
45
46
|
"type": "number",
|
|
46
47
|
"minimum": 1,
|
|
47
|
-
"maximum":
|
|
48
|
+
"maximum": 16384,
|
|
48
49
|
}
|
|
49
50
|
}
|
|
50
51
|
},
|
|
51
52
|
"outs": {
|
|
52
53
|
"success": {
|
|
53
54
|
"name": "Success",
|
|
54
|
-
"description": "
|
|
55
|
+
"description": "The conversation was initialized.",
|
|
55
56
|
"style": "success",
|
|
56
57
|
},
|
|
57
58
|
"error": {
|
|
58
59
|
"name": "Error",
|
|
59
|
-
"description": "
|
|
60
|
+
"description": "There was an error initializing the conversation.",
|
|
60
61
|
"style": "error",
|
|
61
62
|
},
|
|
62
63
|
},
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import re
|
|
2
|
+
|
|
3
|
+
from writer.abstract import register_abstract_template
|
|
4
|
+
from writer.blocks.base_block import WriterBlock
|
|
5
|
+
from writer.ss_types import AbstractTemplate, WriterConfigurationError
|
|
6
|
+
|
|
7
|
+
ALLOWED_CHARS = re.compile(r'^[A-Za-z0-9\-_]+$')
|
|
8
|
+
|
|
9
|
+
class WriterKeyValueStorage(WriterBlock):
|
|
10
|
+
@classmethod
|
|
11
|
+
def register(cls, type: str):
|
|
12
|
+
super(WriterKeyValueStorage, cls).register(type)
|
|
13
|
+
register_abstract_template(
|
|
14
|
+
type,
|
|
15
|
+
AbstractTemplate(
|
|
16
|
+
baseType="blueprints_node",
|
|
17
|
+
writer={
|
|
18
|
+
"name": "Key-Value Storage",
|
|
19
|
+
"description": "Stores data between sessions. Uses unique keys (names) to identify the data. Keys can only contain alphanumeric characters, underscores, and hyphens.",
|
|
20
|
+
"category": "Writer",
|
|
21
|
+
"fields": {
|
|
22
|
+
"action": {
|
|
23
|
+
"name": "Action",
|
|
24
|
+
"type": "Text",
|
|
25
|
+
"description": "What action to perform on the data (save, get, delete, list all keys).",
|
|
26
|
+
"options": {
|
|
27
|
+
"Save": "Save",
|
|
28
|
+
"Get": "Get",
|
|
29
|
+
"Delete": "Delete",
|
|
30
|
+
"List keys": "List keys",
|
|
31
|
+
},
|
|
32
|
+
"default": "Save",
|
|
33
|
+
},
|
|
34
|
+
"key": {
|
|
35
|
+
"name": "Key",
|
|
36
|
+
"type": "Text",
|
|
37
|
+
"description": "Unique identifier of your data that will be used to retrieve, update and delete it.",
|
|
38
|
+
},
|
|
39
|
+
"valueType": {
|
|
40
|
+
"name": "Value type",
|
|
41
|
+
"type": "Text",
|
|
42
|
+
"description": "Specify whether to interpret the value as plain text or JSON.",
|
|
43
|
+
"options": {
|
|
44
|
+
"text": "Plain text",
|
|
45
|
+
"JSON": "JSON",
|
|
46
|
+
},
|
|
47
|
+
"default": "text",
|
|
48
|
+
},
|
|
49
|
+
"value": {
|
|
50
|
+
"name": "Value",
|
|
51
|
+
"type": "Text",
|
|
52
|
+
"description": "Data that you want to store.",
|
|
53
|
+
"control": "Textarea",
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
"outs": {
|
|
57
|
+
"success": {
|
|
58
|
+
"name": "Success",
|
|
59
|
+
"description": "The request was successful.",
|
|
60
|
+
"style": "success",
|
|
61
|
+
},
|
|
62
|
+
"error": {
|
|
63
|
+
"name": "Error",
|
|
64
|
+
"description": "The request wasn't successful.",
|
|
65
|
+
"style": "error",
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
),
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
def run(self):
|
|
73
|
+
try:
|
|
74
|
+
self.result = self._execute_action()
|
|
75
|
+
self.outcome = "success"
|
|
76
|
+
except BaseException as e:
|
|
77
|
+
self.outcome = "error"
|
|
78
|
+
raise e
|
|
79
|
+
|
|
80
|
+
def _execute_action(self):
|
|
81
|
+
from writer.journal import JOURNAL_KEY_PREFIX
|
|
82
|
+
from writer.keyvalue_storage import KeyValueStorage
|
|
83
|
+
|
|
84
|
+
action = self._get_field("action", default_field_value="Save")
|
|
85
|
+
|
|
86
|
+
with self.acquire_httpx_client() as client:
|
|
87
|
+
writer_kv_storage = KeyValueStorage(client=client)
|
|
88
|
+
|
|
89
|
+
if action == "List keys":
|
|
90
|
+
response = writer_kv_storage.get_data_keys()
|
|
91
|
+
return [key for key in response if not key.startswith(JOURNAL_KEY_PREFIX)]
|
|
92
|
+
|
|
93
|
+
key = self._get_field("key", required=True)
|
|
94
|
+
if not ALLOWED_CHARS.fullmatch(key):
|
|
95
|
+
raise WriterConfigurationError("Key can only contain alphanumeric characters, underscores and hyphens")
|
|
96
|
+
|
|
97
|
+
if action == "Save":
|
|
98
|
+
value_type = self._get_field("valueType")
|
|
99
|
+
value = self._get_field("value", as_json=value_type == "JSON")
|
|
100
|
+
return writer_kv_storage.save(key, value)
|
|
101
|
+
if action == "Get":
|
|
102
|
+
return writer_kv_storage.get(key, type_="data")["data"]
|
|
103
|
+
if action == "Delete":
|
|
104
|
+
return writer_kv_storage.delete(key)
|
|
105
|
+
|
|
106
|
+
raise WriterConfigurationError(f"Unknown action for the Key-Value Storage: {action}")
|
writer/blocks/writernocodeapp.py
CHANGED
|
@@ -12,8 +12,8 @@ class WriterNoCodeApp(WriterBlock):
|
|
|
12
12
|
AbstractTemplate(
|
|
13
13
|
baseType="blueprints_node",
|
|
14
14
|
writer={
|
|
15
|
-
"name": "AI Studio
|
|
16
|
-
"description": "Runs
|
|
15
|
+
"name": "AI Studio agent",
|
|
16
|
+
"description": "Runs a Writer AI Studio agent app by ID.",
|
|
17
17
|
"category": "Writer",
|
|
18
18
|
"fields": {
|
|
19
19
|
"appId": {
|
|
@@ -30,12 +30,12 @@ class WriterNoCodeApp(WriterBlock):
|
|
|
30
30
|
"outs": {
|
|
31
31
|
"success": {
|
|
32
32
|
"name": "Success",
|
|
33
|
-
"description": "
|
|
33
|
+
"description": "The agent ran successfully.",
|
|
34
34
|
"style": "success",
|
|
35
35
|
},
|
|
36
36
|
"error": {
|
|
37
37
|
"name": "Error",
|
|
38
|
-
"description": "
|
|
38
|
+
"description": "There was an error running the agent.",
|
|
39
39
|
"style": "error",
|
|
40
40
|
},
|
|
41
41
|
},
|
writer/blocks/writerparsepdf.py
CHANGED
|
@@ -25,23 +25,25 @@ class WriterParsePDFByFileID(WriterBlock):
|
|
|
25
25
|
"type": "string",
|
|
26
26
|
"format": "uuid"
|
|
27
27
|
}
|
|
28
|
-
|
|
28
|
+
},
|
|
29
29
|
"markdown": {
|
|
30
|
-
"name": "
|
|
31
|
-
"type": "
|
|
30
|
+
"name": "Enable markdown",
|
|
31
|
+
"type": "Boolean",
|
|
32
32
|
"default": "yes",
|
|
33
|
-
"
|
|
33
|
+
"validator": {
|
|
34
|
+
"type": "boolean",
|
|
35
|
+
},
|
|
34
36
|
}
|
|
35
37
|
},
|
|
36
38
|
"outs": {
|
|
37
39
|
"success": {
|
|
38
40
|
"name": "Success",
|
|
39
|
-
"description": "
|
|
41
|
+
"description": "The PDF was parsed successfully.",
|
|
40
42
|
"style": "success",
|
|
41
43
|
},
|
|
42
44
|
"error": {
|
|
43
45
|
"name": "Error",
|
|
44
|
-
"description": "
|
|
46
|
+
"description": "There was an error parsing the PDF.",
|
|
45
47
|
"style": "error",
|
|
46
48
|
},
|
|
47
49
|
},
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import json
|
|
2
|
+
|
|
3
|
+
from writer.abstract import register_abstract_template
|
|
4
|
+
from writer.blocks.base_block import WriterBlock
|
|
5
|
+
from writer.ss_types import AbstractTemplate
|
|
6
|
+
|
|
7
|
+
DEFAULT_MODEL = "palmyra-x5"
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class WriterStructuredOutput(WriterBlock):
|
|
11
|
+
@classmethod
|
|
12
|
+
def register(cls, type: str):
|
|
13
|
+
super(WriterStructuredOutput, cls).register(type)
|
|
14
|
+
register_abstract_template(
|
|
15
|
+
type,
|
|
16
|
+
AbstractTemplate(
|
|
17
|
+
baseType="blueprints_node",
|
|
18
|
+
writer={
|
|
19
|
+
"name": "Structured output",
|
|
20
|
+
"description": "Defines a JSON response format that the agent will use to structure its output.",
|
|
21
|
+
"category": "Writer",
|
|
22
|
+
"fields": {
|
|
23
|
+
"prompt": {"name": "Prompt", "type": "Text", "control": "Textarea", "desc": "Description of a JSON object to be created."},
|
|
24
|
+
"modelId": {
|
|
25
|
+
"name": "Model",
|
|
26
|
+
"type": "Model Id",
|
|
27
|
+
"default": DEFAULT_MODEL
|
|
28
|
+
},
|
|
29
|
+
"jsonSchema": {
|
|
30
|
+
"name": "JSON Schema",
|
|
31
|
+
"desc": "JSON schema that defines the structure of the response. For example, `{\"type\": \"object\", \"properties\": {...}, \"required\": [...]}`.",
|
|
32
|
+
"type": "JSON",
|
|
33
|
+
"default": "{}"
|
|
34
|
+
},
|
|
35
|
+
"max_tokens": {
|
|
36
|
+
"name": "Max output tokens",
|
|
37
|
+
"type": "Number",
|
|
38
|
+
"default": "1024",
|
|
39
|
+
"validator": {
|
|
40
|
+
"type": "number",
|
|
41
|
+
"minimum": 1,
|
|
42
|
+
"maximum": 16384,
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"outs": {
|
|
47
|
+
"success": {
|
|
48
|
+
"name": "Success",
|
|
49
|
+
"description": "The structured output was generated.",
|
|
50
|
+
"style": "success",
|
|
51
|
+
},
|
|
52
|
+
"error": {
|
|
53
|
+
"name": "Error",
|
|
54
|
+
"description": "There was an error generating the output.",
|
|
55
|
+
"style": "error",
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
),
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
def run(self):
|
|
63
|
+
import writer.ai
|
|
64
|
+
|
|
65
|
+
try:
|
|
66
|
+
prompt = self._get_field("prompt")
|
|
67
|
+
model_id = self._get_field("modelId", False, default_field_value=DEFAULT_MODEL)
|
|
68
|
+
conversation = writer.ai.Conversation()
|
|
69
|
+
schema = self._get_field("jsonSchema", True, default_field_value="{}")
|
|
70
|
+
max_tokens = int(self._get_field("max_tokens", False, "1024"))
|
|
71
|
+
|
|
72
|
+
response_format = {
|
|
73
|
+
"type": "json_schema",
|
|
74
|
+
"json_schema": {
|
|
75
|
+
"schema": schema
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
conversation += {
|
|
80
|
+
"role": "user",
|
|
81
|
+
"content": prompt,
|
|
82
|
+
}
|
|
83
|
+
config = { "model": model_id, "max_tokens": max_tokens }
|
|
84
|
+
msg = conversation.complete(response_format=response_format, config=config)
|
|
85
|
+
conversation += msg
|
|
86
|
+
|
|
87
|
+
raw_content = msg.get("content")
|
|
88
|
+
if not raw_content:
|
|
89
|
+
self.outcome = "error"
|
|
90
|
+
raise RuntimeError("No content returned from the model. Please validate the prompt and model configuration.")
|
|
91
|
+
|
|
92
|
+
try:
|
|
93
|
+
# Attempt to parse the raw content as JSON
|
|
94
|
+
content = json.loads(raw_content)
|
|
95
|
+
except json.JSONDecodeError:
|
|
96
|
+
self.outcome = "error"
|
|
97
|
+
raise RuntimeError(
|
|
98
|
+
f"Failed to decode JSON content. The raw content was: {raw_content}. Please validate the prompt and model configuration."
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
self.result = content
|
|
102
|
+
self.outcome = "success"
|
|
103
|
+
except BaseException as e:
|
|
104
|
+
self.outcome = "error"
|
|
105
|
+
raise e
|