claude api py
1.0.0
Anthropic의 Claude LLM을 위한 비공식 무료 API입니다.
Claude는 Anthropic의 LLM 앱입니다(ChatGPT와 유사). 이 라이브러리를 사용하면 API(무료)를 사용하고 Python 프로젝트에서 API와 상호 작용할 수 있습니다.
비공식 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
라는 쿠키를 찾아 클릭하세요.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 홈페이지에 접속하세요.