Package: cohere
Cohere Python SDKThis package provides functionality developed to simplify interfacing with theCohere APIin Python 3.5.0.0 alpha 🚀We're nearing the release of our brand new cohere-python SDK! If you'd like to get a head start by installing the alpha version, please go ahead and usepip install --pre --upgrade cohere. Thanks for your patience as we make breaking changes where necessary. If you have any issues using it, we will respond to github issues as soon as possible.See themigration guidefor upgrading and thenew README.mdfor more information and examples.DocumentationSDK Documentation can be foundhere.You can build SDK documentation locally usingcd docs; make clean html.For more details on advanced parameters, you can also consult theAPI documentation.See theexamplesdirectory for examples, including  some additional functionality for visualizations in Jupyter notebooks.InstallationThe package can be installed withpip:pipinstall--upgradecohereInstall from source:pipinstall.RequirementsPython 3.8+Quick StartTo use this library, you must have an API key and specify it as a string when creating thecohere.Clientobject. API keys can be created through theplatform. This is a basic example of the creating the client and using thegenerateendpoint.importcohere# initialize the Cohere Client with an API Keyco=cohere.Client('YOUR_API_KEY')# generate a prediction for a promptprediction=co.chat(message='Howdy! 🤠',model='command')# print the predicted textprint(f'Chatbot:{prediction.text}')There is also an asyncio compatible client calledcohere.AsyncClientwith an equivalent interface. Consult theSDK Docsfor more details.VersioningEach SDK release is only compatible with the latest version of the Cohere API at the time of release. To use the SDK with an older API version, you need to download a version of the SDK tied to the API version you want. Look at theChangelogto see which SDK version to download.EndpointsFor a full breakdown of endpoints and arguments, please consult theSDK DocsandCohere Docs.Cohere EndpointFunction/chatco.chat()/generateco.generate()/embedco.embed()/rerankco.rerank()/classifyco.classify()/tokenizeco.tokenize()/detokenizeco.detokenize()ModelsWhen you call Cohere's APIs we decide on a good default model for your use-case behind the scenes. The default model is great to get you started, but in production environments we recommend that you specify the model size yourself via themodelparameter. Learn more about the available models here(https://dashboard.cohere.com)ResponsesAll of the endpoint functions will return a Cohere object corresponding to the endpoint (e.g. for generation, it would beGeneration). The responses can be found as instance variables of the object (e.g. generation would beGeneration.text). The names of these instance variables and a detailed breakdown of the response body can be found in theSDK DocsandCohere Docs. Printing the Cohere response object itself will display an organized view of the instance variables.ExceptionsUnsuccessful API calls from the SDK will raise an exception. Please see the documentation's page onerrorsfor more information about what the errors mean.ContributingTo set up a development environment, first ensure you havepoetry 1.7+ installedand run:poetryshell# any time you want to run code or testspoetryinstall# install and update dependencies in your environment, the first timeIn addition, to ensure your code is formatted correctly, install pre-commit hooks using:pre-commitinstallYou can run tests locally using:python-mpytestYou can configure a different base url with:CO_API_URL="https://localhost:8050"python3foo.pyor in code using one of:cohere.COHERE_API_URL="https://localhost:8050"# Place before client initilizationcohere.Client(...,api_url="https://localhost:8050")# Alternatively, as a parameter to the Client