30 lines
851 B
Python
30 lines
851 B
Python
from pathlib import Path
|
|
from openai import OpenAI
|
|
|
|
from django.conf import settings
|
|
|
|
class KIMI:
|
|
def __init__(self, history: list):
|
|
self.client = OpenAI(
|
|
api_key = settings.KIMI_API_KEY,
|
|
base_url= settings.KIMI_BASE_URL
|
|
)
|
|
self.history = history
|
|
|
|
|
|
def get_response(self):
|
|
try:
|
|
# print(self.history)
|
|
# 调用 chat-completion, 获取 Kimi 的回答
|
|
completion = self.client.chat.completions.create(
|
|
# model="moonshot-v1-8k",
|
|
model="ep-20250429171558-vgq77",
|
|
messages= self.history,
|
|
temperature=0.3,
|
|
)
|
|
except Exception as e:
|
|
print(e)
|
|
return "李白正在吟诗作对~请稍后再试"
|
|
|
|
return completion.choices[0].message.content
|