add support for TogetherAI (#1890)

### What problem does this PR solve?

#1853 add support for TogetherAI

### Type of change

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

---------

Co-authored-by: Zhedong Cen <cenzhedong2@126.com>
Co-authored-by: Kevin Hu <kevinhu.sh@gmail.com>
This commit is contained in:
黄腾
2024-08-12 10:15:21 +08:00
committed by GitHub
parent 9a6dc89156
commit 94cb66ba80
10 changed files with 62 additions and 5 deletions

View File

@ -39,6 +39,7 @@ EmbeddingModel = {
"LM-Studio": LmStudioEmbed,
"OpenAI-API-Compatible": OpenAI_APIEmbed,
"cohere": CoHereEmbed,
"TogetherAI": TogetherAIEmbed,
"PerfXCloud": PerfXCloudEmbed,
}
@ -57,7 +58,8 @@ CvModel = {
"NVIDIA": NvidiaCV,
"LM-Studio": LmStudioCV,
"StepFun":StepFunCV,
"OpenAI-API-Compatible": OpenAI_APICV
"OpenAI-API-Compatible": OpenAI_APICV,
"TogetherAI": TogetherAICV
}
@ -86,6 +88,7 @@ ChatModel = {
"OpenAI-API-Compatible": OpenAI_APIChat,
"cohere": CoHereChat,
"LeptonAI": LeptonAIChat,
"TogetherAI": TogetherAIChat,
"PerfXCloud": PerfXCloudChat
}
@ -98,7 +101,8 @@ RerankModel = {
"NVIDIA": NvidiaRerank,
"LM-Studio": LmStudioRerank,
"OpenAI-API-Compatible": OpenAI_APIRerank,
"cohere": CoHereRerank
"cohere": CoHereRerank,
"TogetherAI": TogetherAIRerank
}

View File

@ -990,6 +990,13 @@ class LeptonAIChat(Base):
super().__init__(key, model_name, base_url)
class TogetherAIChat(Base):
def __init__(self, key, model_name, base_url="https://api.together.xyz/v1"):
if not base_url:
base_url = "https://api.together.xyz/v1"
super().__init__(key, model_name, base_url)
class PerfXCloudChat(Base):
def __init__(self, key, model_name, base_url="https://cloud.perfxlab.cn/v1"):
if not base_url:

View File

@ -649,3 +649,10 @@ class OpenAI_APICV(GptV4):
self.client = OpenAI(api_key=key, base_url=base_url)
self.model_name = model_name.split("___")[0]
self.lang = lang
class TogetherAICV(GptV4):
def __init__(self, key, model_name, base_url="https://api.together.xyz/v1"):
if not base_url:
base_url = "https://api.together.xyz/v1"
super().__init__(key, model_name, base_url)

View File

@ -555,8 +555,16 @@ class CoHereEmbed(Base):
)
class TogetherAIEmbed(OllamaEmbed):
def __init__(self, key, model_name, base_url="https://api.together.xyz/v1"):
if not base_url:
base_url = "https://api.together.xyz/v1"
super().__init__(key, model_name, base_url)
class PerfXCloudEmbed(OpenAIEmbed):
def __init__(self, key, model_name, base_url="https://cloud.perfxlab.cn/v1"):
if not base_url:
base_url = "https://cloud.perfxlab.cn/v1"
super().__init__(key, model_name, base_url)

View File

@ -245,3 +245,11 @@ class CoHereRerank(Base):
rank = np.array([d.relevance_score for d in res.results])
indexs = [d.index for d in res.results]
return rank[indexs], token_count
class TogetherAIRerank(Base):
def __init__(self, key, model_name, base_url):
pass
def similarity(self, query: str, texts: list):
raise NotImplementedError("The api has not been implement")