from llama_index.core.agent import AgentRunner, ReActAgentWorker, ReActAgent prompt="An interesting question?" task = agent.create_task(prompt) step_output = agent.stream_step(task.task_id) for token in step_output.output.response_gen: print(token, end="")
llm = OpenAI(model="gpt-3.5-turbo") agent = OpenAIAgent.from_tools( [multiply_tool, add_tool], llm=llm, verbose=True ) task = agent.create_task("What is 2123 * 215123") while True: task_result = agent.stream_step(task.task_id) for token in task_result.output.response_gen: print(token, end="") time.sleep(0.2) # sleeping, just to emphasize the streaming if task_result.is_last: break
Cell In[18], line 4 2 while True: 3 task_result = agent.stream_step(task.task_id) ----> 4 for token in task_result.output.response_gen: 5 print(token, end="") 6 time.sleep(0.2) # sleeping, just to emphasize the streaming File ~/Desktop/project/venv/lib/python3.10/site-packages/llama_index/core/chat_engine/types.py:73, in AgentChatResponse.response_gen(self) 71 """Used for fake streaming, i.e. with tool outputs.""" 72 if not self.is_dummy_stream: ---> 73 raise ValueError( 74 "response_gen is only available for streaming responses. " 75 "Set is_dummy_stream=True if you still want a generator." 76 ) 78 for token in self.response.split(" "): 79 yield token + " " ValueError: response_gen is only available for streaming responses. Set is_dummy_stream=True if you still want a generator.