poe-api-wrapper icon indicating copy to clipboard operation
poe-api-wrapper copied to clipboard

API Does not work - send_message Method Output erroring #45

Open gullpavon opened this issue 1 year ago • 2 comments

When I try to access the response from the send_message method in a loop, I am receiving a TypeError stating that string indices must be integers, not 'str'. Here is a snippet of the code I am using:

bot = "a2"
message = "What is reverse engineering?"

# Create new chat thread
# Streamed example:
for chunk in client.send_message(bot, message):
    print(chunk["response"], end="", flush=True)
print("\n")

Exact Error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[177], line 7
      4 # Create new chat thread
      5 # Streamed example:
      6 for chunk in client.send_message(bot, message):
----> 7     print(chunk["response"], end="", flush=True)
      8 print("\n")

TypeError: string indices must be integers, not 'str'

Rather, when I print chunk to see what's happening, the code produced the following output, where each character is printed separately, rather than providing a cohesive message or data object:

R
e
v
e
r
s
e
 
e
n
g
.
.
.

From the output, it seems that the client.send_message method is returning a string instead of a more structured data type like a list or a generator of messages. This is causing the for loop to iterate over each character in the string individually.

Any guidance on how to modify this code to correctly greatly appreciated.

gullpavon avatar Oct 01 '23 16:10 gullpavon

Did you update to the latest version?

snowby666 avatar Oct 01 '23 17:10 snowby666

yes

gullpavon avatar Oct 07 '23 19:10 gullpavon