OCR / kimi_api_test.py
Suevar's picture
Upload 12 files
2bcf29e verified
from openai import OpenAI
from pathlib import Path
client = OpenAI(
api_key='sk-h2mR3KYVzNPS3XR2LXlbZANLDtPAokf0Hb8OLsbnHkyKNjh2',
base_url = 'https://api.moonshot.cn/v1',
)
# completion = client.chat.completions.create(
# model = "moonshot-v1-8k",
# messages=[
# {"role": "system", "content": "你是 Kimi,由 Moonshot AI 提供的人工智能助手,你更擅长中文和英文的对话。你会为用户提供安全,有帮助,准确的回答。同时,你会拒绝一切涉及恐怖主义,种族歧视,黄色暴力等问题的回答。Moonshot AI 为专有名词,不可翻译成其他语言。"},
# {"role": "user", "content": "你好,我叫李雷,1+1等于多少?"}
# ],
# temperature = 0.3,
# )
#
# print(completion.choices[0].message)
file_object = client.files.create(file=Path("./image/3.png"), purpose="file-extract")
file_content = client.files.content(file_id=file_object.id).text
messages=[
{
"role": "system",
"content": "你将收到一张聊天截图,该聊天截图反映了产品A使用过程中存在的一些问题。首先概述聊天内容,然后详细介绍产品中存在的问题,以方便后续工单的创建",
},
{
"role": "system",
"content": file_content,
},
{"role": "user",
"content": "整理这些文件的核心内容,给出其中产品问题的详细描述"},
]
completion = client.chat.completions.create(
model="moonshot-v1-32k",
messages=messages,
temperature=0.3,
)
print(completion.choices[0].message)