Api
API interaction for LLM services.
logger
module-attribute
logger = getLogger(__name__)
PydanticModelT
module-attribute
PydanticModelT = TypeVar('PydanticModelT', bound=BaseModel)
MessageDict
Bases: TypedDict
Typed dictionary for LLM message structure.
Source code in src/codemap/llm/api.py
32 33 34 35 36 |
|
role
instance-attribute
role: Literal['user', 'system']
content
instance-attribute
content: str
validate_schema
validate_schema(
model: type[PydanticModelT], input_data: str | object
) -> PydanticModelT
Validate the schema of the input data.
Source code in src/codemap/llm/api.py
39 40 41 42 43 |
|
call_llm_api
call_llm_api(
messages: list[MessageDict],
config_loader: ConfigLoader,
pydantic_model: type[PydanticModelT] | None = None,
) -> str | PydanticModelT
Call an LLM API using pydantic-ai.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
messages
|
list[MessageDict]
|
The list of messages to send to the LLM |
required |
config_loader
|
ConfigLoader
|
ConfigLoader instance for additional configuration |
required |
pydantic_model
|
type[PydanticModelT] | None
|
Optional Pydantic model class to structure the output. If provided, the function will return an instance of this model. Otherwise, it returns a string. |
None
|
Returns:
Type | Description |
---|---|
str | PydanticModelT
|
The generated response, either as a string or an instance of the pydantic_model. |
Raises:
Type | Description |
---|---|
LLMError
|
If pydantic-ai is not installed or the API call fails. |
Source code in src/codemap/llm/api.py
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 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
|