Client for Humanloop API
Project description
humanloop@0.4.0a7
Requirements
Python >=3.7
Installing
pip install humanloop==0.4.0a7
Getting Started
from pprint import pprint
from humanloop import Humanloop, ApiException
humanloop = Humanloop(
api_key="YOUR_API_KEY",
openai_api_key="YOUR_OPENAI_API_KEY",
ai21_api_key="YOUR_AI21_API_KEY",
mock_api_key="YOUR_MOCK_API_KEY",
anthropic_api_key="YOUR_ANTHROPIC_API_KEY",
)
try:
# Chat
chat_response = humanloop.chat(
project="sdk-example",
messages=[
{
"role": "user",
"content": "Explain asynchronous programming.",
}
],
model_config={
"model": "gpt-3.5-turbo",
"max_tokens": -1,
"temperature": 0.7,
"chat_template": [
{
"role": "system",
"content": "You are a helpful assistant who replies in the style of {{persona}}.",
},
],
},
inputs={
"persona": "the pirate Blackbeard",
},
stream=False,
)
pprint(chat_response.body)
pprint(chat_response.body["project_id"])
pprint(chat_response.body["data"][0])
pprint(chat_response.body["provider_responses"])
pprint(chat_response.headers)
pprint(chat_response.status)
pprint(chat_response.round_trip_time)
except ApiException as e:
print("Exception when calling .chat: %s\n" % e)
pprint(e.body)
if e.status == 422:
pprint(e.body["detail"])
pprint(e.headers)
pprint(e.status)
pprint(e.reason)
pprint(e.round_trip_time)
try:
# Complete
complete_response = humanloop.complete(
project="sdk-example",
inputs={
"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]",
},
model_config={
"model": "gpt-3.5-turbo",
"max_tokens": -1,
"temperature": 0.7,
"prompt_template": "Summarize this for a second-grade student:\n\nText:\n{{text}}\n\nSummary:\n",
},
stream=False,
)
pprint(complete_response.body)
pprint(complete_response.body["project_id"])
pprint(complete_response.body["data"][0])
pprint(complete_response.body["provider_responses"])
pprint(complete_response.headers)
pprint(complete_response.status)
pprint(complete_response.round_trip_time)
except ApiException as e:
print("Exception when calling .complete: %s\n" % e)
pprint(e.body)
if e.status == 422:
pprint(e.body["detail"])
pprint(e.headers)
pprint(e.status)
pprint(e.reason)
pprint(e.round_trip_time)
try:
# Feedback
feedback_response = humanloop.feedback(
type="rating",
value="good",
data_id="data_[...]",
user="user@example.com",
)
pprint(feedback_response.body)
pprint(feedback_response.headers)
pprint(feedback_response.status)
pprint(feedback_response.round_trip_time)
except ApiException as e:
print("Exception when calling .feedback: %s\n" % e)
pprint(e.body)
if e.status == 422:
pprint(e.body["detail"])
pprint(e.headers)
pprint(e.status)
pprint(e.reason)
pprint(e.round_trip_time)
try:
# Log
log_response = humanloop.log(
project="sdk-example",
inputs={
"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]",
},
output="Llamas can be friendly and curious if they are trained to be around people, but if they are treated too much like pets when they are young, they can become difficult to handle when they grow up. This means they might spit, kick, and wrestle with their necks.",
source="sdk",
model_config={
"model": "gpt-3.5-turbo",
"max_tokens": -1,
"temperature": 0.7,
"prompt_template": "Summarize this for a second-grade student:\n\nText:\n{{text}}\n\nSummary:\n",
},
)
pprint(log_response.body)
pprint(log_response.headers)
pprint(log_response.status)
pprint(log_response.round_trip_time)
except ApiException as e:
print("Exception when calling .log: %s\n" % e)
pprint(e.body)
if e.status == 422:
pprint(e.body["detail"])
pprint(e.headers)
pprint(e.status)
pprint(e.reason)
pprint(e.round_trip_time)
Async
async
support is available by prepending a
to any method.
import asyncio
from pprint import pprint
from humanloop import Humanloop, ApiException
humanloop = Humanloop(
api_key="YOUR_API_KEY",
openai_api_key="YOUR_OPENAI_API_KEY",
ai21_api_key="YOUR_AI21_API_KEY",
mock_api_key="YOUR_MOCK_API_KEY",
anthropic_api_key="YOUR_ANTHROPIC_API_KEY",
)
async def main():
try:
complete_response = await humanloop.acomplete(
project="sdk-example",
inputs={
"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]",
},
model_config={
"model": "gpt-3.5-turbo",
"max_tokens": -1,
"temperature": 0.7,
"prompt_template": "Summarize this for a second-grade student:\n\nText:\n{{text}}\n\nSummary:\n",
},
stream=False,
)
pprint(complete_response.body)
pprint(complete_response.body["project_id"])
pprint(complete_response.body["data"][0])
pprint(complete_response.body["provider_responses"])
pprint(complete_response.headers)
pprint(complete_response.status)
pprint(complete_response.round_trip_time)
except ApiException as e:
print("Exception when calling .complete: %s\n" % e)
pprint(e.body)
if e.status == 422:
pprint(e.body["detail"])
pprint(e.headers)
pprint(e.status)
pprint(e.reason)
pprint(e.round_trip_time)
asyncio.run(main())
Streaming
Streaming support is available by suffixing a chat
or complete
method with _stream
.
import asyncio
from humanloop import Humanloop
humanloop = Humanloop(
api_key="YOUR_API_KEY",
openai_api_key="YOUR_OPENAI_API_KEY",
ai21_api_key="YOUR_AI21_API_KEY",
mock_api_key="YOUR_MOCK_API_KEY",
anthropic_api_key="YOUR_ANTHROPIC_API_KEY",
)
async def main():
response = await humanloop.chat_stream(
project="sdk-example",
messages=[
{
"role": "user",
"content": "Explain asynchronous programming.",
}
],
model_config={
"model": "gpt-3.5-turbo",
"max_tokens": -1,
"temperature": 0.7,
"chat_template": [
{
"role": "system",
"content": "You are a helpful assistant who replies in the style of {{persona}}.",
},
],
},
inputs={
"persona": "the pirate Blackbeard",
},
)
async for token in response.content:
print(token)
asyncio.run(main())
Author
This Python package is automatically generated by Konfig
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
humanloop-0.4.0a7.tar.gz
(149.4 kB
view details)
Built Distribution
humanloop-0.4.0a7-py3-none-any.whl
(640.6 kB
view details)
File details
Details for the file humanloop-0.4.0a7.tar.gz
.
File metadata
- Download URL: humanloop-0.4.0a7.tar.gz
- Upload date:
- Size: 149.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 204083b65dd40d51bffac87a7986a417ef3f4799797386a860ec381a896ea2e3 |
|
MD5 | 709379522f3e307bec059973c4d43f4e |
|
BLAKE2b-256 | 98edaab5f54e4dee7fad4a4a0cb3770e8cc77b7acd4cb91c1eabfcaf122f022c |
File details
Details for the file humanloop-0.4.0a7-py3-none-any.whl
.
File metadata
- Download URL: humanloop-0.4.0a7-py3-none-any.whl
- Upload date:
- Size: 640.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4dcb8cda6d52eb153ab7d47e85fdddb5567d9b16d5ecdd9fc87294e528b3b1de |
|
MD5 | 0c9ea3514e3b258763d1c28b99a91bb4 |
|
BLAKE2b-256 | 0c74a0a1489b31a46dd0c885a0255a011f462f122519f9909789e195be34083c |