Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question]: Correct way to converse with agent with Python api #4147

Open
val-life opened this issue Dec 20, 2024 · 0 comments
Open

[Question]: Correct way to converse with agent with Python api #4147

val-life opened this issue Dec 20, 2024 · 0 comments
Assignees
Labels
question Further information is requested

Comments

@val-life
Copy link

Describe your problem

I follow the Python API Reference but does not work. What should be the correct way to do so.

My Code:

from ragflow_sdk import RAGFlow
api = "<my api key>"
url = "http://<my ip>:9222"
rag_object = RAGFlow(api_key=api, base_url=url)

from ragflow_sdk import Agent
AGENT_ID = "4f1464d0b6ba11efb3570242ac120006"
session = Agent.create_session(AGENT_ID,rag_object)

while True:
    question = input("\n===== User ====\n> ")
    if question.lower() == "end":
        break
    print("\n==== Miss R ====\n")
    
    cont = ""
    for ans in session.ask(question, stream=True):
        print(ans.content[len(cont):], end='', flush=True)
        cont = ans.content

Error:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Cell In[11], line 8
      5 print("\n==== Miss R ====\n")
      7 cont = ""
----> 8 for ans in session.ask(question, stream=True):
      9     print(ans.content[len(cont):], end='', flush=True)
     10     cont = ans.content

File [~/environments/my_env/lib/python3.12/site-packages/ragflow_sdk/modules/session.py:34](http://<my ip>:9956/lab/tree/my_env/lib/python3.12/site-packages/ragflow_sdk/modules/session.py#line=33), in Session.ask(self, question, stream)
     32 if json_data["data"] != True:
     33     answer = json_data["data"]["answer"]
---> 34     reference = json_data["data"]["reference"]
     35     temp_dict = {
     36         "content": answer,
     37         "role": "assistant"
     38     }
     39     if "chunks" in reference:

KeyError: 'reference'
@val-life val-life added the question Further information is requested label Dec 20, 2024
@val-life val-life changed the title [Question]: Converse with agent with Python api. [Question]: Correct way to converse with agent with Python api Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants