Skip to content

Commit

Permalink
Refreshed examples
Browse files Browse the repository at this point in the history
  • Loading branch information
ddebowczyk committed Apr 15, 2024
1 parent 3ee5b88 commit 304ea49
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 35 deletions.
31 changes: 31 additions & 0 deletions docs/hub/scalars.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Extracting Scalar Values

Sometimes we just want to get quick results without defining a class for
the response model, especially if we're trying to get a straight, simple
answer in a form of string, integer, boolean or float. Instructor provides
a simplified API for such cases.

<?php
use Cognesy\Instructor\Extras\Scalars\Scalar;
use Cognesy\Instructor\Instructor;
enum CitizenshipGroup : string {
case US = "us";
case Canada = "uk";
case Other = "other";
}
$text = "His name is Jason, he is 28 years old and he lives in Germany.";
$value = (new Instructor)->respond(
messages: [
['role' => 'system', 'content' => $text],
['role' => 'user', 'content' => 'What is Jason\'s citizenship?'],
],
responseModel: Scalar::enum(CitizenshipGroup::class, name: 'citizenshipGroup'),
);

dump($value);

assert($value instanceof CitizenshipGroup);
expect($value == CitizenshipGroup::Other);
71 changes: 36 additions & 35 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -189,41 +189,42 @@ nav:
- Hub:
- Introducing Instructor Hub: 'hub/index.md'
###HUB-INDEX-START###
- Arbitrary properties: 'hub/arbitrary_properties.md'
- Consistent values of arbitrary properties: 'hub/arbitrary_properties_consistency.md'
- Chain of Thought: 'hub/chain_of_thought.md'
- Single label classification: 'hub/classification.md'
- Multiclass classification: 'hub/classification_multiclass.md'
- Extraction of complex objects: 'hub/complex_object_extraction.md'
- Extraction of complex objects (Anthropic): 'hub/complex_object_extraction_anthropic.md'
- Customize parameters of OpenAI client: 'hub/custom_client_parameters.md'
- Custom validation using Symfony Validator: 'hub/custom_validator.md'
- Debugging: 'hub/debugging.md'
- Entity Relationship Extraction: 'hub/entity_relationships.md'
- Handling errors: 'hub/handling_errors.md'
- Support for Anthropic API: 'hub/l_l_m_support_anthropic.md'
- Support for Anyscale API: 'hub/l_l_m_support_anyscale.md'
- Azure support: 'hub/l_l_m_support_azure_o_a_i.md'
- Support for Fireworks.ai API: 'hub/l_l_m_support_fireworks_a_i.md'
- Support for Groq API: 'hub/l_l_m_support_groq.md'
- Support for Mistral API: 'hub/l_l_m_support_mistral.md'
- Support for local Ollama: 'hub/l_l_m_support_ollama.md'
- Support for OpenAI API: 'hub/l_l_m_support_open_a_i.md'
- Support for OpenRouter API: 'hub/l_l_m_support_open_router.md'
- Support for Together.ai API: 'hub/l_l_m_support_together_a_i.md'
- Limiting the length of lists: 'hub/limiting_length_of_lists.md'
- Making some fields optional: 'hub/optional_fields.md'
- Streaming partial updates during inference: 'hub/partial_updates.md'
- Private vs public object field: 'hub/private_vs_public_fields.md'
- Restating instructions: 'hub/restating_instructions.md'
- Ask LLM to rewrite instructions: 'hub/rewriting_instructions.md'
- Expanding Search Queries: 'hub/search_criteria.md'
- Automatic correction based on validation results: 'hub/self_correction.md'
- Extracting sequences of objects: 'hub/sequences.md'
- Reusing components: 'hub/time_range.md'
- Using CoT to improve interpretation of component data: 'hub/time_range_with_co_t.md'
- ValidationMixin: 'hub/validation_mixin.md'
- Receive and process Instructor's internal events: 'hub/wiretap.md'
- Arbitrary properties: 'hub/arbitrary_properties.md'
- Consistent values of arbitrary properties: 'hub/arbitrary_properties_consistency.md'
- Chain of Thought: 'hub/chain_of_thought.md'
- Single label classification: 'hub/classification.md'
- Multiclass classification: 'hub/classification_multiclass.md'
- Extraction of complex objects: 'hub/complex_object_extraction.md'
- Extraction of complex objects (Anthropic): 'hub/complex_object_extraction_anthropic.md'
- Customize parameters of OpenAI client: 'hub/custom_client_parameters.md'
- Custom validation using Symfony Validator: 'hub/custom_validator.md'
- Debugging: 'hub/debugging.md'
- Entity Relationship Extraction: 'hub/entity_relationships.md'
- Handling errors: 'hub/handling_errors.md'
- Support for Anthropic API: 'hub/l_l_m_support_anthropic.md'
- Support for Anyscale API: 'hub/l_l_m_support_anyscale.md'
- Azure support: 'hub/l_l_m_support_azure_o_a_i.md'
- Support for Fireworks.ai API: 'hub/l_l_m_support_fireworks_a_i.md'
- Support for Groq API: 'hub/l_l_m_support_groq.md'
- Support for Mistral API: 'hub/l_l_m_support_mistral.md'
- Support for local Ollama: 'hub/l_l_m_support_ollama.md'
- Support for OpenAI API: 'hub/l_l_m_support_open_a_i.md'
- Support for OpenRouter API: 'hub/l_l_m_support_open_router.md'
- Support for Together.ai API: 'hub/l_l_m_support_together_a_i.md'
- Limiting the length of lists: 'hub/limiting_length_of_lists.md'
- Making some fields optional: 'hub/optional_fields.md'
- Streaming partial updates during inference: 'hub/partial_updates.md'
- Private vs public object field: 'hub/private_vs_public_fields.md'
- Restating instructions: 'hub/restating_instructions.md'
- Ask LLM to rewrite instructions: 'hub/rewriting_instructions.md'
- Extracting Scalar Values: 'hub/scalars.md'
- Expanding Search Queries: 'hub/search_criteria.md'
- Automatic correction based on validation results: 'hub/self_correction.md'
- Extracting sequences of objects: 'hub/sequences.md'
- Reusing components: 'hub/time_range.md'
- Using CoT to improve interpretation of component data: 'hub/time_range_with_co_t.md'
- ValidationMixin: 'hub/validation_mixin.md'
- Receive and process Instructor's internal events: 'hub/wiretap.md'
###HUB-INDEX-END###
# - Single Classification Model: 'hub/single_classification.md'
# - Multiple Classification Model: 'hub/multiple_classification.md'
Expand Down

0 comments on commit 304ea49

Please sign in to comment.