|
1 |
| -.. _scenarios: |
2 |
| - |
3 |
| -`from_prompt` |
4 |
| -def from_prompt(self, description: str, name:Optional[str] = "item", target_number:int = 10, verbose = False): |
5 |
| - from ..questions.question_list import QuestionList |
6 |
| - q = QuestionList(question_name = name, |
7 |
| - question_text = description + f"\n Please try to return {target_number} examples.") |
8 |
| - results = q.run(verbose = verbose) |
9 |
| - return results.select(name).to_scenario_list().expand(name) |
10 |
| - |
11 |
| -`from_search_terms` |
12 |
| -def from_search_terms(cls, search_terms: List[str]) -> ScenarioList: |
13 |
| - """Create a ScenarioList from a list of search terms, using Wikipedia. |
14 |
| - |
15 |
| - Args: |
16 |
| - search_terms: A list of search terms. |
17 |
| - """ |
18 |
| - from ..utilities.wikipedia import fetch_wikipedia_content |
19 |
| - results = fetch_wikipedia_content(search_terms) |
20 |
| - return cls([Scenario(result) for result in results]) |
21 |
| - |
22 |
| -def augment_with_wikipedia(self, search_key:str, content_only: bool = True, key_name: str = "wikipedia_content") -> ScenarioList: |
23 |
| - """Augment the ScenarioList with Wikipedia content.""" |
24 |
| - search_terms = self.select(search_key).to_list() |
25 |
| - wikipedia_results = ScenarioList.from_search_terms(search_terms) |
26 |
| - new_sl = ScenarioList(data = [], codebook = self.codebook) |
27 |
| - for scenario, wikipedia_result in zip(self, wikipedia_results): |
28 |
| - if content_only: |
29 |
| - scenario[key_name] = wikipedia_result["content"] |
30 |
| - new_sl.append(scenario) |
31 |
| - else: |
32 |
| - scenario[key_name] = wikipedia_result |
33 |
| - new_sl.append(scenario) |
34 |
| - return new_sl |
35 |
| - |
36 | 1 | Scenarios
|
37 | 2 | =========
|
38 | 3 |
|
@@ -1903,6 +1868,55 @@ The `show_prompts` method will return the questions created with the f-string wi
|
1903 | 1868 | To learn more about user and system prompts, please see the :ref:`prompts` section.
|
1904 | 1869 |
|
1905 | 1870 |
|
| 1871 | +Special methods |
| 1872 | +--------------- |
| 1873 | + |
| 1874 | +Special methods are available for generating or modifying scenarios using web searches: |
| 1875 | + |
| 1876 | +The `from_prompt` method allows you to create scenarios from a prompt, which can be useful for generating scenarios based on user input or other dynamic sources: |
| 1877 | + |
| 1878 | +.. code-block:: python |
| 1879 | +
|
| 1880 | + from edsl import ScenarioList |
| 1881 | +
|
| 1882 | + scenarios = ScenarioList.from_prompt( |
| 1883 | + description = "What are some popular programming languages?", |
| 1884 | + name = "programming_languages", # optional name for the scenarios; default is "item" |
| 1885 | + target_number = 5, # optional number of scenarios to generate; default is 10 |
| 1886 | + verbose = True # optional flag to return verbose output; default is False |
| 1887 | + ) |
| 1888 | + |
| 1889 | +
|
| 1890 | +The `from_search_terms` method allows you to create scenarios from a list of search terms, which can be useful for generating scenarios based on search queries or other dynamic sources: |
| 1891 | + |
| 1892 | +.. code-block:: python |
| 1893 | +
|
| 1894 | + from edsl import ScenarioList |
| 1895 | +
|
| 1896 | + search_terms = ["Python", "Java", "JavaScript"] |
| 1897 | + scenarios = ScenarioList.from_search_terms(search_terms) |
| 1898 | +
|
| 1899 | +
|
| 1900 | +The method `augment_with_wikipedia` allows you to augment scenarios with information from Wikipedia, which can be useful for enriching scenarios with additional context or data: |
| 1901 | + |
| 1902 | +.. code-block:: python |
| 1903 | +
|
| 1904 | + from edsl import ScenarioList |
| 1905 | +
|
| 1906 | + # method is used to augment existing scenarios |
| 1907 | + scenarios = ScenarioList.from_prompt( |
| 1908 | + description = "What are some popular programming languages?", |
| 1909 | + name = "programming_languages" |
| 1910 | + ) |
| 1911 | + |
| 1912 | + scenarios.augment_with_wikipedia( |
| 1913 | + search_key = "programming languages", |
| 1914 | + content_only = True # default optional flag to return only the content |
| 1915 | + key_name = "wikipedia_content" # default optional key name for the content |
| 1916 | + ) |
| 1917 | +
|
| 1918 | +
|
| 1919 | +
|
1906 | 1920 | Scenario class
|
1907 | 1921 | --------------
|
1908 | 1922 |
|
|
0 commit comments