AshwinPathi / claude-api-py

Unofficial Python API for Anthropic's Claude LLM
https://pypi.org/project/claude-api-py/
MIT License
118 stars 13 forks source link

Error when using stream request #18

Closed Lxb921006 closed 7 months ago

Lxb921006 commented 1 year ago

The following code is shown def test_claude_stream(): SESSION_KEY = "" client = claude_client.ClaudeClient(SESSION_KEY) organizations = client.get_organizations() resp = client.send_message(organization_uuid=organizations[0]['uuid'], message="vuex usage?", stream=True, attachments=List[AttachmentType], conversation_uuid=Optional[str], timezone=constants.Timezone.LA, model=constants.Model.CLAUDE_2, ) print(resp.__next__())

The error is as follows:

Traceback (most recent call last): File "C:\Users\Administrator\Desktop\chat-claude.py", line 62, in test_claude_stream() File "C:\Users\Administrator\Desktop\chat-claude.py", line 56, in test_claude_stream print(resp.next()) File "C:\Users\Administrator\PycharmProjects\pythonProject1\venv\lib\site-packages\claude\claude_client.py", line 289, in _send_message for streamed_data_chunk in custom_requests.sse( File "C:\Users\Administrator\PycharmProjects\pythonProject1\venv\lib\site-packages\claude\custom_requests.py", line 198, in sse encoded_request_body = json.dumps(request_body).encode() File "D:\python3.9\lib\json__init__.py", line 231, in dumps return _default_encoder.encode(obj) File "D:\python3.9\lib\json\encoder.py", line 199, in encode chunks = self.iterencode(o, _one_shot=True) File "D:\python3.9\lib\json\encoder.py", line 257, in iterencode return _iterencode(o, 0) File "D:\python3.9\lib\json\encoder.py", line 179, in default raise TypeError(f'Object of type {o.class.name} ' TypeError: Object of type _UnionGenericAlias is not JSON serializable

AshwinPathi commented 1 year ago

The complete code does not look like the code that produces the error output from your first message, you don't use the API's send_message() method. Also, your cookie is exposed.