| import os | import os | ||||
| from collections.abc import Iterable | from collections.abc import Iterable | ||||
| from time import sleep | |||||
| from typing import Any, Literal, Union | from typing import Any, Literal, Union | ||||
| import anthropic | import anthropic | ||||
| index = 0 | index = 0 | ||||
| for i in range(0, len(full_response_text)): | for i in range(0, len(full_response_text)): | ||||
| sleep(0.1) | |||||
| yield ContentBlockDeltaEvent( | yield ContentBlockDeltaEvent( | ||||
| type='content_block_delta', | type='content_block_delta', | ||||
| delta=TextDelta(text=full_response_text[i], type='text_delta'), | delta=TextDelta(text=full_response_text[i], type='text_delta'), |
| import re | import re | ||||
| from collections.abc import Generator | from collections.abc import Generator | ||||
| from json import dumps, loads | from json import dumps, loads | ||||
| from time import sleep, time | |||||
| from time import time | |||||
| # import monkeypatch | # import monkeypatch | ||||
| from typing import Any, Literal, Optional, Union | from typing import Any, Literal, Optional, Union | ||||
| if not function_call: | if not function_call: | ||||
| tool_calls = MockChatClass.generate_tool_calls(tools=tools) | tool_calls = MockChatClass.generate_tool_calls(tools=tools) | ||||
| sleep(1) | |||||
| return _ChatCompletion( | return _ChatCompletion( | ||||
| id='cmpl-3QJQa5jXJ5Z5X', | id='cmpl-3QJQa5jXJ5Z5X', | ||||
| choices=[ | choices=[ | ||||
| full_text = "Hello, world!\n\n```python\nprint('Hello, world!')\n```" | full_text = "Hello, world!\n\n```python\nprint('Hello, world!')\n```" | ||||
| for i in range(0, len(full_text) + 1): | for i in range(0, len(full_text) + 1): | ||||
| sleep(0.1) | |||||
| if i == len(full_text): | if i == len(full_text): | ||||
| yield ChatCompletionChunk( | yield ChatCompletionChunk( | ||||
| id='cmpl-3QJQa5jXJ5Z5X', | id='cmpl-3QJQa5jXJ5Z5X', |
| import re | import re | ||||
| from collections.abc import Generator | from collections.abc import Generator | ||||
| from time import sleep, time | |||||
| from time import time | |||||
| # import monkeypatch | # import monkeypatch | ||||
| from typing import Any, Literal, Optional, Union | from typing import Any, Literal, Optional, Union | ||||
| def mocked_openai_completion_create_sync( | def mocked_openai_completion_create_sync( | ||||
| model: str | model: str | ||||
| ) -> CompletionMessage: | ) -> CompletionMessage: | ||||
| sleep(1) | |||||
| return CompletionMessage( | return CompletionMessage( | ||||
| id="cmpl-3QJQa5jXJ5Z5X", | id="cmpl-3QJQa5jXJ5Z5X", | ||||
| object="text_completion", | object="text_completion", | ||||
| ) -> Generator[CompletionMessage, None, None]: | ) -> Generator[CompletionMessage, None, None]: | ||||
| full_text = "Hello, world!\n\n```python\nprint('Hello, world!')\n```" | full_text = "Hello, world!\n\n```python\nprint('Hello, world!')\n```" | ||||
| for i in range(0, len(full_text) + 1): | for i in range(0, len(full_text) + 1): | ||||
| sleep(0.1) | |||||
| if i == len(full_text): | if i == len(full_text): | ||||
| yield CompletionMessage( | yield CompletionMessage( | ||||
| id="cmpl-3QJQa5jXJ5Z5X", | id="cmpl-3QJQa5jXJ5Z5X", |