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

Method __call__

utils/src/llms.py:99–167  ·  view source on GitHub ↗

Call the language model with a prompt and optional images. Args: content (str): The prompt content. images (list[str]): A list of image file paths. system_message (str): The system message. history (list): The conversation history.

(
        self,
        content: str,
        images: list[str] = None,
        system_message: str = None,
        history: list = None,
        delay_batch: bool = False,
        return_json: bool = False,
        return_message: bool = False,
    )

Source from the content-addressed store, hash-verified

97
98 @tenacity
99 def __call__(
100 self,
101 content: str,
102 images: list[str] = None,
103 system_message: str = None,
104 history: list = None,
105 delay_batch: bool = False,
106 return_json: bool = False,
107 return_message: bool = False,
108 ) -> str | dict | list:
109 """
110 Call the language model with a prompt and optional images.
111
112 Args:
113 content (str): The prompt content.
114 images (list[str]): A list of image file paths.
115 system_message (str): The system message.
116 history (list): The conversation history.
117 delay_batch (bool): Whether to delay return of response.
118 return_json (bool): Whether to return the response as JSON.
119 return_message (bool): Whether to return the message.
120
121 Returns:
122 str | dict | list: The response from the model.
123 """
124 if content.startswith("You are"):
125 system_message, content = content.split("\n", 1)
126 if history is None:
127 history = []
128 if isinstance(images, str):
129 images = [images]
130 system, message = self.format_message(content, images, system_message)
131 if self._use_batch:
132 result = run_async(self._run_batch(system + history + message, delay_batch))
133 if delay_batch:
134 return
135 try:
136 response = result.to_dict()["result"][0]["choices"][0]["message"][
137 "content"
138 ]
139 except Exception as e:
140 print("Failed to get response from batch")
141 raise e
142 elif self._use_openai:
143 completion = self.client.chat.completions.create(
144 model=self.model, messages=system + history + message
145 )
146 response = completion.choices[0].message.content
147 else:
148 response = requests.post(
149 self.api_base,
150 json={
151 "system": system_message,
152 "prompt": content,
153 "image": [
154 i["image_url"]["url"]
155 for i in message[-1]["content"]
156 if i["type"] == "image_url"

Callers

nothing calls this directly

Calls 6

format_messageMethod · 0.95
_run_batchMethod · 0.95
get_json_from_responseFunction · 0.90
run_asyncFunction · 0.70
to_dictMethod · 0.45
createMethod · 0.45

Tested by

no test coverage detected