Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /promptdriven_pdd /context /find_section_example.py
| # Here's a concise example of how to use the `find_section` function from the `find_section.py` module, along with documentation for the input and output parameters. | |
| # ### Example Usage | |
| # ```python | |
| # Import the find_section function from the module | |
| from pdd.find_section import find_section | |
| # Sample input: a string containing multiple lines, including code blocks | |
| llm_output = """ | |
| Here is some text. | |
| ```python | |
| def hello_world(): | |
| print("Hello, world!") | |
| ``` | |
| Some more text. | |
| ```javascript | |
| function greet() { | |
| console.log("Greetings!"); | |
| } | |
| ``` | |
| """ | |
| # Split the output into lines | |
| lines = llm_output.splitlines() | |
| # Call the find_section function to extract code sections | |
| sections = find_section(lines) | |
| # Print the results | |
| for code_language, start_line, end_line in sections: | |
| print(f"Language: {code_language}, Start: {start_line}, End: {end_line}") | |
| # load ./context/unrunnable_raw_llm_output.py | |
| with open('./context/unrunnable_raw_llm_output.py', 'r') as file: | |
| llm_output = file.read() | |
| lines = llm_output.splitlines() | |
| sections = find_section(lines) | |
| for code_language, start_line, end_line in sections: | |
| print(f"Language: {code_language}, Start: {start_line}, End: {end_line}") | |
| # ``` | |
| # ### Documentation | |
| # #### Input Parameters | |
| # - `lines` (List[str]): A list of strings, where each string represents a line of text. This is typically obtained by splitting a larger string into lines using `splitlines()`. | |
| # - `start_index` (int, optional): The index in the `lines` list from which to start searching for code sections. Defaults to `0`. | |
| # - `sub_section` (bool, optional): A flag indicating whether to treat the search as a sub-section. Defaults to `False`. | |
| # #### Output | |
| # - Returns a list of tuples, where each tuple contains: | |
| # - `code_language` (str): The programming language specified in the code block (e.g., "python", "javascript"). | |
| # - `start_line` (int): The index of the line where the code block starts. | |
| # - `end_line` (int): The index of the line where the code block ends. | |
| # ### Example Output | |
| # For the provided `llm_output`, the output would be: | |
| # ``` | |
| # Language: python, Start: 3, End: 6 | |
| # Language: javascript, Start: 10, End: 14 | |
| # ``` | |
| # This indicates that there are two code sections found: one in Python and one in JavaScript, along with their respective start and end line indices. |
Xet Storage Details
- Size:
- 2.34 kB
- Xet hash:
- 0fabd5f6e36cae858429d7f4f1db8b6a19f35de8d68c7ab6f15f9f344afa9c3d
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.