Skip to main content

Bike4Mind API client

Project description

bike4py

Bike4py is a Python client for the Bike4Mind API.

Installation

pip install bike4py

Usage

To 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.

Upload a file

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)
...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bike4py-0.1.1.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bike4py-0.1.1-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file bike4py-0.1.1.tar.gz.

File metadata

  • Download URL: bike4py-0.1.1.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.12

File hashes

Hashes for bike4py-0.1.1.tar.gz
Algorithm Hash digest
SHA256 50704bffee2ca8d21d8453ff7fa92d3d04ee4ac36dd365d567c0b48491eaf377
MD5 77fdd218449d4d2d7181cff16e02261c
BLAKE2b-256 44daa659a9bbd477757bffdfd7cd403b8c1e6417f20e49e4525edccd45fb9ff8

See more details on using hashes here.

File details

Details for the file bike4py-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: bike4py-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.12

File hashes

Hashes for bike4py-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8195f6bfd493a62bdab2d34f2752134ad4e30c1ee8394ba94aa877335fdf202f
MD5 253662ecd99c98309528514700460fbd
BLAKE2b-256 29f4193819033ab1eca403a275cee552c67aa45596a1cb21d8d05c5548c343de

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page