snowby666 / poe-api-wrapper

👾 A Python API wrapper for Poe.com. With this, you will have free access to GPT-4, Claude, Llama, Gemini, Mistral and more! 🚀
https://pypi.org/project/poe-api-wrapper/
GNU General Public License v3.0
959 stars 114 forks source link

API Does not work - send_message Method Output erroring #45 #63

Closed gullpavon closed 5 months ago

gullpavon commented 1 year ago

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.

snowby666 commented 1 year ago

Did you update to the latest version?

gullpavon commented 1 year ago

yes