Build and run agents you can see, understand and trust.
Python agentchatbotlarge-language-modelsllmllm-agentmcpmulti-agentmulti-modalreact-agentrealtime-agentvoice-agentvoice-assistant
feat(classifier): let per-call options override the Decisions defaults (#3391)
lihongyuan99430fbc7898e5
diff --git a/src/agentscope/classifier/_openai/_model.py b/src/agentscope/classifier/_openai/_model.pyindex f5610c7c5..2bf5efdd4 100644--- a/src/agentscope/classifier/_openai/_model.py+++ b/src/agentscope/classifier/_openai/_model.py@@ -194,19 +194,24 @@ class OpenAIClassifierModel(ClassifierModelBase):**kwargs (`Any`):Options forwarded to ``client.decisions.create``, such as``safety_identifier``, ``extra_headers``, and ``extra_body``.+ ``model`` and ``input`` may also be set here, in which case+ they override the instance defaults for this call only.Returns:`ClassifierResponse`:Answers and refusals keyed by question name, with usage."""start_time = perf_counter()+ # Per-call options override defaults.response = await self.client.decisions.create(- model=self.model,- input=_to_sdk_input(state),- questions=[- _to_sdk_question(name, q) for name, q in questions.items()- ],- **kwargs,+ **{+ "model": self.model,+ "input": _to_sdk_input(state),+ "questions": [+ _to_sdk_question(name, q) for name, q in questions.items()+ ],+ **kwargs,+ },)return ClassifierResponse(model=response.model,diff --git a/tests/classifier_openai_test.py b/tests/classifier_openai_test.pyindex 1f8891bd8..2fb9e6783 100644--- a/tests/classifier_openai_test.py+++ b/tests/classifier_openai_test.py@@ -283,3 +283,45 @@ class OpenAIClassifierModelTest(IsolatedAsyncioTestCase):self.client_cls.return_value = MagicMock(spec=[])with self.assertRaisesRegex(ImportError, "openai>=3.26.0"):classifier.OpenAIClassifierModel(self.credential)++ async def test_per_call_model_replaces_the_default(self) -> None:+ """``model=`` is forwarded once, with the caller's value."""+ model = classifier.OpenAIClassifierModel(self.credential)+ questions = {"urgent": BinaryQuestion(instructions="Urgent?")}+ await model("I was charged twice.", questions, model="x")++ self.assertDictEqual(+ self.client.decisions.create.await_args.kwargs,+ {+ "model": "x",+ "input": "I was charged twice.",+ "questions": [+ {+ "type": "predicate",+ "name": "urgent",+ "instructions": "Urgent?",+ },+ ],+ },+ )++ async def test_per_call_input_replaces_the_state(self) -> None:+ """``input=`` is forwarded once, with the caller's value."""+ model = classifier.OpenAIClassifierModel(self.credential)+ questions = {"urgent": BinaryQuestion(instructions="Urgent?")}+ await model("I was charged twice.", questions, input="raw")++ self.assertDictEqual(+ self.client.decisions.create.await_args.kwargs,+ {+ "model": "gpt-6-luna",+ "input": "raw",+ "questions": [+ {+ "type": "predicate",+ "name": "urgent",+ "instructions": "Urgent?",+ },+ ],+ },+ )