| 9 | payload: str | list[typechat.PromptSection] |
| 10 | |
| 11 | class FixedModel(typechat.TypeChatLanguageModel): |
| 12 | responses: Iterator[str] |
| 13 | conversation: list[ConvoRecord] |
| 14 | |
| 15 | "A model which responds with one of a series of responses." |
| 16 | def __init__(self, responses: list[str]) -> None: |
| 17 | super().__init__() |
| 18 | self.responses = iter(responses) |
| 19 | self.conversation = [] |
| 20 | |
| 21 | @override |
| 22 | async def complete(self, prompt: str | list[typechat.PromptSection]) -> typechat.Result[str]: |
| 23 | # Capture a snapshot because the translator |
| 24 | # can choose to pass in the same underlying list. |
| 25 | if isinstance(prompt, list): |
| 26 | prompt = prompt.copy() |
| 27 | |
| 28 | self.conversation.append({ "kind": "CLIENT REQUEST", "payload": prompt }) |
| 29 | response = next(self.responses) |
| 30 | self.conversation.append({ "kind": "MODEL RESPONSE", "payload": response }) |
| 31 | return typechat.Success(response) |
| 32 | |
| 33 | @dataclass |
| 34 | class ExampleABC: |
no outgoing calls