Skip to content

[Bug]: session.ask() doesn't support stream=False #6206

Open
@Nalkey

Description

@Nalkey

Self Checks

  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (Language Policy).
  • Non-english title submitions will be closed directly ( 非英文标题的提交将会被直接关闭 ) (Language Policy).
  • Please do not modify this template :) and fill in all the required fields.

RAGFlow workspace code commit ID

c54ec09

RAGFlow image version

v0.17.2 full

Other environment information

Actual behavior

Current result during conversing with assitant/agent with Stream=False

Codes:

`from ragflow_sdk import RAGFlow, Agent

rag_object = RAGFlow(api_key="<YOUR_API_KEY>", base_url="http://<YOUR_BASE_URL>:9380")
AGENT_id = "AGENT_ID"
agent = rag_object.list_agents(id = AGENT_id)[0]
session = agent.create_session()

print("\n===== Miss R ====\n")
print("Hello. What can I do for you?")

while True:
question = input("\n===== User ====\n> ")
print("\n==== Miss R ====\n")

cont = ""
for ans in session.ask(question, stream=False):
    print(ans.content[len(cont):], end='', flush=True)
    cont = ans.content`

Result:

Traceback (most recent call last): File "/tmp/test.py", line 16, in <module> for ans in session.ask(question, stream=False): File "/usr/local/lib/python3.10/dist-packages/ragflow_sdk/modules/session.py", line 46, in ask raise Exception(json_data["message"]) KeyError: 'message'

Expected behavior

Expected:

Codes:

`from ragflow_sdk import RAGFlow, Agent

rag_object = RAGFlow(api_key="<YOUR_API_KEY>", base_url="http://<YOUR_BASE_URL>:9380")
AGENT_id = "AGENT_ID"
agent = rag_object.list_agents(id = AGENT_id)[0]
session = agent.create_session()

print("\n===== Miss R ====\n")
print("Hello. What can I do for you?")

while True:
question = input("\n===== User ====\n> ")
print("\n==== Miss R ====\n")

ans = session.ask(question, stream=False)
print(ans.content)`

Then we can get the awnser.

Steps to reproduce

1. Follow the instructs of https://ragflow.io/docs/dev/python_api_reference#converse-with-agent
2. Change the value of parameter `stream` as `False`
3. Execute the script, and ask your question

Additional information

If we only keep session.ask(), we cannot support streaming and non-streaming at the meanwhile due to the yield.
So we have to create a new function to support the non-streaming senario.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions