add supprot for lepton (#1866)

### What problem does this PR solve?

add supprot for lepton
#1853

### Type of change

- [x] New Feature (non-breaking change which adds functionality)

Co-authored-by: Zhedong Cen <cenzhedong2@126.com>
This commit is contained in:
黄腾
2024-08-08 12:09:50 +08:00
committed by GitHub
parent 19ded65c66
commit aed1bbbcaa
5 changed files with 154 additions and 3 deletions

View File

@ -83,7 +83,8 @@ ChatModel = {
"NVIDIA": NvidiaChat,
"LM-Studio": LmStudioChat,
"OpenAI-API-Compatible": OpenAI_APIChat,
"cohere": CoHereChat
"cohere": CoHereChat,
"LeptonAI": LeptonAIChat
}

View File

@ -71,7 +71,7 @@ class Base(ABC):
total_tokens
+ num_tokens_from_string(resp.choices[0].delta.content)
)
if not hasattr(resp, "usage")
if not hasattr(resp, "usage") or not resp.usage
else resp.usage["total_tokens"]
)
if resp.choices[0].finish_reason == "length":
@ -981,3 +981,10 @@ class CoHereChat(Base):
yield ans + "\n**ERROR**: " + str(e)
yield total_tokens
class LeptonAIChat(Base):
def __init__(self, key, model_name, base_url=None):
if not base_url:
base_url = os.path.join("https://"+model_name+".lepton.run","api","v1")
super().__init__(key, model_name, base_url)