@@ -28,14 +28,19 @@ pip install git+ssh://git@github.com/Not-Diamond/not-diamond-python.git
2828The full API of this library can be found in [ api.md] ( api.md ) .
2929
3030``` python
31- import os
3231from not_diamond import NotDiamond
3332
34- client = NotDiamond(
35- api_key = os.environ.get(" NOT_DIAMOND_API_KEY" ), # This is the default and can be omitted
36- )
33+ client = NotDiamond()
3734
38- response = client.retrieve_root()
35+ response = client.model_router.select_model(
36+ llm_providers = [
37+ {
38+ " model" : " model" ,
39+ " provider" : " provider" ,
40+ }
41+ ],
42+ messages = [{" foo" : " string" }],
43+ )
3944```
4045
4146While you can provide an ` api_key ` keyword argument,
@@ -48,17 +53,22 @@ so that your API Key is not stored in source control.
4853Simply import ` AsyncNotDiamond ` instead of ` NotDiamond ` and use ` await ` with each API call:
4954
5055``` python
51- import os
5256import asyncio
5357from not_diamond import AsyncNotDiamond
5458
55- client = AsyncNotDiamond(
56- api_key = os.environ.get(" NOT_DIAMOND_API_KEY" ), # This is the default and can be omitted
57- )
59+ client = AsyncNotDiamond()
5860
5961
6062async def main () -> None :
61- response = await client.retrieve_root()
63+ response = await client.model_router.select_model(
64+ llm_providers = [
65+ {
66+ " model" : " model" ,
67+ " provider" : " provider" ,
68+ }
69+ ],
70+ messages = [{" foo" : " string" }],
71+ )
6272
6373
6474asyncio.run(main())
@@ -87,10 +97,17 @@ from not_diamond import AsyncNotDiamond
8797
8898async def main () -> None :
8999 async with AsyncNotDiamond(
90- api_key = " My API Key" ,
91100 http_client = DefaultAioHttpClient(),
92101 ) as client:
93- response = await client.retrieve_root()
102+ response = await client.model_router.select_model(
103+ llm_providers = [
104+ {
105+ " model" : " model" ,
106+ " provider" : " provider" ,
107+ }
108+ ],
109+ messages = [{" foo" : " string" }],
110+ )
94111
95112
96113asyncio.run(main())
@@ -114,16 +131,23 @@ from not_diamond import NotDiamond
114131
115132client = NotDiamond()
116133
117- response = client.report.evaluate_hallucination (
118- context = " context " ,
119- prompt = " prompt " ,
120- provider = {
134+ response = client.prompt.adapt (
135+ fields = [ " string " ] ,
136+ goldens = [{ " fields " : { " foo " : " string " }}] ,
137+ origin_model = {
121138 " model" : " model" ,
122139 " provider" : " provider" ,
123140 },
124- response = " response" ,
141+ system_prompt = " system_prompt" ,
142+ target_models = [
143+ {
144+ " model" : " model" ,
145+ " provider" : " provider" ,
146+ }
147+ ],
148+ template = " template" ,
125149)
126- print (response.provider )
150+ print (response.origin_model )
127151```
128152
129153## File uploads
@@ -165,7 +189,15 @@ from not_diamond import NotDiamond
165189client = NotDiamond()
166190
167191try :
168- client.retrieve_root()
192+ client.model_router.select_model(
193+ llm_providers = [
194+ {
195+ " model" : " model" ,
196+ " provider" : " provider" ,
197+ }
198+ ],
199+ messages = [{" foo" : " string" }],
200+ )
169201except not_diamond.APIConnectionError as e:
170202 print (" The server could not be reached" )
171203 print (e.__cause__) # an underlying Exception, likely raised within httpx.
@@ -208,7 +240,15 @@ client = NotDiamond(
208240)
209241
210242# Or, configure per-request:
211- client.with_options(max_retries = 5 ).retrieve_root()
243+ client.with_options(max_retries = 5 ).model_router.select_model(
244+ llm_providers = [
245+ {
246+ " model" : " model" ,
247+ " provider" : " provider" ,
248+ }
249+ ],
250+ messages = [{" foo" : " string" }],
251+ )
212252```
213253
214254### Timeouts
@@ -231,7 +271,15 @@ client = NotDiamond(
231271)
232272
233273# Override per-request:
234- client.with_options(timeout = 5.0 ).retrieve_root()
274+ client.with_options(timeout = 5.0 ).model_router.select_model(
275+ llm_providers = [
276+ {
277+ " model" : " model" ,
278+ " provider" : " provider" ,
279+ }
280+ ],
281+ messages = [{" foo" : " string" }],
282+ )
235283```
236284
237285On timeout, an ` APITimeoutError ` is thrown.
@@ -272,11 +320,19 @@ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to
272320from not_diamond import NotDiamond
273321
274322client = NotDiamond()
275- response = client.with_raw_response.retrieve_root()
323+ response = client.model_router.with_raw_response.select_model(
324+ llm_providers = [{
325+ " model" : " model" ,
326+ " provider" : " provider" ,
327+ }],
328+ messages = [{
329+ " foo" : " string"
330+ }],
331+ )
276332print (response.headers.get(' X-My-Header' ))
277333
278- client = response.parse() # get the object that `retrieve_root ()` would have returned
279- print (client )
334+ model_router = response.parse() # get the object that `model_router.select_model ()` would have returned
335+ print (model_router )
280336```
281337
282338These methods return an [ ` APIResponse ` ] ( https://github.com/Not-Diamond/not-diamond-python/tree/main/src/not_diamond/_response.py ) object.
@@ -290,7 +346,15 @@ The above interface eagerly reads the full response body when you make the reque
290346To 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.
291347
292348``` python
293- with client.with_streaming_response.retrieve_root() as response:
349+ with client.model_router.with_streaming_response.select_model(
350+ llm_providers = [
351+ {
352+ " model" : " model" ,
353+ " provider" : " provider" ,
354+ }
355+ ],
356+ messages = [{" foo" : " string" }],
357+ ) as response:
294358 print (response.headers.get(" X-My-Header" ))
295359
296360 for line in response.iter_lines():
0 commit comments