@@ -28,18 +28,20 @@ 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
3132from not_diamond import NotDiamond
3233
33- client = NotDiamond()
34+ client = NotDiamond(
35+ api_key = os.environ.get(" NOT_DIAMOND_API_KEY" ), # This is the default and can be omitted
36+ )
3437
35- response = client.model_router.select_model(
36- llm_providers = [
37- {
38- " model" : " model" ,
39- " provider" : " provider" ,
40- }
41- ],
42- messages = [{" foo" : " string" }],
38+ response = client.router.create_survey_response(
39+ constraint_priorities = " constraint_priorities" ,
40+ email = " email" ,
41+ llm_providers = " llm_providers" ,
42+ use_case_desc = " use_case_desc" ,
43+ user_id = " user_id" ,
44+ x_token = " x-token" ,
4345)
4446```
4547
@@ -53,21 +55,23 @@ so that your API Key is not stored in source control.
5355Simply import ` AsyncNotDiamond ` instead of ` NotDiamond ` and use ` await ` with each API call:
5456
5557``` python
58+ import os
5659import asyncio
5760from not_diamond import AsyncNotDiamond
5861
59- client = AsyncNotDiamond()
62+ client = AsyncNotDiamond(
63+ api_key = os.environ.get(" NOT_DIAMOND_API_KEY" ), # This is the default and can be omitted
64+ )
6065
6166
6267async def main () -> None :
63- response = await client.model_router.select_model(
64- llm_providers = [
65- {
66- " model" : " model" ,
67- " provider" : " provider" ,
68- }
69- ],
70- messages = [{" foo" : " string" }],
68+ response = await client.router.create_survey_response(
69+ constraint_priorities = " constraint_priorities" ,
70+ email = " email" ,
71+ llm_providers = " llm_providers" ,
72+ use_case_desc = " use_case_desc" ,
73+ user_id = " user_id" ,
74+ x_token = " x-token" ,
7175 )
7276
7377
@@ -97,16 +101,16 @@ from not_diamond import AsyncNotDiamond
97101
98102async def main () -> None :
99103 async with AsyncNotDiamond(
104+ api_key = " My API Key" ,
100105 http_client = DefaultAioHttpClient(),
101106 ) as client:
102- response = await client.model_router.select_model(
103- llm_providers = [
104- {
105- " model" : " model" ,
106- " provider" : " provider" ,
107- }
108- ],
109- messages = [{" foo" : " string" }],
107+ response = await client.router.create_survey_response(
108+ constraint_priorities = " constraint_priorities" ,
109+ email = " email" ,
110+ llm_providers = " llm_providers" ,
111+ use_case_desc = " use_case_desc" ,
112+ user_id = " user_id" ,
113+ x_token = " x-token" ,
110114 )
111115
112116
@@ -131,21 +135,24 @@ from not_diamond import NotDiamond
131135
132136client = NotDiamond()
133137
134- response = client.prompt.adapt(
135- fields = [" string" ],
136- goldens = [{" fields" : {" foo" : " string" }}],
138+ response = client.prompt_adaptation.adapt(
139+ fields = [" question" ],
137140 origin_model = {
138- " model" : " model " ,
139- " provider" : " provider " ,
141+ " model" : " gpt-4o " ,
142+ " provider" : " openai " ,
140143 },
141- system_prompt = " system_prompt " ,
144+ system_prompt = " You are a helpful assistant that answers questions accurately. " ,
142145 target_models = [
143146 {
144- " model" : " model" ,
145- " provider" : " provider" ,
146- }
147+ " model" : " claude-3-5-sonnet-20241022" ,
148+ " provider" : " anthropic" ,
149+ },
150+ {
151+ " model" : " gemini-1.5-pro" ,
152+ " provider" : " google" ,
153+ },
147154 ],
148- template = " template " ,
155+ template = " Question: {question} \n Answer: " ,
149156)
150157print (response.origin_model)
151158```
@@ -160,7 +167,7 @@ from not_diamond import NotDiamond
160167
161168client = NotDiamond()
162169
163- client.pzn .create_survey_response(
170+ client.router .create_survey_response(
164171 constraint_priorities = " constraint_priorities" ,
165172 email = " email" ,
166173 llm_providers = " llm_providers" ,
@@ -189,14 +196,13 @@ from not_diamond import NotDiamond
189196client = NotDiamond()
190197
191198try :
192- client.model_router.select_model(
193- llm_providers = [
194- {
195- " model" : " model" ,
196- " provider" : " provider" ,
197- }
198- ],
199- messages = [{" foo" : " string" }],
199+ client.router.create_survey_response(
200+ constraint_priorities = " constraint_priorities" ,
201+ email = " email" ,
202+ llm_providers = " llm_providers" ,
203+ use_case_desc = " use_case_desc" ,
204+ user_id = " user_id" ,
205+ x_token = " x-token" ,
200206 )
201207except not_diamond.APIConnectionError as e:
202208 print (" The server could not be reached" )
@@ -240,14 +246,13 @@ client = NotDiamond(
240246)
241247
242248# Or, configure per-request:
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" }],
249+ client.with_options(max_retries = 5 ).router.create_survey_response(
250+ constraint_priorities = " constraint_priorities" ,
251+ email = " email" ,
252+ llm_providers = " llm_providers" ,
253+ use_case_desc = " use_case_desc" ,
254+ user_id = " user_id" ,
255+ x_token = " x-token" ,
251256)
252257```
253258
@@ -271,14 +276,13 @@ client = NotDiamond(
271276)
272277
273278# Override per-request:
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" }],
279+ client.with_options(timeout = 5.0 ).router.create_survey_response(
280+ constraint_priorities = " constraint_priorities" ,
281+ email = " email" ,
282+ llm_providers = " llm_providers" ,
283+ use_case_desc = " use_case_desc" ,
284+ user_id = " user_id" ,
285+ x_token = " x-token" ,
282286)
283287```
284288
@@ -320,19 +324,18 @@ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to
320324from not_diamond import NotDiamond
321325
322326client = NotDiamond()
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- }],
327+ response = client.router.with_raw_response.create_survey_response(
328+ constraint_priorities = " constraint_priorities" ,
329+ email = " email" ,
330+ llm_providers = " llm_providers" ,
331+ use_case_desc = " use_case_desc" ,
332+ user_id = " user_id" ,
333+ x_token = " x-token" ,
331334)
332335print (response.headers.get(' X-My-Header' ))
333336
334- model_router = response.parse() # get the object that `model_router.select_model ()` would have returned
335- print (model_router )
337+ router = response.parse() # get the object that `router.create_survey_response ()` would have returned
338+ print (router )
336339```
337340
338341These methods return an [ ` APIResponse ` ] ( https://github.com/Not-Diamond/not-diamond-python/tree/main/src/not_diamond/_response.py ) object.
@@ -346,14 +349,13 @@ The above interface eagerly reads the full response body when you make the reque
346349To 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.
347350
348351``` python
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" }],
352+ with client.router.with_streaming_response.create_survey_response(
353+ constraint_priorities = " constraint_priorities" ,
354+ email = " email" ,
355+ llm_providers = " llm_providers" ,
356+ use_case_desc = " use_case_desc" ,
357+ user_id = " user_id" ,
358+ x_token = " x-token" ,
357359) as response:
358360 print (response.headers.get(" X-My-Header" ))
359361
0 commit comments