@@ -15,37 +15,75 @@ The REST API documentation can be found on [docs.bespokelabs.ai](https://docs.be
1515## Installation
1616
1717``` sh
18- # install from PyPI
19- pip install bespokelabs
18+ # install or upgrade from PyPI
19+ pip install --upgrade bespokelabs
2020```
2121
22+ ## Authentication
23+
24+ Set ` BESPOKE_API_KEY ` in your environment:
25+
26+ ``` sh
27+ export BESPOKE_API_KEY=" your-api-key"
28+ ```
29+
30+ The SDK reads this variable automatically when you create a client:
31+
32+ ``` python
33+ from bespokelabs import BespokeLabs
34+
35+ client = BespokeLabs()
36+ ```
37+
38+ You can also pass a key explicitly with ` api_key ` :
39+
40+ ``` python
41+ from bespokelabs import BespokeLabs
42+
43+ client = BespokeLabs(api_key = " your-api-key" )
44+ ```
45+
46+ The same options work with ` AsyncBespokeLabs ` . An explicit ` api_key ` takes
47+ precedence over ` BESPOKE_API_KEY ` . Keep real keys out of source control.
48+
49+ If you keep credentials in a ` .env ` file, install
50+ [ python-dotenv] ( https://pypi.org/project/python-dotenv/ ) and load the file before
51+ creating the client; the SDK does not load ` .env ` files itself:
52+
53+ ``` python
54+ from dotenv import load_dotenv
55+ from bespokelabs import BespokeLabs
56+
57+ load_dotenv() # Loads BESPOKE_API_KEY from .env into the environment.
58+ client = BespokeLabs()
59+ ```
60+
61+ ### Upgrading to 0.4.0
62+
63+ Replace ` auth_token= ` with ` api_key= ` when constructing a client or calling
64+ ` copy() ` or ` with_options() ` . Replace ` client.auth_token ` with ` client.api_key ` .
65+ The ` BESPOKE_API_KEY ` environment variable and HTTP authentication header are
66+ unchanged, so clients configured solely through the environment need no changes.
67+
2268## Usage
2369
2470The full API of this library can be found in [ api.md] ( api.md ) .
2571
2672``` python
27- import os
2873from bespokelabs import BespokeLabs
2974
30- client = BespokeLabs(
31- api_key = os.environ.get(" BESPOKE_API_KEY" ), # This is the default and can be omitted
32- )
75+ client = BespokeLabs() # Reads BESPOKE_API_KEY from the environment.
3376
34- factcheck = client.minicheck.factcheck.create (
35- claim = " claim " ,
36- context = " context " ,
77+ result = client.nimble.system_one (
78+ state = " Please refund the duplicate payment. " ,
79+ questions = { " refund " : { " type " : " noul " , " instructions " : " Refund requested? " }} ,
3780)
38- print (factcheck.support_prob )
81+ print (result.nouls[ " refund " ].noul )
3982```
4083
41- While you can provide an ` api_key ` keyword argument,
42- we recommend using [ python-dotenv] ( https://pypi.org/project/python-dotenv/ )
43- to add ` BESPOKE_API_KEY="My API Key" ` to your ` .env ` file
44- so that your API key is not stored in source control.
45-
4684## Nimble
4785
48- Nimble is available through the same client and ` BESPOKE_API_KEY ` as MiniCheck :
86+ Use Nimble to answer structured questions about text with Noul, Choice, and Score outputs :
4987
5088``` python
5189from bespokelabs import BespokeLabs
@@ -114,21 +152,18 @@ use the SDK's configured retry policy.
114152Simply import ` AsyncBespokeLabs ` instead of ` BespokeLabs ` and use ` await ` with each API call:
115153
116154``` python
117- import os
118155import asyncio
119156from bespokelabs import AsyncBespokeLabs
120157
121- client = AsyncBespokeLabs(
122- api_key = os.environ.get(" BESPOKE_API_KEY" ), # This is the default and can be omitted
123- )
158+ client = AsyncBespokeLabs() # Reads BESPOKE_API_KEY from the environment.
124159
125160
126161async def main () -> None :
127- factcheck = await client.minicheck.factcheck.create (
128- claim = " claim " ,
129- context = " context " ,
162+ result = await client.nimble.system_one (
163+ state = " Please refund the duplicate payment. " ,
164+ questions = { " refund " : { " type " : " noul " , " instructions " : " Refund requested? " }} ,
130165 )
131- print (factcheck.support_prob )
166+ print (result.nouls[ " refund " ].noul )
132167
133168
134169asyncio.run(main())
@@ -161,9 +196,9 @@ from bespokelabs import BespokeLabs
161196client = BespokeLabs()
162197
163198try :
164- client.minicheck.factcheck.create (
165- claim = " claim " ,
166- context = " context " ,
199+ client.nimble.system_one (
200+ state = " Please refund the duplicate payment. " ,
201+ questions = { " refund " : { " type " : " noul " , " instructions " : " Refund requested? " }} ,
167202 )
168203except bespokelabs.APIConnectionError as e:
169204 print (" The server could not be reached" )
@@ -207,9 +242,9 @@ client = BespokeLabs(
207242)
208243
209244# Or, configure per-request:
210- client.with_options(max_retries = 5 ).minicheck.factcheck.create (
211- claim = " claim " ,
212- context = " context " ,
245+ client.with_options(max_retries = 5 ).nimble.system_one (
246+ state = " Please refund the duplicate payment. " ,
247+ questions = { " refund " : { " type " : " noul " , " instructions " : " Refund requested? " }} ,
213248)
214249```
215250
@@ -219,6 +254,7 @@ By default requests time out after 1 minute. You can configure this with a `time
219254which accepts a float or an [ ` httpx.Timeout ` ] ( https://www.python-httpx.org/advanced/#fine-tuning-the-configuration ) object:
220255
221256``` python
257+ import httpx
222258from bespokelabs import BespokeLabs
223259
224260# Configure the default for all requests:
@@ -233,9 +269,9 @@ client = BespokeLabs(
233269)
234270
235271# Override per-request:
236- client.with_options(timeout = 5.0 ).minicheck.factcheck.create (
237- claim = " claim " ,
238- context = " context " ,
272+ client.with_options(timeout = 5.0 ).nimble.system_one (
273+ state = " Please refund the duplicate payment. " ,
274+ questions = { " refund " : { " type " : " noul " , " instructions " : " Refund requested? " }} ,
239275)
240276```
241277
@@ -277,14 +313,14 @@ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to
277313from bespokelabs import BespokeLabs
278314
279315client = BespokeLabs()
280- response = client.minicheck.factcheck. with_raw_response.create (
281- claim = " claim " ,
282- context = " context " ,
316+ response = client.nimble. with_raw_response.system_one (
317+ state = " Please refund the duplicate payment. " ,
318+ questions = { " refund " : { " type " : " noul " , " instructions " : " Refund requested? " }} ,
283319)
284320print (response.headers.get(' X-My-Header' ))
285321
286- factcheck = response.parse() # get the object that `minicheck.factcheck.create ()` would have returned
287- print (factcheck.support_prob )
322+ result = response.parse() # get the object that `nimble.system_one ()` would have returned
323+ print (result.nouls[ " refund " ].noul )
288324```
289325
290326These methods return an [ ` APIResponse ` ] ( https://github.com/bespokelabsai/bespokelabs-python/tree/main/src/bespokelabs/_response.py ) object.
@@ -298,9 +334,9 @@ The above interface eagerly reads the full response body when you make the reque
298334To stream the response body, use ` .with_streaming_response ` instead, which requires a context manager and only reads the response body once you call ` .read() ` , ` .text() ` , ` .json() ` , ` .iter_bytes() ` , ` .iter_text() ` , ` .iter_lines() ` or ` .parse() ` . In the async client, these are async methods.
299335
300336``` python
301- with client.minicheck.factcheck. with_streaming_response.create (
302- claim = " claim " ,
303- context = " context " ,
337+ with client.nimble. with_streaming_response.system_one (
338+ state = " Please refund the duplicate payment. " ,
339+ questions = { " refund " : { " type " : " noul " , " instructions " : " Refund requested? " }} ,
304340) as response:
305341 print (response.headers.get(" X-My-Header" ))
306342
0 commit comments