### Example Budget Question Details Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/questions.mdx Retrieves and displays the properties of an example QuestionBudget instance created using the `example` class method. This is useful for understanding the default configuration. ```python >>> q = QuestionBudget.example() >>> q.question_name 'food_budget' >>> q.question_text 'How would you allocate $100?' >>> q.budget_sum 100 >>> q.question_options ['Pizza', 'Ice Cream', 'Burgers', 'Salad'] ``` -------------------------------- ### Instantiate and Run a Question Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/questions.mdx This example demonstrates how to create a question instance, connect it to a language model, and execute it to get a result. Ensure the Model is imported from edsl.language_models. ```python # Create a question question = FreeTextQuestion( question_name=”opinion”, question_text=”What do you think about AI?” ) # Connect to a language model and run from edsl.language_models import Model model = Model() result = question.by(model).run() ``` -------------------------------- ### Get an example LikertFive Question Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/questions.mdx Call the example method on the QuestionLikertFive class to get a pre-configured instance for demonstration. ```python QuestionLikertFive.example() ``` -------------------------------- ### Basic QuestionNumerical Example Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/questions.mdx Demonstrates creating a QuestionNumerical instance, defining agents, and running the question to get results. ```python from edsl import QuestionNumerical, Agent q_random = QuestionNumerical( question_name = "random", question_text = "Choose a random number between 1 and 1000." ) agents = [Agent({"persona":p}) for p in ["Dog catcher", "Magician", "Spy"]] results = q_random.by(agents).run() results.select("persona", "random") ``` -------------------------------- ### Create a QuestionMatrix Using Example Method Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/questions.mdx A convenience method to create an example instance of QuestionMatrix. ```python QuestionMatrix.example() ``` -------------------------------- ### Create Example Jobs Instance Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/jobs.mdx Demonstrates how to create a default example instance of the Jobs class. This is useful for testing and examples. ```python >>> Jobs.example() Jobs(...) ``` -------------------------------- ### Generate Example QuestionInterview Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/questions.mdx Create a sample QuestionInterview instance for testing or demonstration using the `example()` class method. ```python QuestionInterview.example() ``` -------------------------------- ### Run Example Question and Select Results Source: https://github.com/expectedparrot/edsl/blob/main/docs/notebooks/question_extract_example.ipynb Execute an example QuestionExtract and then use .select() to retrieve the extracted data, which is returned as a Dataset object. ```python results = QuestionExtract.example().run() results.select("extract_name") ``` -------------------------------- ### Create a Basic Example Survey Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/surveys.mdx Demonstrates how to create a basic example survey and access its questions. ```python >>> s = Survey.example() >>> [q.question_text for q in s.questions] ['Do you like school?', 'Why not?', 'Why?'] ``` -------------------------------- ### Get and Instantiate an App Source: https://github.com/expectedparrot/edsl/blob/main/edsl/macros/examples/yc/Untitled.ipynb Retrieves a specific application by its name from the AppRegistry and instantiates it with required parameters. This example shows how to get the 'advice_to_checklist' app. ```python survey = AppRegistry.get_app("advice_to_checklist")(advice_text=yc_advice) ``` -------------------------------- ### Create Example QuestionTopK Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/questions.mdx Generates an example instance of the QuestionTopK class using its example method. ```python QuestionTopK.example() ``` -------------------------------- ### Create a QuestionCheckBox using example() Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/questions.mdx Generate a default QuestionCheckBox instance using the static example() method for quick testing or demonstration. ```python QuestionCheckBox.example() ``` -------------------------------- ### Create an Example QuestionBudget Instance Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/questions.mdx Use the `example` class method to quickly create a predefined instance of QuestionBudget for demonstration or testing purposes. ```python QuestionBudget.example() ``` -------------------------------- ### Install ffmpeg Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/notebooks/video_scenario_example.mdx Before using video scenarios, ensure you have the ffmpeg package installed. This is a prerequisite for handling video files. ```bash # brew install ffmpeg ``` -------------------------------- ### example Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/dataset.mdx Returns an example Dataset, optionally with a specified number of entries. ```APIDOC ## example ### Description Return an example dataset. ### Method `example(n: int = None)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters * **n** (int) - Optional - The number of example entries to return. ### Response #### Success Response (200) Dataset: An example Dataset. ### Request Example ```python >>> Dataset.example() Dataset([{'a': [1, 2, 3, 4]}, {'b': [4, 3, 2, 1]}]) ``` ```python >>> Dataset.example(n =2) Dataset([{'a': [1, 1]}, {'b': [2, 2]}]) ``` ``` -------------------------------- ### Get an example Result object Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/results.mdx Shows how to obtain a sample Result object for testing or demonstration purposes. It also verifies the type and instance of the returned object. ```python >>> result = Result.example() >>> type(result) >>> isinstance(result, Result) True ``` -------------------------------- ### Create Example QuestionList Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/questions.mdx Generates an example instance of the QuestionList class using its example method. ```python QuestionList.example() ``` -------------------------------- ### Create Example Scenario Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/scenarios.mdx Returns a pre-defined example Scenario instance. Useful for testing or quick demonstrations. ```python >>> s = Scenario.example() >>> 'persona' in s True ``` -------------------------------- ### Create a Multiple Choice Question using example() Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/questions.mdx Generate a default example of a QuestionMultipleChoice question using the static example method. ```python QuestionMultipleChoice.example() ``` -------------------------------- ### Generate Example QuestionDropdown Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/questions.mdx Quickly create a sample QuestionDropdown instance for testing or demonstration purposes using the `example()` class method. ```python QuestionDropdown.example() ``` -------------------------------- ### Run Example Question Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/questions.mdx Executes an example question with a specified model and returns the results. Useful for quick demonstrations and testing, especially with remote inference and cache disabled. ```python from edsl.language_models import LanguageModel from edsl import QuestionFreeText as Q m = Q._get_test_model(canned_response="Yo, what's up?") results = Q.run_example(show_answer=True, model=m, disable_remote_cache=True, disable_remote_inference=True) ``` -------------------------------- ### example Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/agents.mdx Returns an example Agent instance. Can optionally randomize the instance. ```APIDOC ## example ### Description Returns an example Agent instance. Can optionally randomize the instance. ### Method ``` classmethod example(randomize: bool = False) ``` ### Parameters #### Path Parameters - **randomize** (bool) - Optional - Defaults to False. Whether to randomize the agent instance. ``` -------------------------------- ### Generate an Example QuestionDict Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/questions.mdx Use the class method `example()` to create a sample instance of QuestionDict. This is helpful for quick testing or understanding the class structure. ```python QuestionDict.example() ``` -------------------------------- ### Create an Example Survey with Parameter Substitution Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/surveys.mdx Shows how to create an example survey with parameter substitution enabled, illustrating dynamic question text. ```python >>> s = Survey.example(params=True) >>> s.questions[3].question_text "To the question '{{ q0.question_text}}', you said '{{ q0.answer }}'. Do you still feel this way?" ``` -------------------------------- ### QuestionFunctional Example Usage Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/questions.mdx Demonstrates creating and activating a QuestionFunctional instance with a predefined example function and running it with a scenario and agent. ```python from edsl import Scenario, Agent # Create an instance of QuestionFunctional with the new function question = QuestionFunctional.example() # Activate and test the function question.activate() scenario = Scenario({"numbers": [1, 2, 3, 4, 5]}) agent = Agent(traits={"multiplier": 10}) results = question.by(scenario).by(agent).run(disable_remote_cache = True, disable_remote_inference = True) results.select("answer.*").to_list()[0] == 150 ``` -------------------------------- ### Generate Example Linear Scale Question Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/questions.mdx Use the static example method to create a default instance of QuestionLinearScale. ```python QuestionLinearScale.example() ``` -------------------------------- ### FileStore.example Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/filestore.mdx Returns an example Scenario instance. This can be used for testing or demonstration purposes. The 'randomize' argument can be used to ensure uniqueness of the example data. ```APIDOC ## classmethod example(*, example_type='txt', randomize: bool = False) ### Description Returns an example Scenario instance with FileStore objects. ### Parameters * **example_type** (str) - Optional - The type of example to generate (e.g., 'txt', 'png', 'mp4'). Defaults to 'txt'. * **randomize** (bool) - Optional - If True, adds a random string to the value of the example key to ensure uniqueness. Defaults to False. ### Returns Scenario: A Scenario instance with example data. ### Examples ```python >>> s = Scenario.example() >>> 'persona' in s True >>> s1 = Scenario.example(randomize=True) >>> s2 = Scenario.example(randomize=True) >>> s1.data != s2.data True ``` ``` -------------------------------- ### example Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/results.mdx Returns an example Results object, with an option to randomize agent and scenario combinations. ```APIDOC ## example ### Description Return an example Results object. ### Method `*classmethod* example(*randomize: bool = False*)` ### Parameters #### Keyword Arguments * **randomize** (bool) - Optional - if True, randomizes agent and scenario combinations. ### Returns [Results](/en/latest/#edsl.results.Results "edsl.results.results.Results") ### Examples ```python >>> r = Results.example() ``` ``` -------------------------------- ### example() Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/surveys.mdx Create an example survey for testing and demonstration purposes. This method creates a simple branching survey about school preferences. ```APIDOC ## *classmethod* example(*params: bool = False*, *randomize: bool = False*, *include_instructions: bool = False*, *custom_instructions: str | None = None*) ### Description Create an example survey for testing and demonstration purposes. ### Method GET (assumed) ### Endpoint `/example` (assumed) ### Parameters #### Query Parameters - **params** (boolean) - Optional - If True, adds a fourth question that demonstrates parameter substitution by referencing the question text and answer from the first question. - **randomize** (boolean) - Optional - If True, adds a random UUID to the first question text to ensure uniqueness across multiple instances. - **include_instructions** (boolean) - Optional - Whether to include instructions in the example survey. - **custom_instructions** (string) - Optional - Custom instructions to include in the example survey. ### Response #### Success Response (200) - **survey** (Survey) - An example Survey object. ### Response Example ```json { "survey": { "questions": [ { "question_text": "Do you like school?", "question_options": ["Yes", "No"], "question_name": "q0" }, { "question_text": "Why do you like school?", "question_name": "q1" }, { "question_text": "Why do you not like school?", "question_name": "q2" } ] } } ``` ``` -------------------------------- ### Create Example Dataset Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/dataset.mdx Generates a sample Dataset for testing or demonstration purposes. Can create a default example or a specified number of rows. ```python >>> Dataset.example() Dataset( [{'a': [1, 2, 3, 4 ]}, {'b': [4, 3, 2, 1 ]} ]) ``` ```python >>> Dataset.example(n =2) Dataset( [{'a': [1, 1 ]}, {'b': [2, 2 ]} ]) ``` -------------------------------- ### Create a QuestionExtract Instance Using Example Method Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/questions.mdx A convenient class method to create an example instance of QuestionExtract. ```python QuestionExtract.example() ``` -------------------------------- ### AgentList Example Transformation Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/agents.mdx Demonstrates transforming an AgentList example into a scenario list and dropping a specific trait. ```python >>> AgentList.example().to_scenario_list().drop('age') ScenarioList([Scenario({'hair': 'brown', 'height': 5.5}), Scenario({'hair': 'brown', 'height': 5.5})]) ``` -------------------------------- ### Generate Example Free Text Question Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/questions.mdx Use the example() class method to create a default instance of QuestionFreeText. ```python QuestionFreeText.example() ``` -------------------------------- ### Create and Run a Multiple Choice Question Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/overview.mdx Define a multiple-choice question using EDSL and run it to get a response from a language model. This is a basic example to get started with EDSL surveys. ```python from edsl import QuestionMultipleChoice q = QuestionMultipleChoice( question_name = "capital", question_text = "What is the capital of France?", question_options = ["Berlin", "Rome", "Paris", "Madrid", "London"] ) results = q.run() ``` -------------------------------- ### Create an Agent instance Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/agents.mdx Demonstrates how to create a basic Agent instance. ```python >>> Agent.example() Agent(traits = {'age': 22, 'hair': 'brown', 'height': 5.5}) ``` -------------------------------- ### Create and Run a Video Scenario Question Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/notebooks/video_scenario_example.mdx This snippet shows how to create a FileStore object for a local video, set up a scenario with the video, define a free-text question referencing the video, and run it using a model. ```python from edsl import FileStore, QuestionFreeText, Scenario, Model fs = FileStore("Nightmare_Before_Christmas_(1993).mp4") s = Scenario({"video":fs}) q = QuestionFreeText( question_name = "test", question_text = "Breifly describe what is happening in this video: {{ scenario.video }}" ) m = Model("gemini-2.5-flash", service_name="google") r = q.by(s).by(m).run() ``` -------------------------------- ### Get Example Numerical Question Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/questions.mdx Calls the example class method to get a pre-configured instance of QuestionNumerical. ```python QuestionNumerical.example() ``` -------------------------------- ### Import EDSL Components for Data Labeling Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/notebooks/data_labeling_agent.mdx Import necessary classes for creating questions, surveys, scenarios, agents, and models from the EDSL library. Ensure you have followed the getting started guide before running this code. ```python from edsl import ( QuestionMultipleChoice, QuestionList, QuestionNumerical, Survey, ScenarioList, AgentList, Agent, Model ) ``` -------------------------------- ### Initialize and Push Notebook Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/notebooks/answering_instructions_example.mdx This snippet demonstrates how to create a Notebook object from a specified file path and then push it to a platform with a description, alias, and visibility settings. ```python from edsl import Notebook nb = Notebook(path = "answering_instructions_example.ipynb") nb.push( description = "Example answering instructions", alias = "answering-instructions-notebook", visibility = "public" ) ``` -------------------------------- ### Get Example Objects Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/notebooks/save_load_objects_locally.mdx Retrieves example instances of various EDSL objects using the `example()` method. These can be used for testing or demonstration purposes. ```python my_question = QuestionFreeText.example() my_survey = Survey.example() my_scenariolist = ScenarioList.example() my_scenario = Scenario.example() my_agentlist = AgentList.example() my_agent = Agent.example() ``` -------------------------------- ### Get Prompt Text Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/prompts.mdx A simple example showing how to get the text content of a Prompt object. ```python >>> p = Prompt("Hello, {{person}}") ``` -------------------------------- ### Get Example AgentList Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/agents.mdx Retrieves a pre-defined example AgentList. Can be used with or without a custom codebook for trait descriptions. ```python al = AgentList.example() al AgentList([Agent(traits = {'age': 22, 'hair': 'brown', 'height': 5.5}), Agent(traits = {'age': 22, 'hair': 'brown', 'height': 5.5})]) ``` ```python al = AgentList.example(codebook={'age': 'Age in years'}) al[0].codebook {'age': 'Age in years'} ``` -------------------------------- ### Create a Text FileStore Instance Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/filestore.mdx Demonstrates how to create a FileStore instance from a local text file. Ensure the file exists and is accessible. ```python import tempfile # Create a text file with tempfile.NamedTemporaryFile(suffix=".txt", mode="w") as f: _ = f.write("Hello World") _ = f.flush() fs = FileStore(f.name) ``` -------------------------------- ### Get an example Rank Question Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/questions.mdx Call the example method on the QuestionRank class to retrieve a sample instance for testing or demonstration. ```python QuestionRank.example() ``` -------------------------------- ### Get Help on EDSL Objects Source: https://github.com/expectedparrot/edsl/blob/main/docs/overview.md Use the built-in `help()` function or object-specific `example()` methods to get information about EDSL objects and their attributes/methods. ```python help(object) object.example() ``` ```python QuestionMultipleChoice.example() ``` -------------------------------- ### Cache.fetch_input_example() Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/data.mdx Creates an example input dictionary for a 'fetch' operation. ```APIDOC ## Cache.fetch_input_example() ### Description Create an example input for a ‘fetch’ operation. ### Method `fetch_input_example() -> dict` ``` -------------------------------- ### Import and Example Question Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/notebooks/starter_tutorial.mdx Import various question types from EDSL and get an example of a QuestionMultipleChoice. Substitute any question type class name for `QuestionMultipleChoice`. ```python from edsl import ( # QuestionCheckBox, # QuestionExtract, # QuestionFreeText, # QuestionFunctional, # QuestionLikertFive, # QuestionLinearScale, # QuestionList, QuestionMultipleChoice, # QuestionNumerical, # QuestionRank, # QuestionTopK, # QuestionYesNo ) q = QuestionMultipleChoice.example() # substitute any question type class name q ``` -------------------------------- ### Get Model Names from Example ModelList Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/language_models.mdx Retrieves the names of models within an example ModelList instance. The output is a set containing model names. ```python >>> ModelList.example().names {...} ``` -------------------------------- ### Create a Simple Scenario Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/scenarios.mdx Initializes a Scenario object with product and price data. ```python s = Scenario({"product": "coffee", "price": 4.99}) ``` -------------------------------- ### Get Image Dimensions Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/filestore.mdx Retrieves the width and height of an image file. Raises a ValueError if the file is not an image or if PIL is not installed. ```python >>> fs = FileStore.example("png") >>> width, height = fs.get_image_dimensions() >>> isinstance(width, int) and isinstance(height, int) True ``` -------------------------------- ### Example Results with ggplot2 Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/scenarios.mdx Demonstrates how to generate a ggplot2 plot from Results. Requires R and ggplot2 to be installed. The code for the plot is provided as a string. ```python >>> from edsl.results import Results >>> r = Results.example() >>> # The following would create a plot if R is installed (not shown in doctest): >>> # r.ggplot2('' >>> # ggplot(df, aes(x=how_feeling)) + >>> # geom_bar() + >>> # labs(title="Distribution of Feelings") >>> # '') ``` -------------------------------- ### Generate ggplot2 Plot Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/agents.mdx This example demonstrates how to create visualizations using R's ggplot2 library from EDSL data. Requires R and ggplot2 to be installed. ```python >>> from edsl.results import Results >>> r = Results.example() >>> # The following would create a plot if R is installed (not shown in doctest): >>> # r.ggplot2(''' >>> # ggplot(df, aes(x=how_feeling)) + >>> # geom_bar() + >>> # labs(title="Distribution of Feelings") >>> # ''') ``` -------------------------------- ### File Push Output Example Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/filestore.mdx Example output from the push method, showing file details like description, object type, URL, UUID, version, and visibility. ```json { 'description': 'My example CSV file', 'object_type': 'scenario', 'url': 'https://www.expectedparrot.com/content/17c0e3d3-8d08-4ae0-bc7d-384a56a07e4e', 'uuid': '17c0e3d3-8d08-4ae0-bc7d-384a56a07e4e', 'version': '0.1.47.dev1', 'visibility': 'public' } ``` -------------------------------- ### Get Survey Parameters Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/surveys.mdx Returns an empty set of parameters for a default example survey. This property is used to track parameters used within survey questions. ```python >>> s = Survey.example() >>> s.parameters set() ``` -------------------------------- ### Create and Inspect Example Results Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/results.mdx Demonstrates how to create a sample Results object and check its contents. Useful for initial data exploration and testing. ```python >>> # Create a simple Results object from example data >>> r = Results.example() >>> len(r) > 0 # Contains Result objects True >>> # Filter and transform data >>> filtered = r.filter("how_feeling == 'Great'") >>> # Access hierarchical data >>> 'agent' in r.known_data_types True ``` -------------------------------- ### Handle start question before end question error Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/surveys.mdx When adding a question group, the `start_question` must precede the `end_question`. This example demonstrates the `SurveyCreationError` raised when the order is incorrect. ```python # Example showing index order error >>> try: ... Survey.example().add_question_group("q1", "q0", "group1") ... except SurveyCreationError: ... print("Error: Start index greater than end index (as expected)") Error: Start index greater than end index (as expected) ``` -------------------------------- ### Cache.example() Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/data.mdx Creates an example Cache instance pre-populated with CacheEntry objects. Useful for testing and demonstration. ```APIDOC ## Cache.example() ### Description Creates an example Cache instance pre-populated with CacheEntry objects. This method is useful for documentation, testing, and demonstration purposes. ### Method `classmethod` ### Parameters #### Keyword Arguments - **randomize** (bool) - Optional - If True, creates CacheEntry objects with randomized content for uniqueness. If False, uses consistent example entries. ### Returns - **Cache**: A new Cache object containing example CacheEntry objects. ### Examples ```python >>> cache = Cache.example() >>> len(cache) > 0 True >>> from edsl.caching.cache_entry import CacheEntry >>> all(isinstance(entry, CacheEntry) for entry in cache.values()) True ``` ```python >>> # Create examples with randomized content >>> cache1 = Cache.example(randomize=True) >>> cache2 = Cache.example(randomize=True) >>> # With randomization, keys should be different >>> len(cache1) > 0 and len(cache2) > 0 True ``` ``` -------------------------------- ### Load and List EDSL Apps Source: https://github.com/expectedparrot/edsl/blob/main/edsl/macros/examples/yc/TwoSentences.ipynb Loads EDSL applications from a specified package and lists the first available app. Ensure the 'edsl' library is installed and the example apps are present in the package. ```python from edsl.app import AppRegistry AppRegistry.from_package("edsl.app.examples") AppRegistry.list()[0] ``` -------------------------------- ### Agent.example() Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/agents.mdx Returns a sample Agent instance with predefined traits. Useful for quick testing or demonstration. ```APIDOC ## Agent.example() ### Description Returns a sample Agent instance with predefined traits. Useful for quick testing or demonstration. ### Method classmethod ### Returns An example Agent instance. ### Example ```python >>> Agent.example() Agent(traits = {'age': 22, 'hair': 'brown', 'height': 5.5}) ``` ``` -------------------------------- ### Generate ggplot2 Plot from Results Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/results.mdx This example demonstrates how to generate a ggplot2 plot from the Results object. It requires R and the ggplot2 package to be installed. The ggplot2 code should reference column names as they appear after any transformations. ```python >>> from edsl.results import Results >>> r = Results.example() >>> # The following would create a plot if R is installed (not shown in doctest): >>> # r.ggplot2('' >>> # ggplot(df, aes(x=how_feeling)) + >>> # geom_bar() >>> # labs(title="Distribution of Feelings") >>> # '') ``` -------------------------------- ### Create Example QuestionYesNo Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/questions.mdx Generates an example instance of the QuestionYesNo class using its example method. ```python QuestionYesNo.example() ``` -------------------------------- ### LanguageModel.example() Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/language_models.mdx Creates an example language model instance for testing and demonstration, with options for real or test models. ```APIDOC ## *classmethod* example(*test_model: bool = False*, *canned_response: str = 'Hello world'*, *throw_exception: bool = False*) ### Description Create an example language model instance for testing and demonstration. This method provides a convenient way to create a model instance for examples, tests, and documentation. It can create either a real model (with API key checking disabled) or a test model that returns predefined responses. ### Args: - test_model (bool): If True, creates a test model that doesn’t make real API calls - canned_response (str): For test models, the predefined response to return - throw_exception (bool): For test models, whether to throw an exception instead of responding ### Returns: LanguageModel: An example model instance ### Examples: Create a test model with a custom response: ```python >>> from edsl.language_models import LanguageModel >>> m = LanguageModel.example(test_model=True, canned_response="WOWZA!") >>> isinstance(m, LanguageModel) True ``` Use the test model to answer a question: ```python >>> from edsl import QuestionFreeText >>> q = QuestionFreeText(question_text="What is your name?", question_name='example') >>> q.by(m).run(cache=False, disable_remote_cache=True, disable_remote_inference=True).select('example').first() 'WOWZA!' ``` Create a test model that throws exceptions: ```python >>> m = LanguageModel.example(test_model=True, canned_response="WOWZA!", throw_exception=True) >>> r = q.by(m).run(cache=False, disable_remote_cache=True, disable_remote_inference=True, print_exceptions=True) Exception report saved to ... ``` ``` -------------------------------- ### Install Datasets Library Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/notebooks/import_agents.mdx Use this command to install the 'datasets' library and its dependencies. Ensure you have pip installed. ```bash ! pip install datasets ``` -------------------------------- ### Initialize and Push Notebook Source: https://github.com/expectedparrot/edsl/blob/main/docs/notebooks/answering_instructions_example.ipynb Initialize a Notebook object with the current notebook's path and push it to Coop with a description, alias, and public visibility. ```python from edsl import Notebook nb = Notebook(path = "answering_instructions_example.ipynb") nb.push( description = "Example answering instructions", alias = "answering-instructions-notebook", visibility = "public" ) ``` -------------------------------- ### Install EDSL from PyPI Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/notebooks/starter_tutorial.mdx Install the EDSL library using pip. It is recommended to use a virtual environment. This command installs the library quietly. ```python # ! uv pip install edsl -q ``` -------------------------------- ### Initialize Investment Budget Question Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/questions.mdx Shows how to initialize a QuestionBudget for an investment scenario, specifying the question details and verifying the assigned question name. ```python >>> q = QuestionBudget( ... question_name="investment", ... question_text="How would you invest $1000?", ... question_options=["Stocks", "Bonds", "Real Estate", "Cash"], ... budget_sum=1000 ... ) >>> q.question_name 'investment' ``` -------------------------------- ### View Datasets Installation Details Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/notebooks/import_agents.mdx This output shows the successful installation of the 'datasets' library and its associated packages. It lists the versions of installed dependencies. ```python Collecting datasets Downloading datasets-3.5.0-py3-none-any.whl.metadata (19 kB) Requirement already satisfied: filelock in /Users/johnhorton/Library/Caches/pypoetry/virtualenvs/edsl-EZo3_VAr-py3.11/lib/python3.11/site-packages (from datasets) (3.18.0) Requirement already satisfied: numpy>=1.17 in /Users/johnhorton/Library/Caches/pypoetry/virtualenvs/edsl-EZo3_VAr-py3.11/lib/python3.11/site-packages (from datasets) (1.26.4) Collecting pyarrow>=15.0.0 (from datasets) Using cached pyarrow-19.0.1-cp311-cp311-macosx_12_0_arm64.whl.metadata (3.3 kB) Collecting dill<0.3.9,>=0.3.0 (from datasets) Downloading dill-0.3.8-py3-none-any.whl.metadata (10 kB) Requirement already satisfied: pandas in /Users/johnhorton/Library/Caches/pypoetry/virtualenvs/edsl-EZo3_VAr-py3.11/lib/python3.11/site-packages (from datasets) (2.2.3) Requirement already satisfied: requests>=2.32.2 in /Users/johnhorton/Library/Caches/pypoetry/virtualenvs/edsl-EZo3_VAr-py3.11/lib/python3.11/site-packages (from datasets) (2.32.3) Requirement already satisfied: tqdm>=4.66.3 in /Users/johnhorton/Library/Caches/pypoetry/virtualenvs/edsl-EZo3_VAr-py3.11/lib/python3.11/site-packages (from datasets) (4.67.1) Collecting xxhash (from datasets) Downloading xxhash-3.5.0-cp311-cp311-macosx_11_0_arm64.whl.metadata (12 kB) Collecting multiprocess<0.70.17 (from datasets) Downloading multiprocess-0.70.16-py311-none-any.whl.metadata (7.2 kB) Collecting fsspec<=2024.12.0,>=2023.1.0 (from fsspec[http]<=2024.12.0,>=2023.1.0->datasets) Downloading fsspec-2024.12.0-py3-none-any.whl.metadata (11 kB) Requirement already satisfied: aiohttp in /Users/johnhorton/Library/Caches/pypoetry/virtualenvs/edsl-EZo3_VAr-py3.11/lib/python3.11/site-packages (from datasets) (3.11.16) Collecting huggingface-hub>=0.24.0 (from datasets) Downloading huggingface_hub-0.30.2-py3-none-any.whl.metadata (13 kB) Requirement already satisfied: packaging in /Users/johnhorton/Library/Caches/pypoetry/virtualenvs/edsl-EZo3_VAr-py3.11/lib/python3.11/site-packages (from datasets) (24.2) Requirement already satisfied: pyyaml>=5.1 in /Users/johnhorton/Library/Caches/pypoetry/virtualenvs/edsl-EZo3_VAr-py3.11/lib/python3.11/site-packages (from datasets) (6.0.2) Requirement already satisfied: aiohappyeyeballs>=2.3.0 in /Users/johnhorton/Library/Caches/pypoetry/virtualenvs/edsl-EZo3_VAr-py3.11/lib/python3.11/site-packages (from aiohttp->datasets) (2.6.1) Requirement already satisfied: aiosignal>=1.1.2 in /Users/johnhorton/Library/Caches/pypoetry/virtualenvs/edsl-EZo3_VAr-py3.11/lib/python3.11/site-packages (from aiohttp->datasets) (1.3.2) Requirement already satisfied: attrs>=17.3.0 in /Users/johnhorton/Library/Caches/pypoetry/virtualenvs/edsl-EZo3_VAr-py3.11/lib/python3.11/site-packages (from aiohttp->datasets) (25.3.0) Requirement already satisfied: frozenlist>=1.1.1 in /Users/johnhorton/Library/Caches/pypoetry/virtualenvs/edsl-EZo3_VAr-py3.11/lib/python3.11/site-packages (from aiohttp->datasets) (1.5.0) Requirement already satisfied: multidict<7.0,>=4.5 in /Users/johnhorton/Library/Caches/pypoetry/virtualenvs/edsl-EZo3_VAr-py3.11/lib/python3.11/site-packages (from aiohttp->datasets) (6.3.1) Requirement already satisfied: propcache>=0.2.0 in /Users/johnhorton/Library/Caches/pypoetry/virtualenvs/edsl-EZo3_VAr-py3.11/lib/python3.11/site-packages (from aiohttp->datasets) (0.3.1) Requirement already satisfied: yarl<2.0,>=1.17.0 in /Users/johnhorton/Library/Caches/pypoetry/virtualenvs/edsl-EZo3_VAr-py3.11/lib/python3.11/site-packages (from aiohttp->datasets) (1.18.3) Requirement already satisfied: typing-extensions>=3.7.4.3 in /Users/johnhorton/Library/Caches/pypoetry/virtualenvs/edsl-EZo3_VAr-py3.11/lib/python3.11/site-packages (from huggingface-hub>=0.24.0->datasets) (4.13.0) Requirement already satisfied: charset-normalizer<4,>=2 in /Users/johnhorton/Library/Caches/pypoetry/virtualenvs/edsl-EZo3_VAr-py3.11/lib/python3.11/site-packages (from requests>=2.32.2->datasets) (3.4.1) Requirement already satisfied: idna<4,>=2.5 in /Users/johnhorton/Library/Caches/pypoetry/virtualenvs/edsl-EZo3_VAr-py3.11/lib/python3.11/site-packages (from requests>=2.32.2->datasets) (3.10) Requirement already satisfied: urllib3<3,>=1.21.1 in /Users/johnhorton/Library/Caches/pypoetry/virtualenvs/edsl-EZo3_VAr-py3.11/lib/python3.11/site-packages (from requests>=2.32.2->datasets) (1.26.20) Requirement already satisfied: certifi>=2017.4.17 in /Users/johnhorton/Library/Caches/pypoetry/virtualenvs/edsl-EZo3_VAr-py3.11/lib/python3.11/site-packages (from requests>=2.32.2->datasets) (2025.1.31) Requirement already satisfied: python-dateutil>=2.8.2 in /Users/johnhorton/Library/Caches/pypoetry/virtualenvs/edsl-EZo3_VAr-py3.11/lib/python3.11/site-packages (from pandas->datasets) (2.9.0.post0) ``` -------------------------------- ### Survey.example() Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/surveys.mdx Creates a basic example survey instance. It can optionally include instructions and parameter substitution. ```APIDOC ## classmethod Survey.example() ### Description Creates a basic example survey instance. It can optionally include instructions and parameter substitution. ### Method classmethod ### Returns Survey: A configured example survey instance. ### Examples Create a basic example survey: ```python >>> s = Survey.example() >>> [q.question_text for q in s.questions] ['Do you like school?', 'Why not?', 'Why?'] ``` Create an example with parameter substitution: ```python >>> s = Survey.example(params=True) >>> s.questions[3].question_text "To the question '{{ q0.question_text}}', you said '{{ q0.answer }}'. Do you still feel this way?" ``` ``` -------------------------------- ### Initializing AgentList with Agents Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/agents.mdx Demonstrates initializing an AgentList with a list of Agent objects, including setting traits and a codebook. ```python >>> from edsl import Agent >>> al = AgentList([Agent(traits = {'age': 22, 'hair': 'brown', 'height': 5.5}), ... Agent(traits = {'age': 22, 'hair': 'brown', 'height': 5.5})]) >>> al AgentList([Agent(traits = {'age': 22, 'hair': 'brown', 'height': 5.5}), Agent(traits = {'age': 22, 'hair': 'brown', 'height': 5.5})]) >>> al_with_codebook = AgentList([Agent(traits = {'age': 22})], codebook={'age': 'Age in years'}) >>> al_with_codebook[0].codebook {'age': 'Age in years'} ``` -------------------------------- ### Example Personas List Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/notebooks/google_form_to_edsl.mdx This is an example output of personas generated by the EDSL question. ```python ['Retired Couple in Suburbia', 'Young Urban Professional', 'Environmentally Conscious Family', 'Small Business Owner', 'Historic Home Enthusiast'] ``` -------------------------------- ### Initialize Notebook and Push/Patch Source: https://github.com/expectedparrot/edsl/blob/main/docs/notebooks/research_methods.ipynb Initializes a Notebook object and demonstrates pushing or patching it to EDSL. ```python from edsl import Notebook nb = Notebook(path = "research_methods.ipynb") if refresh := False: nb.push( description = "Using EDSL to create research methods", alias = "research-methods-notebook", visibility = "public" ) else: nb.patch('50ae2f14-f40f-46c9-8be3-c09f621a677b', value = nb) ``` -------------------------------- ### Install EDSL Source: https://github.com/expectedparrot/edsl/blob/main/docs/notebooks/question_extract_example.ipynb Install the EDSL library. This is a prerequisite for using EDSL functionalities. ```python # ! pip install edsl ``` -------------------------------- ### Exercise and Print Example Source: https://github.com/expectedparrot/edsl/blob/main/integration/notebooks/check_printing.ipynb Defines a function to exercise and print an example from a given module. ```python def exercise(module): example = module.example() example.print() ``` -------------------------------- ### Create and Push a Notebook Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/notebooks/scenarios_filestore_example.mdx Instantiate a Notebook object with its file path and push it to Expected Parrot with a description, alias, and visibility settings. ```python n = Notebook(path = "scenarios_filestore_example.ipynb") ``` ```python n.push( description = "Example code for using data files for scenarios via FileStore and Expected Parrot", alias = "my-scenario-image-notebook", visibility = "public" ) ``` ```json {'description': 'Example code for using data files for scenarios via FileStore and Expected Parrot', 'object_type': 'notebook', 'url': 'https://www.expectedparrot.com/content/0f21a6ba-45b2-4cf2-9bea-87929855797f', 'uuid': '0f21a6ba-45b2-4cf2-9bea-87929855797f', 'version': '0.1.47.dev1', 'visibility': 'public'} ``` -------------------------------- ### Initialize QuestionFreeText with Answering Instructions Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/questions.mdx Shows how to initialize a QuestionFreeText with custom answering instructions. ```python >>> q = QuestionFreeText( ... question_name="explanation", ... question_text="Explain how photosynthesis works.", ... answering_instructions="Provide a detailed scientific explanation." ... ) ``` -------------------------------- ### Self-check Example QuestionList Response Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/questions.mdx Performs a self-check on an example response generated by the QuestionList class. ```python QuestionList.example().self_check() ``` -------------------------------- ### Get Number of Results Source: https://github.com/expectedparrot/edsl/blob/main/docs/mintlify-migration/en/latest/results.mdx Get the total number of results after combining them. This confirms the addition operation. ```python len(add_results) ```