Call the LLM with a system prompt and user message. Args: system_prompt: System message user_contents: List of user content items temperature: Sampling temperature max_tokens: Maximum tokens in response Returns: R
(
self,
system_prompt: str,
user_contents: List[Any],
temperature: float = 0.7,
max_tokens: Optional[int] = None,
)
| 115 | return None |
| 116 | |
| 117 | def call_with_system( |
| 118 | self, |
| 119 | system_prompt: str, |
| 120 | user_contents: List[Any], |
| 121 | temperature: float = 0.7, |
| 122 | max_tokens: Optional[int] = None, |
| 123 | ) -> Optional[str]: |
| 124 | """ |
| 125 | Call the LLM with a system prompt and user message. |
| 126 | |
| 127 | Args: |
| 128 | system_prompt: System message |
| 129 | user_contents: List of user content items |
| 130 | temperature: Sampling temperature |
| 131 | max_tokens: Maximum tokens in response |
| 132 | |
| 133 | Returns: |
| 134 | Response text, or None on failure |
| 135 | """ |
| 136 | try: |
| 137 | from openai import OpenAI |
| 138 | |
| 139 | if not self.api_key: |
| 140 | print("[LLMClient] ERROR: API key not provided!") |
| 141 | return None |
| 142 | |
| 143 | client = OpenAI(base_url=self.base_url, api_key=self.api_key) |
| 144 | |
| 145 | # Build user message content |
| 146 | user_content: List[Dict[str, Any]] = [] |
| 147 | for part in user_contents: |
| 148 | if isinstance(part, str): |
| 149 | user_content.append({"type": "text", "text": part}) |
| 150 | elif isinstance(part, Image.Image): |
| 151 | buf = io.BytesIO() |
| 152 | part.save(buf, format="PNG") |
| 153 | image_b64 = base64.b64encode(buf.getvalue()).decode("utf-8") |
| 154 | user_content.append({ |
| 155 | "type": "image_url", |
| 156 | "image_url": {"url": f"data:image/png;base64,{image_b64}"} |
| 157 | }) |
| 158 | |
| 159 | messages = [ |
| 160 | {"role": "system", "content": system_prompt}, |
| 161 | {"role": "user", "content": user_content}, |
| 162 | ] |
| 163 | |
| 164 | kwargs = { |
| 165 | "model": self.model, |
| 166 | "messages": messages, |
| 167 | "temperature": temperature, |
| 168 | } |
| 169 | if max_tokens: |
| 170 | kwargs["max_tokens"] = max_tokens |
| 171 | |
| 172 | completion = client.chat.completions.create(**kwargs) |
| 173 | |
| 174 | if completion and completion.choices: |
nothing calls this directly
no outgoing calls
no test coverage detected