add Moonshot, debug my_llm (#126)

This commit is contained in:
KevinHuSh
2024-03-15 18:59:00 +08:00
committed by GitHub
parent de09b0e1a4
commit 2447f95629
6 changed files with 76 additions and 48 deletions

View File

@ -54,6 +54,21 @@ class MoonshotChat(GptTurbo):
self.client = OpenAI(api_key=key, base_url="https://api.moonshot.cn/v1",)
self.model_name = model_name
def chat(self, system, history, gen_conf):
if system: history.insert(0, {"role": "system", "content": system})
try:
response = self.client.chat.completions.create(
model=self.model_name,
messages=history,
**gen_conf)
ans = response.choices[0].message.content.strip()
if response.choices[0].finish_reason == "length":
ans += "...\nFor the content length reason, it stopped, continue?" if is_english(
[ans]) else "······\n由于长度的原因,回答被截断了,要继续吗?"
return ans, response.usage.completion_tokens
except openai.APIError as e:
return "**ERROR**: "+str(e), 0
from dashscope import Generation
class QWenChat(Base):