May 17, 2023

Improved Python SDK

We’ve just released a new version of our Python SDK supporting our v4 API!

This brings support for:

  • 💬 Chat mode humanloop.chat(...)
  • 📥 Streaming support humanloop.chat_stream(...)
  • 🕟 Async methods humanloop.acomplete(...)

https://pypi.org/project/humanloop/

Installation

pip install --upgrade humanloop

Example usage

1complete_response = humanloop.complete(
2 project="sdk-example",
3 inputs={
4 "text": "Llamas that are well-socialized and trained to halter and lead after weaning and are very friendly and pleasant to be around. They are extremely curious and most will approach people easily. However, llamas that are bottle-fed or over-socialized and over-handled as youth will become extremely difficult to handle when mature, when they will begin to treat humans as they treat each other, which is characterized by bouts of spitting, kicking and neck wrestling.[33]",
5 },
6 model_config={
7 "model": "gpt-3.5-turbo",
8 "max_tokens": -1,
9 "temperature": 0.7,
10 "prompt_template": "Summarize this for a second-grade student:\n\nText:\n{{text}}\n\nSummary:\n",
11 },
12 stream=False,
13)
14pprint(complete_response)
15pprint(complete_response.project_id)
16pprint(complete_response.data[0])
17pprint(complete_response.provider_responses)

Migration from 0.3.x

For those coming from an older SDK version, this introduces some breaking changes. A brief highlight of the changes:

  • The client initialization step of hl.init(...) is now humanloop = Humanloop(...).
    • Previously provider_api_keys could be provided in hl.init(...). They should now be provided when constructing Humanloop(...) client.
    • 1humanloop = Humanloop(
      2 api_key="YOUR_API_KEY",
      3 openai_api_key="YOUR_OPENAI_API_KEY",
      4 anthropic_api_key="YOUR_ANTHROPIC_API_KEY",
      5)
  • hl.generate(...)’s various call signatures have now been split into individual methods for clarity. The main ones are:
    • humanloop.complete(project, model_config={...}, ...) for a completion with the specified model config parameters.
    • humanloop.complete_deployed(project, ...) for a completion with the project’s active deployment.