claude api py
1.0.0
Anthropic 的 Claude LLM 的非官方免費 API。
Claude 是 Anthropic 的 LLM 應用程式(類似於 ChatGPT)。該庫允許您使用 API(免費)並在您的 python 專案中與之互動。
非官方 Claude API 正在積極開發。以下端點可用於某些功能:
請注意,API 是同步的。
claude_2
以外的模型該專案正在積極開發中,並且非常不穩定,因此不能保證它適合您。如果您發現錯誤,或者您認為它應該在無法正常工作的情況下工作,請提交問題。
使用以下命令安裝庫:
pip install claude-api-py
如果這不起作用,您可以直接從此 github 儲存庫安裝:
pip install git+git://github.com/AshwinPathi/claude-api-py.git
目前有一個要求:
sseclient-py
連結在這裡從 Claude 網站取得sessionKey
。您將需要它來啟動機器人。理想情況下,您用來存取克勞德的電腦也有一個使用者代理程式。
您可以透過登入https://claude.ai/chats
並執行以下操作來獲取此資訊:
Application
選項卡。Storage
下,前往Cookies
。https://claude.ai
的 cookie,點擊它。sessionKey
字段,然後複製會話金鑰。它應該以sk-ant-sid01...
使用機器人。您可以在example.py
中查看範例。
# The ClaudeClient is the raw API that gives you access to all organization and conversation level API calls
# with a simple python interface. However, you have to pass organization_uuid and conversation_uuid everywhere, so
# its not ideal if you want a simple to use API.
from claude import claude_client
# The ClaudeWrapper takes in a claude client instance and allows you to use a single organization and conversation
# context. This allows you to use the API more ergonomically.
from claude import claude_wrapper
client = claude_client . ClaudeClient ( SESSION_KEY )
organizations = client . get_organizations ()
# You can omit passing in the organization uuid and the wrapper will assume
# you will use the first organization instead.
claude_obj = claude_wrapper . ClaudeWrapper ( client , organization_uuid = organizations [ 0 ][ 'uuid' ])
new_conversation_data = claude_obj . start_new_conversation ( "New Conversation" , "Hi Claude!" )
conversation_uuid = new_conversation_data [ 'uuid' ]
# You can get the response from the initial message you sent with:
initial_response = new_conversation_data [ 'response' ]
# You can get the title of the new chat you created with this:
chat_title = new_conversation_data [ 'title' ]
conversation_uuid = claude_obj . get_conversations ()[ 0 ][ 'uuid' ]
response = claude_obj . send_message ( "How are you doing today!" , conversation_uuid = conversation_uuid )
conversation_uuid = claude_obj . get_conversations ()[ 0 ][ 'uuid' ]
# This is so you don't have to constantly pass in conversation uuid on every call that requires it.
# anywhere that has an argument conversation_uuid=X can be omitted if you set the conversation context.
claude_obj . set_conversation_context ( conversation_uuid )
response = claude_obj . send_message ( "How are you doing today!" )
response = claude_obj . send_message ( "Who won the league of legends worlds 2022 finals?" )
# This generates an attachment in the right format
attachment = claude_obj . get_attachment ( 'example_attachment.txt' )
response = claude_obj . send_message ( "Hi Claude, what does this attachment say?" , attachments = [ attachment ],
conversation_uuid = conversation_uuid )
deleted = claude_obj . delete_conversation ( conversation_uuid )
failed_deletions = claude_obj . delete_all_conversations ()
assert len ( failed_deletions ) == 0
conversation = claude_obj . rename_conversation ( "New name" , conversation_uuid = conversation_uuid )
conversation_history = claude_obj . get_conversation_info ( conversation_uuid = conversation_uuid )
該圖書館純粹用於教育目的,並且是非官方的。如果您的帳戶被禁止,我不承擔任何責任。如果您想使用實際的 API,請造訪 anthropic 網站。