API Documentation¶
GeoDataFrame AI¶
GeoDataFrameAI
¶
Bases: GeoDataFrame
A class to represent a GeoDataFrame with AI capabilities. It is a proxy for the GeoPandas GeoDataFrame class, allowing for additional functionality related to AI and machine learning tasks.
Source code in geopandasai/geodataframe_ai.py
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 |
|
__init__(*args, description=None, **kwargs)
¶
Initialize the GeoDataFrameAI class.
Source code in geopandasai/geodataframe_ai.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
|
chat(prompt, *other_dfs, return_type=None, provided_libraries=None)
¶
This method is used to start a conversation with the AI. It takes a prompt and any number of other GeoDataFrames as input. The prompt is a string that describes the task or question to be answered. The other_dfs are additional GeoDataFrames that can be used to provide context for the AI.
:param prompt: The prompt to start the conversation. :param other_dfs: Additional GeoDataFrames to provide context. :param return_type: The type of the return value. If None, it will be inferred. :param provided_libraries: A list of libraries that are provided by the user. :return: The result of the conversation, which can be any type or a MagicReturn object.
Source code in geopandasai/geodataframe_ai.py
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 |
|
inject(function_name, ai_module='ai', ai_module_path='ai')
¶
Inject the state of the GeoDataFrameAI into the current context.
Source code in geopandasai/geodataframe_ai.py
130 131 132 133 134 135 136 |
|
inspect()
¶
Print the history of the last output.
Source code in geopandasai/geodataframe_ai.py
114 115 116 117 118 119 120 |
|
reset()
¶
Reset the state of the GeoDataFrameAI.
Source code in geopandasai/geodataframe_ai.py
122 123 124 125 126 127 128 |
|
set_description(description)
¶
Describe the GeoDataFrameAI. This is a user-provided description that can be used to provide context for the AI.
Source code in geopandasai/geodataframe_ai.py
37 38 39 40 41 42 43 44 45 46 |
|
Configuration¶
GeoPandasAIConfig
dataclass
¶
Configuration class for GeoPandasAI.
This class holds the configuration settings for GeoPandasAI, including the lite LLM configuration, libraries to be used, cache backend, data descriptor, code injector, code executor, and return types. It is designed to be immutable after creation, ensuring that the configuration remains consistent throughout the application.
Source code in geopandasai/config.py
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 |
|
set_active_lite_llm_config(lite_llm_config)
¶
Set the active lite LLM configuration.
Source code in geopandasai/config.py
89 90 91 92 93 94 95 96 |
|
update_geopandasai_config(lite_llm_config=None, libraries=None, cache_backend=None, descriptor=None, return_types=None, injector=None, executor=None)
¶
Update the GeoPandasAI configuration.
This function allows you to update the configuration of GeoPandasAI, including the lite LLM configuration, libraries, cache backend, descriptor, return types, and code injector. If a parameter is not provided, the current value will be retained. :param lite_llm_config: The configuration for the lite LLM, if any. :param libraries: A list of libraries to be used in the GeoPandasAI environment. :param cache_backend: The cache backend to be used. :param descriptor: The data descriptor to be used. :param return_types: A set of types that can be returned by the AI. :param injector: The code injector to be used. :param executor: The code executor to be used.
Source code in geopandasai/config.py
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 |
|
GeoPandas Wrapper¶
read_arrow(source, *args, **kwargs)
¶
Read Arrow (e.g. pyarrow.Table) data and return a GeoDataFrameAI.
Source code in geopandasai/wrapper.py
62 63 64 65 66 67 68 69 70 |
|
read_feather(path, *args, **kwargs)
¶
Read a Feather file and return a GeoDataFrameAI.
Source code in geopandasai/wrapper.py
28 29 30 31 32 33 34 35 36 |
|
read_file(filename, *args, **kwargs)
¶
Read a vector file (shapefile, GeoJSON, etc.) and return a GeoDataFrameAI.
Source code in geopandasai/wrapper.py
6 7 8 9 10 11 12 13 14 |
|
read_fileobj(fileobj, *args, **kwargs)
¶
Read a file-like object and return a GeoDataFrameAI.
Source code in geopandasai/wrapper.py
51 52 53 54 55 56 57 58 59 |
|
read_parquet(path, *args, **kwargs)
¶
Read a Parquet file and return a GeoDataFrameAI.
Source code in geopandasai/wrapper.py
17 18 19 20 21 22 23 24 25 |
|
read_postgis(sql, con, *args, **kwargs)
¶
Read data from a PostGIS-enabled database and return a GeoDataFrameAI.
Source code in geopandasai/wrapper.py
39 40 41 42 43 44 45 46 47 48 |
|
to_feather(gdf, path, *args, **kwargs)
¶
Write a GeoDataFrameAI to a Feather file.
Source code in geopandasai/wrapper.py
86 87 88 89 90 91 92 93 94 95 |
|
to_file(gdf, filename, *args, **kwargs)
¶
Write a GeoDataFrameAI to a file (shapefile, GeoPackage, GeoJSON, etc.).
Source code in geopandasai/wrapper.py
98 99 100 101 102 103 104 105 106 107 |
|
to_parquet(gdf, path, *args, **kwargs)
¶
Write a GeoDataFrameAI to a Parquet file.
Source code in geopandasai/wrapper.py
74 75 76 77 78 79 80 81 82 83 |
|
to_postgis(gdf, name, con, *args, **kwargs)
¶
Write a GeoDataFrameAI to a PostGIS-enabled database.
Source code in geopandasai/wrapper.py
110 111 112 113 114 115 116 117 118 119 120 |
|
Services¶
Cache Backend¶
ACacheBackend
¶
Bases: ABC
Base class for all cache backends. This class defines the interface for caching mechanisms used in GeoPandasAI. It provides methods to get, set, clear, and reset cache entries. Subclasses should implement these methods to provide specific caching functionality.
Source code in geopandasai/external/cache/backend/base.py
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 |
|
clear_cache(key)
¶
Clear the cached result for the given key.
Source code in geopandasai/external/cache/backend/base.py
25 26 27 28 29 |
|
get_cache(key)
¶
Get the cached result for the given key.
Source code in geopandasai/external/cache/backend/base.py
13 14 15 16 17 |
|
reset_cache()
¶
Reset the cache.
Source code in geopandasai/external/cache/backend/base.py
31 32 33 34 35 |
|
set_cache(key, value)
¶
Set the cached result for the given key.
Source code in geopandasai/external/cache/backend/base.py
19 20 21 22 23 |
|
FileSystemCacheBackend
¶
Bases: ACacheBackend
FileSystemCacheBackend is a cache backend that stores cached results in the file system.
Source code in geopandasai/external/cache/backend/file_system.py
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 |
|
InMemoryCacheBackend
¶
Bases: ACacheBackend
InMemoryCacheBackend is a cache backend that stores cached results in memory.
Source code in geopandasai/external/cache/backend/in_memory.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
Code Execution Backend¶
ACodeExecutor
¶
Bases: ABC
Abstract base class for executing Python code.
Source code in geopandasai/services/code/executor/base.py
7 8 9 10 11 12 13 14 |
|
TrustedCodeExecutor
¶
Bases: ACodeExecutor
A class for executing trusted Python code in a temporary file.
This class inherits from ACodeExecutor
and provides functionality
to safely execute Python code passed as a string. It ensures the
result matches the expected return type and wraps GeoDataFrame results
with GeoDataFrameAI
for additional functionality.
Source code in geopandasai/services/code/executor/trusted.py
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 |
|
execute(code, return_type, *dfs)
¶
Executes the provided Python code in a temporary file and returns the result. :param code: The Python code to execute as a string. :param return_type: The expected return type of the code execution. :param dfs: An iterable of GeoDataFrame or DataFrame objects to be passed as arguments to the executed code. :return: The result of the executed code, wrapped in GeoDataFrameAI if it is a GeoDataFrame.
Source code in geopandasai/services/code/executor/trusted.py
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 |
|
UntrustedCodeExecutor
¶
Bases: TrustedCodeExecutor
A class for executing untrusted Python code with user confirmation.
This class extends TrustedCodeExecutor
and adds an interactive confirmation
step before executing the provided code. It highlights the code for better
readability and ensures the user explicitly approves execution, making it
suitable for scenarios where code safety is a concern.
Source code in geopandasai/services/code/executor/untrusted.py
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 |
|