Bike4py is a Python client for the Bike4Mind API.
pip install bike4pyTo use the client, you need to create a client with your refresh token:
from bike4py import LLMClient
client = LLMClient(
refresh_token="your_refresh_token"
)Once you've created a client, you should connect to the websocket - this is where responses to your prompt will be sent:
# Connect to websocket, needed to see LLM responses
await client.connect()You can then submit a prompt and stream the response. The notebook ID can be found in the URL of the notebook you want to use.
# Submit a prompt
request = ChatCompletionRequest(
sessionId="%your_notebook_id%",
message="Hello, how are you?"
)
response = client.submit_prompt(request)
# Stream the response
async for event in client.stream_events():
if isinstance(event, StatusEvent):
print(event.status)
if isinstance(event, CompletionEvent):
print(event.success)
if isinstance(event, ContentEvent):
print(event.content)The event classes emitted by the stream_events method are:
StatusEvent: Status updates from the LLM as Bike4Mind is processing the request.ContentEvent: While generating, the LLM will stream content in chunks; this event includes the accumulated progress of the response.CompletionEvent: At completion, this event is emitted with the final response.
The intent is that it's easy to separate the event types and process only the ones you need. If you want streaming content for UI purposes, process the ContentEvent events. If you want to know when the LLM has completed, process the CompletionEvent event.
file_id = client.upload_file("test.txt", "text/plain")This will return a file_id which you can then pass to the submit_prompt method to include in a prompt.
...
file_id = client.upload_file("test.txt", "text/plain")
request = ChatCompletionRequest(
sessionId="%your_notebook_id%",
message="Can you summarize this file for me?",
fabFileIds=[file_id]
)
response = client.submit_prompt(request)
...