Skip to content

Commit

Permalink
feat: Added use streaming field
Browse files Browse the repository at this point in the history
  • Loading branch information
ramedina86 committed Nov 15, 2024
1 parent 10a7c5d commit 0e05573
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/writer/workflows_blocks/writerchat.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ def register(cls, type: str):
"desc": "Where the conversation will be stored",
"type": "Text",
},
"useStreaming": {
"name": "Use streaming",
"type": "Text",
"default": "yes",
"options": {
"yes": "Yes",
"no": "No"
}
},
"tools": {
"name": "Tools",
"type": "Tools",
Expand Down Expand Up @@ -78,6 +87,7 @@ def run(self):
import writer.ai

conversation_state_element = self._get_field("conversationStateElement")
use_streaming = self._get_field("useStreaming", False, "yes") == "yes"
tools_raw = self._get_field("tools", True)
tools = []

Expand Down Expand Up @@ -110,12 +120,17 @@ def run(self):

try:
msg = ""
for chunk in conversation.stream_complete(tools=tools):
if chunk.get("content") is None:
chunk["content"] = ""
msg += chunk.get("content")
conversation += chunk
if not use_streaming:
msg = conversation.complete(tools=tools)
conversation += msg
self.evaluator.set_state(conversation_state_element, self.instance_path, conversation, base_context=self.execution_env)
else:
for chunk in conversation.stream_complete(tools=tools):
if chunk.get("content") is None:
chunk["content"] = ""
msg += chunk.get("content")
conversation += chunk
self.evaluator.set_state(conversation_state_element, self.instance_path, conversation, base_context=self.execution_env)
except BaseException:
msg = {
"role": "assistant",
Expand Down

0 comments on commit 0e05573

Please sign in to comment.