| 49 | |
| 50 | |
| 51 | class FakeModel(Model): |
| 52 | def __init__( |
| 53 | self, |
| 54 | tracing_enabled: bool = False, |
| 55 | initial_output: list[TResponseOutputItem] | Exception | None = None, |
| 56 | ): |
| 57 | if initial_output is None: |
| 58 | initial_output = [] |
| 59 | self.turn_outputs: list[list[TResponseOutputItem] | Exception] = ( |
| 60 | [initial_output] if initial_output else [] |
| 61 | ) |
| 62 | self.tracing_enabled = tracing_enabled |
| 63 | self.last_turn_args: dict[str, Any] = {} |
| 64 | self.first_turn_args: dict[str, Any] | None = None |
| 65 | self.hardcoded_usage: Usage | None = None |
| 66 | |
| 67 | def set_hardcoded_usage(self, usage: Usage): |
| 68 | self.hardcoded_usage = usage |
| 69 | |
| 70 | def set_next_output(self, output: list[TResponseOutputItem] | Exception): |
| 71 | self.turn_outputs.append(output) |
| 72 | |
| 73 | def add_multiple_turn_outputs(self, outputs: list[list[TResponseOutputItem] | Exception]): |
| 74 | self.turn_outputs.extend(outputs) |
| 75 | |
| 76 | def get_next_output(self) -> list[TResponseOutputItem] | Exception: |
| 77 | if not self.turn_outputs: |
| 78 | return [] |
| 79 | return self.turn_outputs.pop(0) |
| 80 | |
| 81 | async def get_response( |
| 82 | self, |
| 83 | system_instructions: str | None, |
| 84 | input: str | list[TResponseInputItem], |
| 85 | model_settings: ModelSettings, |
| 86 | tools: list[Tool], |
| 87 | output_schema: AgentOutputSchemaBase | None, |
| 88 | handoffs: list[Handoff], |
| 89 | tracing: ModelTracing, |
| 90 | *, |
| 91 | previous_response_id: str | None, |
| 92 | conversation_id: str | None, |
| 93 | prompt: Any | None, |
| 94 | ) -> ModelResponse: |
| 95 | turn_args = { |
| 96 | "system_instructions": system_instructions, |
| 97 | "input": input, |
| 98 | "model_settings": model_settings, |
| 99 | "tools": tools, |
| 100 | "output_schema": output_schema, |
| 101 | "previous_response_id": previous_response_id, |
| 102 | "conversation_id": conversation_id, |
| 103 | } |
| 104 | |
| 105 | if self.first_turn_args is None: |
| 106 | self.first_turn_args = turn_args.copy() |
| 107 | |
| 108 | self.last_turn_args = turn_args |
no outgoing calls