-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkimi_k3.py
More file actions
53 lines (46 loc) · 1.77 KB
/
Copy pathkimi_k3.py
File metadata and controls
53 lines (46 loc) · 1.77 KB
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
52
53
"""Kimi K3 via NovAI (OpenAI-compatible, drop-in).
Moonshot's Kimi K3: 2.8T-param MoE, native vision, 1M-token context.
Only change vs. the OpenAI SDK: base_url + model="kimi-k3".
pip install openai
export NOVAI_API_KEY=sk-...
python kimi_k3.py
"""
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["NOVAI_API_KEY"],
base_url="https://aiapi-pro.com/v1",
)
# 1) Plain chat -----------------------------------------------------------
resp = client.chat.completions.create(
model="kimi-k3",
messages=[{"role": "user", "content": "Explain mixture-of-experts routing in 3 bullet points."}],
)
print(resp.choices[0].message.content)
# 2) Streaming ------------------------------------------------------------
# for chunk in client.chat.completions.create(
# model="kimi-k3",
# messages=[{"role": "user", "content": "Write a haiku about long context."}],
# stream=True):
# print(chunk.choices[0].delta.content or "", end="", flush=True)
# 3) Vision (K3 is multimodal) -------------------------------------------
# resp = client.chat.completions.create(
# model="kimi-k3",
# messages=[{
# "role": "user",
# "content": [
# {"type": "text", "text": "What's in this image?"},
# {"type": "image_url",
# "image_url": {"url": "https://example.com/chart.png"}}, # replace with your image
# ],
# }],
# )
# print(resp.choices[0].message.content)
# 4) Long context (up to 1M tokens) --------------------------------------
# with open("big_document.txt") as f:
# doc = f.read()
# resp = client.chat.completions.create(
# model="kimi-k3",
# messages=[{"role": "user", "content": f"Summarize the key risks:\n\n{doc}"}],
# )
# print(resp.choices[0].message.content)