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

Method run

camel/models/model_manager.py:180–212  ·  view source on GitHub ↗

r"""Process a list of messages by selecting a model based on the scheduling strategy. Sends the entire list of messages to the selected model, and returns a single response. Args: messages (List[OpenAIMessage]): Message list with the chat

(
        self, messages: List[OpenAIMessage]
    )

Source from the content-addressed store, hash-verified

178 return choice(self.models)
179
180 def run(
181 self, messages: List[OpenAIMessage]
182 ) -> Union[ChatCompletion, Stream[ChatCompletionChunk]]:
183 r"""Process a list of messages by selecting a model based on
184 the scheduling strategy.
185 Sends the entire list of messages to the selected model,
186 and returns a single response.
187
188 Args:
189 messages (List[OpenAIMessage]): Message list with the chat
190 history in OpenAI API format.
191
192 Returns:
193 Union[ChatCompletion, Stream[ChatCompletionChunk]]:
194 `ChatCompletion` in the non-stream mode, or
195 `Stream[ChatCompletionChunk]` in the stream mode.
196 """
197 self.current_model = self.scheduling_strategy()
198
199 # Pass all messages to the selected model and get the response
200 try:
201 response = self.current_model.run(messages)
202 except Exception as exc:
203 logger.error(f"Error processing with model: {self.current_model}")
204 if self.scheduling_strategy == self.always_first:
205 self.scheduling_strategy = self.round_robin
206 logger.warning(
207 "The scheduling strategy has been changed to 'round_robin'"
208 )
209 # Skip already used one
210 self.current_model = self.scheduling_strategy()
211 raise exc
212 return response

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected