Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
51 lines (43 loc) · 1.52 KB

File metadata and controls

51 lines (43 loc) · 1.52 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from __future__ import annotations
import httpx
import pytest
from kimi_sdk import Kimi, Message, generate
def _chat_completion_response() -> dict[str, object]:
return {
"id": "chatcmpl-test123",
"object": "chat.completion",
"created": 1234567890,
"model": "kimi-k2-turbo-preview",
"choices": [
{
"index": 0,
"message": {"role": "assistant", "content": "Hello"},
"finish_reason": "stop",
}
],
"usage": {"prompt_tokens": 10, "completion_tokens": 5, "total_tokens": 15},
}
@pytest.mark.asyncio
async def test_generate_smoke() -> None:
def handler(request: httpx.Request) -> httpx.Response:
assert request.url.path == "/v1/chat/completions"
return httpx.Response(200, json=_chat_completion_response())
transport = httpx.MockTransport(handler)
async with httpx.AsyncClient(transport=transport) as http_client:
kimi = Kimi(
model="kimi-k2-turbo-preview",
api_key="test-key",
stream=False,
http_client=http_client,
)
result = await generate(
chat_provider=kimi,
system_prompt="You are helpful.",
tools=[],
history=[Message(role="user", content="Hi")],
)
assert result.message.role == "assistant"
assert result.message.extract_text() == "Hello"
assert result.usage is not None
assert result.usage.input_other == 10
assert result.usage.output == 5
Morty Proxy This is a proxified and sanitized view of the page, visit original site.