MCPcopy Create free account
hub / github.com/Paper2Poster/Paper2Poster / format_message

Method format_message

utils/src/llms.py:182–213  ·  view source on GitHub ↗

Message formatter for OpenAI server call.

(
        self,
        content: str,
        images: list[str] = None,
        system_message: str = None,
    )

Source from the content-addressed store, hash-verified

180 return await self.oai_batch.run()
181
182 def format_message(
183 self,
184 content: str,
185 images: list[str] = None,
186 system_message: str = None,
187 ):
188 """
189 Message formatter for OpenAI server call.
190 """
191 if system_message is None:
192 system_message = "You are a helpful assistant"
193 system = [
194 {
195 "role": "system",
196 "content": [{"type": "text", "text": system_message}],
197 }
198 ]
199 message = [{"role": "user", "content": [{"type": "text", "text": content}]}]
200 if images is not None:
201 if not isinstance(images, list):
202 images = [images]
203 for image in images:
204 with open(image, "rb") as f:
205 message[0]["content"].append(
206 {
207 "type": "image_url",
208 "image_url": {
209 "url": f"data:image/jpeg;base64,{base64.b64encode(f.read()).decode('utf-8')}"
210 },
211 }
212 )
213 return system, message
214
215 def get_batch_result(self):
216 """

Callers 1

__call__Method · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected