cohere-ai / cohere-python

Python Library for Accessing the Cohere API
https://docs.cohere.ai
MIT License
293 stars 64 forks source link

Add Jupyter Lite support for SDK #50

Closed knajjars closed 2 years ago

knajjars commented 2 years ago

How to reproduce:

  1. Go to: https://cohere-ai.github.io/jupyter_lite/repl/?toolbar=1&kernel=python
  2. Add the following code snippet
    import piplite
    await piplite.install("cohere")
    import cohere
    co = cohere.Client('<your_prod_api_key>')
    prediction = co.generate(
    model='xlarge-20220301',
    prompt='The table lists the following professions as artistic careers:\n1. Painter\n2.',
    max_tokens=50,
    temperature=1,
    k=0,
    p=0.75,
    frequency_penalty=0,
    presence_penalty=0,
    stop_sequences=[],
    return_likelihoods='NONE')
    print('Prediction: {}'.format(prediction.generations[0].text))
  3. It fails due to the stdlib used for performing HTTP requests, which is not compatible with Pyodide (Python port for WASM)

Expected behavior:

  1. We should support using the SDK in a Pyodide environment, by either allowing passing a custom http client or building a separate SDK for Pyodide.
alexguo247 commented 2 years ago

https://github.com/cohere-ai/cohere-python/pull/51