# from openai import OpenAI
# import os

# # for backward compatibility, you can still use `https://api.deepseek.com/v1` as `base_url`.
# client = OpenAI(api_key=os.getenv("DEEPSEEK_API_KEY"), base_url="https://api.deepseek.com")
# print(client.models.list())


# response = client.chat.completions.create(
#     model="deepseek-chat", # DeepSeek-V3-0324
#     messages=[{"role": "user", "content": "What version are you?"}],
#     temperature=0
# )
# print(response.choices[0].message.content)  # Likely outputs "V3"

# from openai import OpenAI
# import os

# client = OpenAI(
#   base_url="https://openrouter.ai/api/v1",
#   api_key=os.getenv("OPENROUTER_API_KEY"),
# )

# completion = client.chat.completions.create(
# #   extra_headers={
# #     "HTTP-Referer": "<YOUR_SITE_URL>", # Optional. Site URL for rankings on openrouter.ai.
# #     "X-Title": "<YOUR_SITE_NAME>", # Optional. Site title for rankings on openrouter.ai.
# #   },
#   extra_body={},
#   model="deepseek/deepseek-chat-v3-0324",
#   messages=[
#     {
#       "role": "user",
#       "content": "What version are you?"
#     }
#   ]
# )
# print(completion.choices[0].message.content)



from openai import OpenAI
import os

# Initialize client with Fireworks endpoint
client = OpenAI(
    base_url="https://api.fireworks.ai/inference/v1",
    api_key=os.getenv("FIREWORKS_API_KEY")
)

# Create a chat completion request
stream = client.chat.completions.create(
    model="accounts/fireworks/models/deepseek-v3",  # or simply "fireworks/deepseek-v3"
    messages=[
        {"role": "user", "content": "say: \"This is a Test\""}
    ],
    temperature=0,
    top_p=1,
    max_tokens=512,
    stream=True,
)

# print(stream.choices[0].message.content)
# print(stream)

full_text = []
usage_info = None

for chunk in stream:
    print(chunk)
    print(type(chunk))
    continue
    # 每个 chunk 是 ChatCompletionChunk
    if len(chunk.choices) > 0:
        delta = chunk.choices[0].delta.content or ""
        print(delta, end="", flush=True)   # 实时打印
        full_text.append(delta)

    # Fireworks 特有：最后一个 chunk 带有 usage/perf 信息
    if chunk.usage is not None:
        usage_info = chunk.usage

# print("\n\n=== Final Result ===")
# print("".join(full_text))
# if usage_info:
#     print("Prompt tokens:", usage_info.prompt_tokens)
#     print("Completion tokens:", usage_info.completion_tokens)
#     print("Total tokens:", usage_info.total_tokens)
