-
-
Notifications
You must be signed in to change notification settings - Fork 664
/
sitemap.yaml
1927 lines (1927 loc) · 140 KB
/
sitemap.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
.pytest_cache/README.md:
hash: 7cc7f8d7cb2f2f6ea48da17c4b42c097
summary: The pytest cache directory is an essential component of the pytest framework's
cache plugin, which supports features like the `--lf` (last failed) and `--ff`
(failed first) options, as well as the `cache` fixture. It is crucial not to commit
this directory to version control, as it contains transient data that aids in
optimizing test execution. For comprehensive guidance and best practices, refer
to the [pytest cache documentation](https://docs.pytest.org/en/stable/how-to/cache.html).
Key terms include pytest, cache directory, cache plugin, `--lf`, `--ff`, cache
fixture, and version control.
api.md:
hash: eb98fb7f83415f27d1f4ac914e88f7a5
summary: The API Reference guide provides detailed documentation for a range of
features including `instructor.from_openai`, which likely facilitates interaction
with OpenAI models. It also covers `instructor.dsl.validators`, `iterable`, `partial`,
`parallel`, and `maybe`, suggesting a focus on facilitating and validating data
operations, handling iterative processes, partial functions, parallel processing,
and optional operations. Additionally, `instructor.function_calls` suggests guidance
on executing and managing function calls. This technical documentation is essential
for developers looking to implement efficient coding practices using these APIs.
Key terms include API Reference, OpenAI, data operations, function calls, parallel
processing, and validation.
blog/index.md:
hash: 10fbf1928e67e5f5278955322f96c013
summary: 'Subscribe to our newsletter for updates on new features and tips for using
Instructor, a tool that enhances AI query understanding, validation, and model
optimization. Explore advanced topics such as achieving GPT-4 level summaries
with GPT-3.5, understanding guardrails in AI, and validating AI-generated citations.
Enhance your Python skills with guidance on caching functions, batch processing
with async, and streaming models for improved latency. Learn about integrations
with Ollama, llama-cpp-python, Anyscale, and Together Compute. Access educational
resources, including a course on structured outputs and a keynote on Pydantic.
These insights are ideal for those eager to optimize AI models and improve Python
programming efficiency. Keywords: AI query understanding, GPT-4 summaries, Python
caching, AI model optimization, Instructor updates.'
blog/posts/aisummit-2023.md:
hash: 94a032207a2c663c0d9bf722f7d93d6e
summary: In this AI Engineer Keynote, delivered at the AI Engineer Summit, the speaker,
identified as jxnl, explores how [Pydantic](https://docs.pydantic.dev/latest/)
can be a powerful tool for prompt engineering in Python. The talk delves into
the documentation and insights provided by standard blog posts about Pydantic's
applications in developing more efficient AI systems. The speaker invites feedback
to further refine these concepts. Key themes include Python programming, Pydantic
usage, prompt engineering techniques, and advancements in AI development. Watch
the full talk [here](https://www.youtube.com/watch?v=yj-wSRJwrrc) for more detailed
insights.
blog/posts/announcing-gemini-tool-calling-support.md:
hash: 7f7358c04cd1e161b5006f496392ab51
summary: The announcement highlights the new support for structured outputs using
tool calling in the `instructor` platform, compatible with both Gemini SDK and
VertexAI SDK. It emphasizes the ease of setup and the generous free token quota
of the Gemini SDK, recommending it over VertexAI, which requires more complex
authentication. The article provides installation instructions, a usage example
with Python code, and compares both SDKs, noting the models that currently support
tool calling are `gemini-1.5-flash-latest` and `gemini-1.5-pro-latest`. It also
credits Sonal for contributing to the Gemini Tool Calling support. Key terms include
Gemini SDK, VertexAI SDK, tool calling, structured outputs, and API integration.
blog/posts/anthropic-prompt-caching.md:
hash: 3512680e4297a460ee9540c8174efdc8
summary: The article introduces Anthropic's new prompt caching feature, aimed at
tackling the challenges of slow response times and high costs developers face
when handling large contexts in language models. This feature, still in beta,
reduces costs and latency by caching frequently used text, thus avoiding repeated
processing. Key limitations include a minimum cache size requirement (2048 tokens
for Claude Haiku and 1024 for Claude Sonnet) and the current inability to cache
tool definitions, though future updates are expected to address this. The article
provides a practical example using Jane Austen's "Pride and Prejudice" to illustrate
how prompt caching can optimize API calls. Important keywords include prompt caching,
Anthropic, large context, response times, and high costs.
blog/posts/anthropic.md:
hash: a2e9176359f6abf16ce62975b978ed41
summary: 'The announcement introduces support for the Anthropic client in the instructor
package, highlighting new features except for streaming support. Users can experiment
by patching the client with `ANTHROPIC_JSON` to leverage enhanced capabilities.
The integration allows creating models with specific attributes using the `anthropic`
client and `pydantic` for data validation. Key topics include missing partial
streaming features, improving re-asking support for XML, and community feedback
for handling nested data types. Keywords: Anthropic support, streaming, `instructor`
package, `pydantic`, model creation, community feedback.'
blog/posts/bad-schemas-could-break-llms.md:
hash: 83ebd7f74900e32e79a3edbb825d4f4f
summary: The article discusses how bad schemas can dramatically impact the structured
outputs of LLMs like Claude and GPT-4o, potentially leaving 60% performance gains
on the table. Key points include how field naming, such as changing from `final_choice`
to `answer`, and implementing a Chain of Thought can significantly boost model
accuracy. The article highlights JSON mode's sensitivity compared to Tool Calling,
emphasizing the need for careful optimization and robust evaluation. It also underscores
the importance of choosing effective response models and the influence of naming
conventions on model performance. The GSM8k dataset is used for benchmarking,
revealing insights into response model optimization.
blog/posts/best_framework.md:
hash: 7a7b2ee06935e41b65ae4b528d4b26fa
summary: The Instructor library is an innovative tool for generating structured
outputs from large language models (LLMs) like GPTs using Python type annotations.
It seamlessly integrates with the OpenAI Python SDK via a simple patch, allowing
users to define structured data models with Pydantic, which eliminates the complexities
of handling open-ended text outputs. Key features include Pydantic model validation,
retry logic with Tenacity, and support for parallel tool calling, making Instructor
adaptable across platforms like Anyscale and Ollama. Its low abstraction makes
it easy to integrate into existing OpenAI-based applications, facilitating structured,
type-safe, and validated data extraction from LLMs.
blog/posts/caching.md:
hash: 4f1c410b7594f24b628860780b654088
summary: This article provides a comprehensive guide to caching in Python with a
focus on optimizing computationally expensive tasks, particularly when working
with Pydantic models. It discusses the use of `functools.cache` for simple in-memory
caching ideal for applications with immutable arguments, introduces `diskcache`
for persistent, large data caching suitable for longer-term data reuse, and covers
`redis` for distributed systems requiring scalable in-memory data storage. The
article provides detailed implementation examples, highlighting the benefits and
use cases for each caching strategy. Core ideas include enhancing performance,
reducing computation time, and addressing caching challenges with Pydantic models.
Key details emphasize persistent caching, distributed systems, and handling complex
data structures.
blog/posts/chain-of-density.md:
hash: c7852c03e42587934e4954cc0999a1b1
summary: 'The article, titled "Smarter Summaries w/ Finetuning GPT-3.5 and Chain
of Density," explores how to condense complex text summarization processes into
efficient AI models using fine-tuning techniques. It highlights a method called
Chain Of Density, which produces entity-dense summaries comparable to those generated
by humans, using iterative refinement. By fine-tuning GPT-3.5 models with aids
like the Instructor library, the article details a method that rivals GPT-4 in
summarization capability while achieving a 20x decrease in latency and a 50x reduction
in cost. The process involves data modeling with Pydantic, generating concise
summaries, and benchmarking against GPT-4, illustrating significant cost and performance
improvements. Keywords: Chain Of Density, GPT-3.5, GPT-4, summarization, fine-tuning,
Pydantic, Instructor library, entity density, AI validation, cost-efficiency.'
blog/posts/citations.md:
hash: f5a6b8ec79cb6648eaf5bb4caba54a00
summary: This blog post explores how to ensure the accuracy of information through
citation verification using Pydantic and OpenAI's large language models (LLMs).
The article demonstrates several methods, starting with a basic substring check
in Pydantic to verify if citations exist in text chunks. It then progresses to
leveraging OpenAI's LLMs to perform more sophisticated citation validation and
ensure that answers are aligned with citations and context. The post highlights
the potential of these techniques for generating accurate datasets and improving
model performance, emphasizing key concepts such as LLM citation verification,
data validation with Pydantic, and AI-driven data accuracy. Keywords include Pydantic,
validation, citations, OpenAI, LLM, data accuracy, and fine-tuning.
blog/posts/course.md:
hash: 189a78e4ca8a61e1208c24e418d546ac
summary: Explore a free, comprehensive course on Weights and Biases, designed to
enhance your understanding of steering language models. Released by the author
"jxnl," this course is based on detailed material from their introductory tutorial.
Accessible to everyone, the course is available on [wandb.courses](https://www.wandb.courses/courses/steering-language-models)
and offers a brief yet insightful learning experience, being just under an hour
long. Key topics include open source, language model steering, and practical applications
of Weights and Biases. Perfect for those eager to deepen their knowledge in machine
learning and AI.
blog/posts/distilation-part1.md:
hash: 8bd4605b66d7b473b5b07425435a743e
summary: "This article introduces the `Instructor` library, designed to streamline\
\ the fine-tuning of task-specific language models using Python functions. It\
\ highlights how `Instructor` simplifies complex machine learning pipelines by\
\ auto-generating datasets for fine-tuning and allows for easy function implementation\
\ swaps while maintaining backward compatibility. The guide includes a quick start\
\ example for using `Instructor\u2019s` distillation feature, demonstrating efficient\
\ integration of traditional machine learning with language models. Key points\
\ include the benefits of `Instructor`, essential commands for running a fine-tuning,\
\ and a future outlook on enhancing Python functions with fine-tuned models. For\
\ more information, users are encouraged to explore resources on GitHub and participate\
\ in feedback through a survey at useinstructor.com."
blog/posts/fake-data.md:
hash: 477a1d7b1ffdd545ff31c5cef793e907
summary: "The article discusses techniques for generating synthetic data using AI\
\ models, specifically through the integration of Pydantic, OpenAI, and the Instructor\
\ library. It highlights the process of creating realistic user data by defining\
\ models, such as `UserDetail`, and incorporating example data at different levels\u2014\
attribute, model, and descriptive text fields. Core strategies include leveraging\
\ celebrity names, complex examples from improved models like \"gpt-4-turbo-preview,\"\
\ and refining data output with detailed descriptions, such as \"Fancy French\
\ sounding names.\" These methods provide nuanced control over the synthetic data\
\ generation process, making it application-specific and diverse. Key concepts\
\ include AI-generated data, Pydantic examples, OpenAI GPT models, and synthetic\
\ user data creation."
blog/posts/full-fastapi-visibility.md:
hash: 6292081adfb17d0f262598bea28343c8
summary: The article discusses integrating Logfire, a new observability tool, with
FastAPI and OpenAI's Instructor to enhance application performance monitoring
using OpenTelemetry. It highlights Logfire's compatibility with Pydantic and FastAPI,
providing comprehensive logging capabilities that improve visibility and error
reproduction. The tutorial includes code examples demonstrating data extraction
from user queries, parallel processing with `asyncio`, and streaming data with
`Iterable`. Key benefits include streamlined application profiling, efficient
parallel processing, and real-time streaming, appealing to developers using FastAPI
and Instructor. Core keywords include Logfire, FastAPI, Pydantic, OpenTelemetry,
asyncio, streaming, and application observability.
blog/posts/generator.md:
hash: 7eb1ba5b594739e284e7be0703af86b9
summary: "The article explores Python generators and their significant role in enhancing\
\ performance and efficiency through data streaming, particularly in latency-sensitive\
\ applications like eCommerce and chat interfaces, such as ChatGPT. It details\
\ how generators allow for lazy evaluation, maintaining state, and reducing memory\
\ usage by yielding one item at a time instead of loading entire datasets. Furthermore,\
\ the piece introduces LLM (Large Language Model) streaming with generators, enabling\
\ real-time processing of data streams, exemplified through a product ranking\
\ use case in e-commerce using the Instructor library. Key topics include Python\
\ generators, LLM streaming, memory efficiency, and real-time data extraction\u2014\
vital for improving user experience and application responsiveness."
blog/posts/introducing-cerebras-support.md:
hash: 1c3a2368c3de632e9b70eb13bbdae88c
summary: The article introduces Cerebras support for the Instructor platform, highlighting
the integration of a new AI chip designed specifically for efficiency and performance
with large language models. Users can now leverage Cerebras inference using the
`from_cerebras` method, allowing for up to 550 tokens per second. Key steps include
installing the Cerebras SDK and using Python code to create and validate responses
with a Pydantic model. It also covers the setup for synchronous and asynchronous
client operations, as well as streaming capabilities with the `CEREBRAS_JSON`
mode. This integration aims to enhance AI model deployment with greater speed
and precision in processing queries. Keywords include Cerebras, Instructor platform,
AI chip, language models, Pydantic model, API, and streaming.
blog/posts/introducing-structured-outputs.md:
hash: 4e238316604c63c010b6315458624416
summary: The article discusses OpenAI's Structured Outputs, which ensure generated
responses match a provided JSON schema, highlighting key challenges such as limited
validation, streaming complexities, and unpredictable latency. It mentions the
vendor lock-in issue associated with adopting Structured Outputs and introduces
the `instructor` library as a solution. `Instructor` offers automatic validation
with retry logic, real-time streaming validation, and a provider-agnostic API,
allowing developers to switch between LLM providers easily. It addresses the limitations
of OpenAI's system and enhances output consistency and flexibility in AI projects.
Key terms include OpenAI, Structured Outputs, validation, streaming, latency,
vendor lock-in, and `instructor`.
blog/posts/introduction.md:
hash: e0b2504459dd6e4c052998017f25d079
summary: This post explores simplifying interactions with Language Learning Models
(LLMs) using Instructor and Pydantic, a widely adopted Python tool. It addresses
the complexity of existing LLM frameworks and highlights how Pydantic facilitates
model definitions and validations, providing widespread framework compatibility.
Examples of modular schema composition, validation, and using enums illustrate
Pydantic's capabilities. The approach treats language models as microservices,
similar to FastAPI, allowing developers to write Python functions utilizing Pydantic
objects, eliminating complex prompt chains. The post promotes Instructor as a
tool enhancing ease of use for LLM integrations, targeting both experienced and
novice developers. Key terms include Pydantic, LLMs, JSON Schema, OpenAI, and
FastAPI.
blog/posts/jinja-proposal.md:
hash: 9c8fa69a918d69c3c44842dee754524f
summary: This proposal introduces the integration of Jinja templating into the Instructor
platform to enhance its prompt formatting, validation, and versioning capabilities.
By leveraging Jinja's advanced formatting features such as list iteration and
conditional implementation, Instructor can handle complex prompt structures while
facilitating version control and better logging of prompt templates and variables.
Additionally, the use of Pydantic models for validation ensures secure handling
of sensitive information and enhances type safety. This integration aims to streamline
the creation of dynamic and reusable prompt templates, differentiate Instructor
from standard libraries, and improve the overall robustness and flexibility of
the platform. Key concepts include Jinja templating, prompt formatting, validation
with Pydantic, version control, secure logging, and dynamic content rendering.
blog/posts/langsmith.md:
hash: ebc5ab599dbacfd1c0e4472daacc9d66
summary: This blog post explores the versatile DevOps platform LangSmith, a component
of LangChain, which is often mistakenly thought to work only with LangChain models.
The article demonstrates how LangSmith can enhance the OpenAI client by enabling
seamless support for observability and monitoring in LLM applications. Key steps
include setting up the LangSmith API key, installing necessary SDKs, and employing
the `wrap_openai` function to integrate LangSmith with OpenAI. The post provides
a Python example utilizing LangSmith and the `instructor` tool to classify questions
asynchronously with an OpenAI client, showcasing its capabilities for developing,
testing, and monitoring AI applications. This post is ideal for readers interested
in AI, LangChain, OpenAI applications, and DevOps for machine learning.
blog/posts/learn-async.md:
hash: a3e52ba98ab41811317e720aea62f460
summary: The article explores the use of `asyncio` in Python for concurrent data
processing, specifically focusing on batch processing with the `AsyncOpenAI()`
class and instructor library. It compares several methods for running asynchronous
tasks, including `asyncio.gather` and `asyncio.as_completed`, discussing the pros
and cons of each. The article highlights the importance of rate limiting using
`asyncio.Semaphore` to manage concurrent requests to a server and avoid overload.
Key points include the use of `async` and `await` keywords, understanding concurrency
in Python, and the performance benefits of handling tasks asynchronously. The
results illustrate significant speed improvements for async processing compared
to sequential execution. The post finishes with practical implications of async
processing and considerations for choosing an approach based on task nature and
resource management.
blog/posts/logfire.md:
hash: 5fd5debd53d1b913db672a141e95b870
summary: The article introduces Logfire, a new observability platform from the creators
of Pydantic, which integrates seamlessly with libraries like Pydantic, HTTPx,
and Instructor. It guides users through examples of using Logfire to enhance application
performance visibility, focusing on classifying scam emails, validating content
with `llm_validator`, and extracting data from infographics using GPT-4V. The
article also provides code examples and emphasizes Logfire's ease of integration,
efficient logging, and detailed tracking capabilities. Keywords include Logfire,
Pydantic, email classification, data extraction, GPT-4V, observability, and application
performance.
blog/posts/matching-language.md:
hash: dde687555d3d1f1dd61e6cd3965e5f4f
summary: The article addresses the challenge of ensuring that language model-generated
summaries match the language of the source text, highlighting a common issue where
summaries default to English due to English-based instructions. To combat this,
the author explores techniques involving Pydantic for data validation and the
`langdetect` library for language detection. The article provides examples and
results, demonstrating that reiterating instructions to specify language can significantly
improve accuracy. By incorporating a language detection attribute in the prompt,
the model achieves consistent language matching, enhancing multilingual summarization
performance. Key topics include multilingual summarization, language models, language
detection, and OpenAI's GPT-3.5.
blog/posts/open_source.md:
hash: 3555f28a7e8fc62cff97b61c93a84aa5
summary: The article explores the integration of structured output capabilities
using JSON schema with various open-source and local language models through Instructor.
It highlights the use of Pydantic for structured data validation and discusses
support for platforms like OpenAI, Mistral, and Ollama. Key solutions include
Ollama's local model implementation, llama-cpp-python's structured outputs, Anyscale's
Mistral model, and platforms like Groq and Together AI. The guide provides examples
and instructions for leveraging these tools to enhance AI projects with structured
data outputs, emphasizing keywords such as "structured output," "local models,"
"open source," "JSON schema," and specific platforms like "Mistral," "Ollama,"
and "llama-cpp-python."
blog/posts/openai-distilation-store.md:
hash: 837becb03daf90bf500b66a573ef6619
summary: OpenAI has launched a new feature, API Model Distillation, enabling developers
to create custom, efficient models tailored to specific use cases. This is further
enhanced by integration with Instructor, which offers structured output capabilities
through Pydantic models. The process involves generating smaller, focused models
from the inputs and outputs of larger models, ensuring high performance while
reducing costs and latency. The integration allows seamless use of OpenAI API
parameters and enhances metadata handling, promoting efficient and organized API
calls. This combination leads to consistent, optimized AI solutions for specialized
tasks, enhancing performance and cost-effectiveness for AI applications. For detailed
guidance, refer to OpenAI's documentation and the Instructor GitHub repository.
blog/posts/parea.md:
hash: b98fad29342cb154cbf4387faf9a2259
summary: This article introduces [Parea](https://www.parea.ai), a platform that
enhances the integration of `instructor` with OpenAI clients by providing features
for monitoring, collaboration, testing, and labeling of LLM applications. Key
functionalities include grouping LLM call retries under a single trace, tracking
validation errors automatically, and offering a user interface for labeling JSON
responses. The article demonstrates using Parea to create emails containing URLs
from instructor docs with a Pydantic model for validation. It highlights Parea's
capabilities in validation error tracking and response labeling to improve fine-tuning
processes. With Parea's annotation queue and Form Mode, non-developers can safely
label data for fine-tuning, improving ease of use and accuracy.
blog/posts/pydantic-is-still-all-you-need.md:
hash: 59888fa5461b08df2296ab2188415d6f
summary: 'The article titled "Pydantic is Still All You Need: Reflections on a Year
of Structured Outputs" emphasizes the importance of using structured outputs with
language models, highlighting Pydantic''s capabilities in enhancing data validation
and system reliability. It discusses the benefits of Pydantic, such as modular
structures with nested objects, validators for error handling, and streaming with
structured outputs, which improve compatibility and maintainability. The article
also addresses real-world applications like generation, extraction, and complex
search queries. It reinforces how structured outputs facilitate a classical programming
approach compatible with existing software ecosystems. Key developments include
Pydantic''s expansion to multiple programming languages and tools, such as Rust
and popular AI models.'
blog/posts/rag-and-beyond.md:
hash: c5e2f50a36e691eb2ec5714a1c790979
summary: This article explores advanced strategies for enhancing Retrieval Augmented
Generation (RAG) beyond simple embedding search. It critiques the limitations
of basic RAG models, such as query-document mismatch and monolithic search backends,
and introduces improved techniques using query understanding. Examples from Metaphor
Systems and personal assistant applications demonstrate how structured query models
can integrate multiple search backends, offering more precise and contextually
enriched search results. The piece highlights the use of instructor, a tool that
employs Pydantic to model complex queries, facilitating seamless interactions
between language models and search backends. This approach emphasizes the potential
of combining Large Language Models (LLMs) with advanced information retrieval
and query understanding techniques to optimize search processes.
blog/posts/rag-timelines.md:
hash: 0522d54c9bb90793695e34f84ebd616b
summary: The article discusses enhancing Retrieval-Augmented Generation (RAG) systems
using time filters with the Instructor Python library. It emphasizes the importance
of handling time-based constraints like "last week" or "previous month" for queries.
The post outlines using Pydantic models to represent time ranges and integrate
large language models (LLMs) to generate accurate search queries. Key considerations
include managing nuances in dates and timezones, calculating relative time periods,
and normalizing user inputs. By doing so, RAG systems can improve their accuracy
and relevance in information retrieval within specified time frames. Keywords
include RAG, time filters, LLMs, Pydantic, and Instructor library.
blog/posts/situate-context.md:
hash: 1d2cfa41fd490ac9856438c4cf7861bc
summary: The article discusses implementing Anthropic's Contextual Retrieval technique
to improve Retrieval-Augmented Generation (RAG) systems by adding explanatory
context to document chunks to prevent loss of information. It highlights the use
of async processing for efficiency, outlines a sample implementation using Python
and async libraries, and provides performance metrics demonstrating significant
reductions in retrieval failure rates. Key features include the use of Claude
for generating context, structured output with Pydantic models, and prompt caching
for efficiency. It also suggests experimentation with chunk sizing, embedding
models, and employing reranking for enhanced results.
blog/posts/timestamp.md:
hash: 0285bfdee4ff7fdb0b23f8a046bcb7fe
summary: 'The article discusses a method to ensure consistent timestamp formats
in language model outputs, addressing common issues in video content workflows.
It highlights the challenge of inconsistent timestamp formats, such as HH:MM:SS
and MM:SS, which can lead to parsing errors. The solution involves using Pydantic
for data validation and a custom parser to normalize timestamps, maintaining consistency
across video segments. The approach combines schema validation with context-aware
processing for reliable timestamp handling. Key terms: timestamp formats, Pydantic,
normalization, language models, video content workflows, data validation.'
blog/posts/using_json.md:
hash: d709a4205f18e43c377112effb7947a2
summary: The article discusses how the Instructor library enhances the process of
obtaining well-structured JSON data from Large Language Models (LLMs) using Python
type annotations and Pydantic models. It highlights Instructor's integration with
various LLMs like GPT-3.5 and GPT-4 and its compatibility with multiple programming
languages, including Python, TypeScript, Ruby, Go, and Elixir. The key benefits
of Instructor include seamless integration with OpenAI SDK, type validation, field
requirements, default values, and advanced types like URLs and lists with Pydantic
models. Instructor allows for a zero-overhead adoption path, making it a user-friendly
tool for developers to extract and validate JSON outputs from LLMs efficiently.
blog/posts/validation-part1.md:
hash: 1cda1e712a5d000abc087c1fab1af700
summary: "The article \"Good LLM Validation is Just Good Validation\" discusses\
\ incorporating dynamic, machine-learning-driven validation into software using\
\ Python libraries like Pydantic and Instructor. It highlights the evolution from\
\ static, rule-based methods to adaptive validations using large language models\
\ (LLMs). The post emphasizes the importance of reliable validation, introduces\
\ tools like Instructor for OpenAI\u2019s function call API, and provides examples\
\ of validating user inputs and complex data structures. Key topics include the\
\ use of field validators, model validators, context-based validation, and automatic\
\ retries for invalid responses. The approach aims to enhance validation processes\
\ in AI systems without introducing new concepts. Keywords: LLM validation, machine\
\ learning, Pydantic, Instructor, OpenAI, dynamic validation, AI systems, Python\
\ libraries, software development."
blog/posts/version-1.md:
hash: 8a7d049bb50978209bd429cc28753cd8
summary: The announcement of the release of `instructor=1.0.0` introduces a refined
API for the `instructor` package, designed for easier integration and removal
while maintaining compatibility with OpenAI and other AI models. Over the past
10 months, the package has grown significantly, amassing over 4,000 GitHub stars
and 120k monthly downloads. The updates in version 1.0.0 focus on improved typing
and usability, introducing new methods like `create_iterable` and `create_partial`
for better handling of data streams. Key features include seamless integration
with existing clients, enhanced type inference, and support for asynchronous operations.
The release also highlights support across multiple languages, including JavaScript,
Elixir, and PHP, reinforcing its core philosophy of "easy to try, easy to delete."
blog/posts/youtube-transcripts.md:
hash: 8e478f24910f76825861938cb418efa7
summary: This article guides readers through analyzing YouTube transcripts to create
structured chapters, using tools like `instructor`, OpenAI, and `youtube-transcript-api`.
It includes step-by-step instructions for extracting chapters from a video's transcript
and outlines how to configure a Pydantic model for structured data output. Key
objectives include summarizing YouTube transcripts into distinct chapters and
exploring alternative applications like study notes, content summarization, and
quiz generation. By leveraging these models, users can transform video content
into various engaging formats. Keywords include YouTube transcript analysis, Pydantic
model, chapter extraction, video content, and OpenAI integration.
cli/batch.md:
hash: f061f50334b5b07fdacfa5900532828a
summary: The guide provides an overview of using the Command Line Interface (CLI)
for managing OpenAI batch jobs with the `instructor` tool. It details how to list,
create, and cancel batch jobs. Key functionalities include viewing all existing
jobs with options for limiting the results, creating jobs from `.jsonl` files
using a Python script with Pydantic and the `BatchJob` object, and canceling outstanding
jobs. Essential commands like `list`, `create-from-file`, and `cancel` are explained,
along with their respective options. Keywords include CLI, batch jobs, OpenAI,
Python, `instructor`, `.jsonl`, and Pydantic.
cli/finetune.md:
hash: 450817623f555045064ffc818f5abf69
summary: The article discusses the Command Line Interface (CLI) for managing fine-tuning
jobs on OpenAI using the "instructor" tool. It emphasizes that the CLI is still
under development and lacks full feature support, inviting contributions to enhance
its functionality. The guide provides detailed instructions on creating fine-tuning
jobs either from a file or an existing ID, with customizable options such as model
selection, epochs, batch size, and learning rate. It also covers viewing job statuses
and file management within the system. The CLI aims to serve as a light wrapper
around the API, and contributions can be made via the [jxnl/instructor GitHub
repository](https://www.github.com/jxnl/instructor). Key points include fine-tuning,
model training, job monitoring, and community contributions.
cli/index.md:
hash: 87b74ae56ba5174d89eae8f50657b251
summary: The Instructor CLI is a command-line tool designed to streamline interactions
with the OpenAI API, assisting with API usage monitoring and model fine-tuning.
To get started, users need to set the OpenAI API key as an environment variable
and install the tool via pip. Key features include tracking API usage, such as
token counts and requests, and optimizing models through a fine-tuning app. For
additional support or contributions, users can access the GitHub repository. Keywords
include OpenAI API, command-line tool, API usage monitoring, model fine-tuning,
and installation.
cli/usage.md:
hash: 92bfb660828a7fa5972ea7aabd497e06
summary: The OpenAI API Usage CLI tool is designed to help users monitor their OpenAI
API usage, providing breakdowns by model, date, and cost. The tool offers command-line
options to view usage data, including a command to list API usage for the past
N days or specifically for today. Usage is presented in a detailed table format,
showcasing metrics like total requests and total cost. The tool aims to act as
a lightweight wrapper around the API, and contributions from the community are
welcome through issues or pull requests on the GitHub repository. Key features
include usage monitoring, API metrics display, and community contribution support.
concepts/alias.md:
hash: 482721ff5d70a566a37fda716899070d
summary: This page is currently under development and focuses on providing information
about Pydantic, a Python library used for data validation and settings management.
The page highlights the concept of using aliases in Pydantic models to customize
field names, a feature that enhances code readability and integration with external
systems. For comprehensive guidance, readers are encouraged to visit the official
[Pydantic documentation](https://docs.pydantic.dev/latest/concepts/alias/). Key
terms include Pydantic, data validation, Python, aliases, and settings management.
concepts/caching.md:
hash: 7aa2bfb9e02fec6ea810d0ea908c5063
summary: The blog post explores various caching techniques in Python, focusing on
improving application performance through effective data management. Key topics
include the use of `functools.cache` for simple in-memory caching, ideal for functions
with immutable arguments in small to medium-sized applications. It also covers
`diskcache` for persistent, large data caching, suitable for applications needing
cache persistence between sessions. Additionally, the post details Redis caching
for distributed systems, which is recommended for scenarios requiring fast read/write
access and handling complex data structures. Throughout, examples demonstrate
how caching can optimize computational efficiency and data retrieval. Key phrases
include "caching techniques," "in-memory caching," "persistent data caching,"
"Redis caching," and "distributed systems caching."
concepts/distillation.md:
hash: 5cadbe7476df7904182424644270dcd6
summary: The article discusses the use of the Instructor library to simplify fine-tuning
language models, such as `gpt-3.5-turbo`, to replicate Python function behavior.
By leveraging Pydantic type hints and `Instructions`, developers can make language
models backward compatible with existing Python functions and streamline the creation
of a fine-tuning dataset using automatic data logging and structured output. This
approach not only conserves tokens by eliminating schema transmission but also
facilitates seamless integration of classical machine learning with language models.
The library's features enhance efficiency by distilling function requirements
into model weights and simple code, making it a game-changer in the field of AI
function replication and fine-tuning.
concepts/enums.md:
hash: bb4f52ad0b29468955a1d468a884fcd7
summary: The text discusses the use of Enums in Python to prevent data misalignment
by standardizing fields in data models. By including an "Other" option in Enums,
uncertainty in data can be captured effectively. It provides an example using
Python's Pydantic BaseModel to define user roles such as "PRINCIPAL," "TEACHER,"
"STUDENT," and "OTHER." As an alternative to Enums, the use of the `Literal` type
is suggested for defining the same roles. Key concepts include the importance
of standardized data representation, the flexibility of Enums and Literals, and
effective error handling in data models.
concepts/fastapi.md:
hash: 235362431dbee08aa1e18c2e41514916
summary: This guide provides an overview of integrating Pydantic models with FastAPI,
a modern, high-performance Python web framework known for automatic OpenAPI documentation
and AsyncIO support. It demonstrates setting up a FastAPI app with a POST endpoint
that uses Pydantic to define and validate data structures seamlessly. The snippet
showcases handling synchronous and streaming responses, beneficial for managing
large data from language models like GPT-3. The guide also highlights FastAPI's
capability to automatically generate interactive documentation pages, enhancing
development convenience and API testing. Key terms include FastAPI, Pydantic,
OpenAPI, JSON Schema, asynchronous programming, and StreamingResponse.
concepts/fields.md:
hash: 9de5e9cfabe9014e5cb7497d60766874
summary: The article provides an overview of using Pydantic's `Field` function to
customize and add metadata to fields in models, highlighting its role in default
value assignment and JSON schema customization. Key features include setting default
and factory defaults for field values, using the `Annotated` type for field annotations,
and controlling field exclusion from models with parameters like `exclude` and
`SkipJsonSchema`. It also outlines methods for enhancing JSON schemas with additional
information such as title, description, and examples, relevant for prompt engineering.
The article emphasizes the significance of these customization options in JSON
schema generation, which supports more precise and efficient model validations
and prompting for language models.
concepts/lists.md:
hash: 08e70ce9877857c9a8d2cafc494b83c5
summary: The content discusses structured data extraction using Python's Pydantic
library, focusing on defining schema classes for tasks like extracting user information.
It highlights methods for multi-task extraction using `Iterable[T]`, enabling
dynamic creation of classes with adaptable features for streaming tasks. Various
examples demonstrate extracting user entities with GPT models like "gpt-3.5-turbo"
and "gpt-4," showing synchronous and asynchronous streaming capabilities. Key
concepts include task extraction, streaming data processing, and asynchronous
programming, all facilitated by the `instructor` and `openai` libraries. This
approach enhances efficiency in handling dynamic data structures and real-time
data processing in AI applications.
concepts/logging.md:
hash: fa370d49da298dfb7beb120b6929aa34
summary: 'This Python code snippet demonstrates how to set logging to DEBUG to track
and view requests and responses made to OpenAI''s API, which is useful for debugging.
It utilizes the `instructor` and `openai` libraries along with `pydantic` for
defining data models. By setting the logging level, developers can gain insights
into the interactions between their application and OpenAI, specifically when
creating chat completions. The example includes a setup for extracting user details
using the `instructor` library, with key functionality and parameters outlined
for effective API integration. Keywords: OpenAI, API, logging, debugging, Python,
chat completions, pydantic, data models.'
concepts/maybe.md:
hash: cefcf24ec71e524b675b339d464f9d9c
summary: The article discusses the `Maybe` pattern, a functional programming concept
used for error handling, particularly in handling missing data or errors without
raising exceptions. It showcases using this pattern in API calls to language models
to minimize hallucinations. The approach involves defining Pydantic models, `UserDetail`
and `MaybeUser`, to encapsulate both successful results and errors. The `extract`
function, using the `MaybeUser` model, processes content through a language model,
and returns structured data, handling cases where data extraction is unsuccessful.
Highlighted keywords include Maybe pattern, Pydantic, error handling, language
models, missing data, functional programming, and API calls.
concepts/models.md:
hash: 26dece5991f1bb057e255e3038598a4b
summary: The article discusses defining LLM (Large Language Model) output schemas
in Pydantic using `pydantic.BaseModel`. It explains how to use Pydantic models
as a `response_model` in client `create` calls to OpenAI, detailing how they define
schemas, validate API responses, and return Pydantic model instances. The guide
covers using docstrings and field annotations for prompting, handling optional
values, dynamic model creation with `create_model`, and adding custom methods
to enhance model behavior. The text emphasizes the adaptability of Pydantic for
generating prompts and shaping model responses dynamically based on runtime information
or user-specific descriptions. Key concepts include response modeling, schema
validation, and leveraging Python for dynamic language model interactions.
concepts/parallel.md:
hash: 1971dd00762d1c3220755f225145ace1
summary: OpenAI has introduced an experimental feature called parallel function
calling, available in the `gpt-4-turbo-preview` model, aimed at reducing application
latency by enabling multiple function calls in a single request. This feature
allows developers to streamline processes without complex schema manipulation.
By setting the mode to `PARALLEL_TOOLS`, users can execute parallel function calls
using response models defined as `Iterable` types. This technique is particularly
useful for applications requiring rapid responses, such as retrieving weather
data for multiple locations or conducting quick Google searches. Developers should
note that this feature is in preview and may undergo changes.
concepts/partial.md:
hash: 02119bfd49a4e03e1f80a64746464f9d
summary: The article discusses the concept of streaming partial responses using
field-level streaming to provide real-time updates and incremental snapshots for
response models, especially useful in UI component rendering. By leveraging the
`create_partial` feature in the `instructor` library, developers can dynamically
generate response models with optional fields. This allows for partial parsing
of data as soon as it becomes available. The article provides examples, including
synchronous and asynchronous streaming methods, demonstrating how these updates
can be processed in real-time using tools like OpenAI's API and Pydantic BaseModel.
Key terms include partial responses, incremental updates, real-time streaming,
`create_partial`, and the `instructor` library.
concepts/patching.md:
hash: 3a4352e86fdf1d39268b8c43be0fb4fa
summary: The article discusses enhancements to client functionality with new keywords
like `response_model`, `max_retries`, and `validation_context` for backward compatibility.
It emphasizes the use of TOOL mode for structured output, especially with OpenAI
clients, noting that function calling is being deprecated. It highlights various
modes for structured data extraction, including Gemini Tool Calling, JSON Mode,
and Parallel Tool Calling, while noting limitations and compatibility issues.
Additionally, it covers Gemini Vertex AI Tool Calling and mentions experimental
Markdown JSON Mode for Databricks and vision models. Key terms include OpenAI,
TOOL mode, JSON format, Gemini, Vertex AI, and Databricks.
concepts/philosophy.md:
hash: cbc5ee756e57727843031bb140d5da54
summary: The philosophy of the instructor library emphasizes simplicity, transparency,
and flexibility for leveraging language models (LLMs) in Python. It aims to streamline
structured outputs with minimal dependencies, utilizing Pydantic for complex tasks.
Key features include the use of `response_model` and `patch` to simplify user
experience, maintaining transparency by limiting hidden prompts, and easy integration
with existing OpenAI systems. The framework encourages defining schemas, validators,
and encapsulated logic within Python functions to minimize complexity and regret.
The library and its documentation are designed to enhance Python programming skills,
focusing on maintaining a simple, adaptable, and easily debuggable codebase without
unnecessary abstractions.
concepts/prompt_caching.md:
hash: 741469d18862d9a489fa1046f7c54285
summary: Prompt Caching is a feature designed to enhance the efficiency of API calls
by storing and reusing shared prompt portions, especially beneficial for applications
making multiple calls with similar context. OpenAI's automatic prompt caching
for models like gpt-4o and o1-preview reduces processing redundancy without additional
fees, while Anthropic offers a beta feature that allows manual caching via `anthropic.beta.prompt_caching.messages.create`.
Key for optimizing language model interactions, prompt caching lowers costs and
speeds up response times, with minimal cache sizes required for certain models.
This method helps manage large contexts more effectively, making it a valuable
tool for applications using OpenAI or Anthropic models.
concepts/prompting.md:
hash: 59442ff85a0e7b35d68b5827c457a836
summary: The document provides comprehensive tips on prompt engineering, emphasizing
the use of Instructor and Pydantic to create self-descriptive, modular, and flexible
models. Key principles include modularity, self-description using Pydantic's `Field`,
optional attributes using Python's `Optional` type, and standardization via Enums
for fixed value fields. It also covers error handling through the Maybe pattern,
managing arbitrary properties and list lengths, and defining relationships between
entities. Additionally, it highlights the reuse of components in different contexts,
employing a "chain of thought" for added logic. These techniques ensure data integrity
and ease of use, making them ideal for developers seeking structured and efficient
prompt engineering solutions.
concepts/raw_response.md:
hash: 172d21ce233868b4a78bc28b46b0e79c
summary: This guide demonstrates using the instructor package to create and handle
AI chat completions, leveraging the OpenAI API and pydantic for structured data
processing. It presents a code example featuring a custom client setup to extract
user details like name and age from a conversation, highlighting the use of models
such as `gpt-3.5-turbo` to achieve accurate data extraction and response handling.
Key concepts include the creation of chat completions, use of the `UserExtract`
model for structured response modeling, and inspection of detailed completion
metadata. This process underscores powerful AI capabilities in structured data
extraction and natural language understanding.
concepts/reask_validation.md:
hash: 8045c90edc12d2158dd87fc737ddb810
summary: The content discusses leveraging Pydantic's validation framework for both
code-based and LLM-based validation, highlighting the integration of error messages
as a means for AI self-correction. It outlines how Pydantic can enforce rules
through validators, providing examples of both code and LLM-based validations.
The text also introduces the concept of a reasking mechanism to improve LLM outputs
by setting `max_retries` for validation errors. Additional insights include advanced
validation techniques, optimizing token usage by removing unnecessary URLs in
error messages, and ensuring better reliability of LLM-generated content. Key
topics include Pydantic, AI self-reflection, validation errors, LLM-based validation,
and optimizing token usage.
concepts/retrying.md:
hash: e159f64b0b1002b7cb66e898c8916d71
summary: 'This article explores how to effectively use Pydantic validators and Tenacity
for implementing retry logic in Python applications. It starts with a simple example
of a validator that ensures a name is in uppercase using Pydantic''s validation
tools. The piece highlights setting up basic retry mechanisms with parameters
like `max_retries` and catching retry exceptions. For advanced control, the article
introduces using the Tenacity library, offering customizable retry logic such
as back-offs, asynchronous retries, and retry callbacks. Key points also include
Tenacity''s various features, such as stopping after a set number of attempts
or a delay, and the ability to add retry callbacks for logging or debugging. Keywords:
Pydantic, validators, Tenacity, retry logic, Python, back-offs, asynchronous retries,
retry exceptions.'
concepts/templating.md:
hash: e1f4e1b93670fa5e5176540276dcb68f
summary: Instructor's Jinja templating provides a dynamic and efficient way to adapt
and manage prompts, integrating seamlessly with validation processes and handling
sensitive information securely. The solution offers separation of prompt structure
and content, allowing for complex logic implementation and template reusability.
Enhanced prompt versioning and logging are supported through Pydantic integration,
ensuring validation and type safety. Key features include context-aware prompt
rendering with Jinja syntax, dynamic validation with Pydantic, and secure handling
of sensitive data using `SecretStr`. This approach is ideal for applications requiring
adaptable prompts, such as chatbots, where user context and data security are
paramount.
concepts/typeadapter.md:
hash: e264c774c4e9ea2ce505091092b9f827
summary: This page is a work in progress and provides an overview of Pydantic's
Type Adapter, a feature used for data validation and parsing in Python applications.
For more comprehensive information, visit Pydantic's official documentation. Key
topics include data validation, Python data models, and improved data handling
processes.
concepts/typeddicts.md:
hash: 67996f828a2f30c25aefa973f2df34d5
summary: This content introduces the use of TypedDicts in Python, specifically demonstrating
integration with OpenAI's API through a library called "instructor." It highlights
how to define a TypedDict class, `User`, with specific fields like `name` and
`age`, to type-check API responses against expected data structures. The example
involves creating a chat completion request using the OpenAI model "gpt-3.5-turbo,"
which is expected to return data conforming to the `User` TypedDict format. Key
points include Python TypedDicts, OpenAI integration, response validation, and
TypedDicts for structured data handling.
concepts/types.md:
hash: 5c4f474578740ebe82ac906cadfb324d
summary: This document provides an overview of how the Instructor library supports
simple types like `str`, `int`, `float`, `bool`, `Union`, `Literal`, and advanced
data types such as `Annotated`, `Enum`, `List`, and `Union` out-of-the-box. It
demonstrates how these types can be directly used in response models, drawing
on the power of `pydantic.BaseModel` for validation and schema creation. Key examples
cover configurations for openai API responses, including handling complex data
structures like `pandas.DataFrame`, and using advanced type annotations and schemas.
The document emphasizes the flexibility and extensibility of Instructor in managing
both primitive and complex data types within Python applications. Keywords include
Pydantic, Python type annotations, Instructor library, OpenAI integration, and
data validation.
concepts/union.md:
hash: 3f8f5dfa16758a160bb5243f95aa22e7
summary: This text discusses the use of `Union` types in Pydantic models, which
are employed to represent values that can be one of several types. The example
provided illustrates how to create _agents_ that dynamically choose actions by
selecting an output class, such as in search and lookup functions where different
actions like executing another search or lookup can be determined. The code snippet
demonstrates defining `Search` and `Lookup` classes with an `execute` method,
and an `Action` class that utilizes a `Union` type to execute one of these actions.
For further details, reference is made to 'examples/union/run.py'. Key points
include the flexibility and dynamic functionality provided by `Union` types in
creating adaptable and efficient operations, especially relevant in Python application
development.
concepts/usage.md:
hash: a7199c1ee62fb9189bda5ad0dceda5ff
summary: The text provides a guide on handling non-streaming requests using the
OpenAI API and the `instructor` Python library. It demonstrates how to access
usage data for these requests, highlighting a method to retrieve token details
such as completion tokens, prompt tokens, and total tokens. Additionally, it discusses
how to handle exceptions like `IncompleteOutputException` when the context length
is exceeded, suggesting to adjust the prompt accordingly. Key topics include using
the OpenAI GPT-3.5-turbo model, handling Pydantic models, and managing API responses.
Essential keywords include OpenAI API, token usage, error handling, Python, and
Pydantic.
contributing.md:
hash: 9f2e20be2b0d0c1e3f592893aca7272a
summary: Contribute to the `Instructor` project by creating evals using pytest to
assess OpenAI models and the instructor library. Participation involves monitoring
model quality with weekly tests, filing issues for bugs with detailed examples,
and submitting pull requests, particularly for issues labeled "help wanted" or
"good first issue." Use tools like `Grit` for code checks, and explore MkDocs
features like `mkdocs serve`, `hl_lines` in code blocks, and admonitions for documentation
improvements. Enhance SEO by emphasizing keywords such as "pytest evals," "OpenAI
model quality," "bug filing and issue tracking," "pull requests," and "MkDocs
documentation."
examples/batch_job_oai.md:
hash: 0fd755b51960cb08d63186828ca59809
summary: This tutorial provides a comprehensive guide on using OpenAI's Batch API
for large-scale synthetic data generation, focusing on creating synthetic questions
using the `ms-marco` dataset. It highlights the cost-effectiveness, higher rate
limits, and model compatibility benefits of the Batch API compared to standard
API calls. The guide includes a step-by-step process to generate question-answer
pairs using the `instructor` library, create compatible `.jsonl` files, and manage
batch jobs via a CLI command. It also covers parsing the generated responses using
Pydantic models, ensuring efficient use of AI for non-time-sensitive tasks that
require processing large data volumes. Key elements include use cases for the
Batch API, command-line interfaces, batch job management, and synthetic data generation.
examples/bulk_classification.md:
hash: debc068b30a32f46f4ac46fcb8425a58
summary: This tutorial provides a comprehensive guide on bulk classification using
user-provided tags, highlighting its application in tasks like document classification
within RAG applications. It emphasizes defining a structured schema to store tags,
such as tag ID, name, and description, in a database. The process involves implementing
models using Pydantic to ensure accurate validation and minimize errors like hallucinations
during classification with an `AsyncOpenAI` client. Key steps include setting
up a tagging system with FastAPI endpoints and making asynchronous predictions
using OpenAI's GPT model. Additionally, it suggests improvements like incorporating
confidence scores and multi-class classification to enhance robustness. Core keywords
include classification, user-provided tags, Pydantic, OpenAI, AsyncOpenAI, FastAPI,
schema, and multi-class classification.
examples/classification.md:
hash: 2b631e2ac4984e33c8aa426e83f04321
summary: This tutorial demonstrates how to implement text classification tasks,
including single-label and multi-label classifications, using the OpenAI API and
Pydantic models. It emphasizes the use of Literal types instead of enums for improved
type checking, and the inclusion of few-shot examples to enhance classification
accuracy. The tutorial covers the definition of Pydantic structures for different
classification tasks, and the development of functions that utilize these structures
for categorizing text as SPAM or NOT_SPAM, and support tickets into categories
like TECH_ISSUE, BILLING, and GENERAL_QUERY. Key strategies like providing chain
of thought explanations and leveraging prompting techniques are also highlighted
to refine the model's prediction capabilities.
examples/document_segmentation.md:
hash: 51a4ec944b26fe523f81a04af3ef2958
summary: This guide explains how to perform document segmentation using Cohere's
command-r-plus LLM, which accommodates a 128k context length. By defining structured
data models, such as `Section` and `StructuredDocument`, and using a systematic
preprocessing method that enumerates the document lines, users can leverage LLMs
to split complex documents into meaningful sections centered around single concepts.
The guide also presents an example using a tutorial on the Transformer architecture
by Sebastian Raschka. Key terms include document segmentation, LLM, Transformer
architecture, structured output, and multi-head attention. This method offers
an efficient way to handle documents with varying content types, such as code
snippets or equations, without relying on simplistic text-splitting rules.
examples/entity_resolution.md:
hash: a245a0fa35ec48ea6e1dc8e505a9a3f1
summary: 'The guide on "Entity Resolution and Visualization for Legal Documents"
demonstrates how to extract and resolve entities from legal contracts using AI,
specifically OpenAI''s API, and visualize them as an entity graph. Core components
include defining data structures with `Entity` and `Property` classes and utilizing
the `DocumentExtraction` model. The process involves extracting entities, resolving
dependencies, and visualizing these as an interactive graph using Graphviz. This
method aids in understanding complex legal documents, highlighting intricate details
and interconnected clauses. Keywords: entity resolution, legal contracts, visualization,
AI, OpenAI API, Graphviz, data structures, document extraction, entity graph.'
examples/exact_citations.md:
hash: 01fae6ee2e6505a4dbca84443ff2f89a
summary: This article explains an example of using the Instructor framework with
validators to ensure that AI-generated answers are backed by direct quotes from
the context, thereby preventing misinformation or hallucinations. It introduces
two main data structures, the `Fact` and `QuestionAnswer` classes, which encapsulate
statements and their supporting context quotes. The example uses Python and OpenAI's
API to validate answers by checking that each fact has corresponding valid quotes.
This method enhances answer reliability by only including facts with verifiable
sources, making it valuable for applications requiring precise citations. Key
terms include validated citations, fact verification, AI-generated answers, OpenAI
API, and context-based validation.
examples/examples.md:
hash: 93b8e3ebe40d4bc57d4c474a5dd82cad
summary: The content provides guidance on enhancing Pydantic models by incorporating
examples directly into the JSON schema extra, which enhances clarity and usability.
It features Python code that demonstrates how to define a Pydantic model, `SyntheticQA`,
with a set of example questions and answers embedded in the schema. The code also
includes a function, `get_synthetic_data()`, that uses OpenAI's API to generate
synthetic examples based on a prompt. Key concepts include integrating practical
examples into code schemas, using Pydantic for data validation, and leveraging
OpenAI's API for generating synthetic data. Keywords include Pydantic, JSON schema,
Python, OpenAI, synthetic data, and model examples.
examples/extract_slides.md:
hash: d2372bf70450ea0bf7de4447c1dc9b10
summary: This guide provides a comprehensive approach to extracting data from slides,
emphasizing the need to not only isolate text but also consider images that might
contain crucial information. The focus is on creating a structured data model
using Pydantic, which categorizes competitors by industry, facilitating their
identification and analysis. A function is defined to read images from URLs and
extract relevant competitor information using AI, specifically leveraging OpenAI's
capabilities. The process is demonstrated with a sample execution, showcasing
the extraction of competitor details and features from images. Key concepts include
data extraction, competitor analysis, AI integration, and image processing.
examples/extracting_receipts.md:
hash: 581d01ba20ae695f6949198019dc1a88
summary: This post demonstrates the use of Python's Pydantic library and OpenAI's
GPT-4 model for extracting and validating receipt data from images, ideal for
automating expense tracking and financial analysis tasks. It defines `Item` and
`Receipt` classes to structure data, and uses a custom validation function to
ensure that the total amount matches the sum of item prices. The `extract_receipt`
function processes image URLs using OpenAI's tools to extract receipt information.
Key steps include defining data models, implementing validation, and utilizing
GPT-4 for image analysis. This method enhances accuracy in financial data extraction
and automation.
examples/extracting_tables.md:
hash: e57703d6aa37be746110157fa77356e2
summary: 'This post demonstrates how to extract tables from images using Python
and OpenAI''s advanced vision model. By leveraging custom type annotations in
Python, such as `MarkdownDataFrame`, and the `pydantic` and `pandas` libraries,
it efficiently converts tables into markdown format for easier data analysis and
automation. The provided code, available on GitHub, outlines the setup of a `Table`
class for organizing extracted data and a function to extract tables using the
`OpenAI` client, patched with the `instructor` library. The method effectively
handles tables from complex images, such as an example showcasing the top-grossing
apps in Ireland, and is ideal for tasks requiring structured data output. Key
terms: table extraction, OpenAI vision model, Python programming, markdown conversion,
data automation.'
examples/groq.md:
hash: d42d7fae7d25e63956811a3601dac868
summary: This guide introduces the use of Groq for AI inference, highlighting the
transition from traditional platforms like OpenAI and Anthropic to Groq using
the mixtral-8x7b model. The document outlines the steps to access Groq's API by
creating an API key on [groqcloud](https://console.groq.com). It provides installation
instructions for necessary Python packages such as `instructor`, `groq`, `pydantic`,
`openai`, and `anthropic`, and explains how to set up the Groq API key environment
variable. An example Python script demonstrates how to use Groq for structured
data output, particularly showcasing a model that provides information about subjects,
such as facts about the company Tesla in the demonstrated output. Additionally,
the content references another useful script, `groq_example2.py`, available in
the repository. Key terms include Groq, API key, mixtral-8x7b model, structured
outputs, GroqCloud, and Python integration.
examples/image_to_ad_copy.md:
hash: 8a1d68f85eaf52fd3348a081c047eb45
summary: This post outlines how to utilize the GPT-4 Vision API and Chat API to
automate the creation of advertising copy from product images, an innovative solution
beneficial for marketing teams and e-commerce platforms. The process involves
building models to identify and describe products from images, using the Vision
API for product detection, and employing Chat API to generate engaging advertising
copy. Key components include defining Python models using Pydantic to ensure data
consistency, and deploying functions for product detection and ad copy generation.
Core ideas include automation, AI-driven marketing solutions, and product image
analysis, highlighting key features, descriptions, and advertising strategies.
examples/index.md:
hash: 275769f86bdff0c1ba527ea9a0830aef
summary: "Discover a comprehensive collection of cookbooks designed to showcase\
\ the power of structured outputs in AI applications. This resource offers practical\
\ examples and guides on various AI techniques, including classifying using enums,\
\ AI self-assessment, batch classification, extracting tables with GPT-Vision,\
\ entity resolution, and more. Learn how to implement advanced AI strategies,\
\ such as generating knowledge graphs, segmenting documents, and using multi-modal\
\ data with tools like OpenAI\u2019s APIs, local models from Ollama, and Mistral/Mixtral.\
\ Maximize efficiency and cost-effectiveness with insights on saving API costs\
\ and storing responses in databases. Ideal for developers and AI enthusiasts\
\ looking to solve real-world problems with structured AI outputs. Subscribe to\
\ our newsletter for updates and tips on enhancing AI applications. Key topics:\
\ AI applications, structured outputs, instructor models, classification, entity\
\ extraction, GPT-Vision, multi-modal data, OpenAI APIs."
examples/knowledge_graph.md:
hash: 99f0d0e7707d598cf3f85562c2c59b59
summary: This guide explores how to effectively visualize knowledge graphs for complex
topics using the Instructor library, Pydantic, and Graphviz. It explains the creation
and structuring of knowledge graphs with `Node` and `Edge` objects, generated
through OpenAI's API, and how these can be visualized using Graphviz. Additionally,
it covers an iterative approach to updating and expanding knowledge graphs by
continuously integrating new information, demonstrated with an example of generating
a comprehensive graph from multiple textual inputs. This automated process simplifies
understanding of intricate subjects like quantum mechanics, enhancing learning
and retention. Key points emphasize on modeling, API usage, visualization, iterative
updates, and the integration with open-source libraries.
examples/local_classification.md:
hash: ac2f251e89cb575947a5bddddbf87cc8
summary: This article guides users on how to use Llama-cpp-python with the `instructor`
library for classifying confidential data securely on local infrastructure. By
employing models like `Mistral-7B-Instruct-v0.2-GGUF`, users can handle queries
about document content, last modified dates, access permissions, and related documents
without data leaving their system. It covers setup instructions, including necessary
installations and configurations for systems with and without GPUs, ensuring data
privacy and security. Additionally, it demonstrates integrating the solution with
Python, highlighting the ability to perform complex document-related AI tasks
locally. Key terms include "local models," "confidential data," "data privacy,"
"llama-cpp-python," "AI document classification," and "secure processing."
examples/mistral.md:
hash: 1117552d2bc7fc47ae3b6ea7844107ec
summary: This guide provides an overview of using MistralAI models, specifically
the mistral-large-latest, for structured outputs in Python applications. It details
the steps required to obtain a Mistral API key from the MistralAI website and
showcases an example using the MistralClient for inference. Important aspects
include installing necessary packages like `instructor`, `mistralai`, and `pydantic`,
and setting up the API key for authentication. The example demonstrates using
a custom data model with Pydantic to structure outputs with MistralAI, highlighting
the integration of tools for improved data handling and response formatting. Keywords
include MistralAI, MistralClient, structured outputs, API key, Pydantic, and Python
integration.
examples/moderation.md:
hash: 7c7c016150aba8d8eb2605ce1953a654
summary: This text introduces OpenAI's moderation endpoint, a tool designed to ensure
content compliance with OpenAI's usage policies by identifying and filtering harmful
content. The moderation model categorizes flagged content into areas such as hate,
harassment, self-harm, sexual content, and violence, each with subcategories for
detailed classification. The text outlines how to incorporate this moderation
tool to monitor API inputs and outputs using an example code snippet with Python
and Pydantic. Keywords include OpenAI, moderation, content compliance, harmful
content, categorization, monitoring, API, and validation.
examples/multi_modal_gemini.md:
hash: 38fccdafc78b0e980571a9ce79738642
summary: 'This tutorial demonstrates how to use `instructor` with `google-generativeai`
for handling multi-modal data, specifically focusing on integration with audio
files. It provides three methods: uploading an entire audio file for analysis,
using inline audio segments with the `pydub` library, and handling lists containing
various content types. The tutorial uses an example of a State of the Union address
by President John F. Kennedy. Key points include setting the mode to `GEMINI_JSON`
for multi-modal input handling, using `genai.upload_file` for file uploads, and
ensuring that large files respect payload size limitations. These strategies facilitate
audio transcription, file management, and efficient LLM interaction with audio
data. Core ideas emphasize seamless integration with multi-modal audio data and
leveraging Google''s generative AI for audio analysis. Keywords: multi-modal data,
audio files, generative AI, LLM, transcription, Google Gemini, audio integration,
State of the Union Address.'
examples/ollama.md:
hash: 3dd1e7df7c09c23ba733763afb755f2e
summary: This blog post explores how to leverage Ollama's OpenAI compatibility layer
to generate structured outputs using JSON schema from open-source Large Language