Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for TogetherAI #1890

Merged
merged 4 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/apps/llm_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def add_llm():
api_key = req.get("api_key","xxxxxxxxxxxxxxx")
else:
llm_name = req["llm_name"]
api_key = "xxxxxxxxxxxxxxx"
api_key = req.get("api_key","xxxxxxxxxxxxxxx")

llm = {
"tenant_id": current_user.id,
Expand Down
9 changes: 8 additions & 1 deletion conf/llm_factories.json
Original file line number Diff line number Diff line change
Expand Up @@ -2443,6 +2443,13 @@
}
]
},
{
"name": "TogetherAI",
"logo": "",
"tags": "LLM,TEXT EMBEDDING,IMAGE2TEXT",
"status": "1",
"llm": []
},
{
"name": "PerfXCloud",
"logo": "",
Expand Down Expand Up @@ -2594,6 +2601,6 @@
"model_type": "embedding"
}
]
}
}
]
}
8 changes: 6 additions & 2 deletions rag/llm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"LM-Studio": LmStudioEmbed,
"OpenAI-API-Compatible": OpenAI_APIEmbed,
"cohere": CoHereEmbed,
"TogetherAI": TogetherAIEmbed,
"PerfXCloud": PerfXCloudEmbed,
}

Expand All @@ -57,7 +58,8 @@
"NVIDIA": NvidiaCV,
"LM-Studio": LmStudioCV,
"StepFun":StepFunCV,
"OpenAI-API-Compatible": OpenAI_APICV
"OpenAI-API-Compatible": OpenAI_APICV,
"TogetherAI": TogetherAICV
}


Expand Down Expand Up @@ -86,6 +88,7 @@
"OpenAI-API-Compatible": OpenAI_APIChat,
"cohere": CoHereChat,
"LeptonAI": LeptonAIChat,
"TogetherAI": TogetherAIChat,
"PerfXCloud": PerfXCloudChat
}

Expand All @@ -98,7 +101,8 @@
"NVIDIA": NvidiaRerank,
"LM-Studio": LmStudioRerank,
"OpenAI-API-Compatible": OpenAI_APIRerank,
"cohere": CoHereRerank
"cohere": CoHereRerank,
"TogetherAI": TogetherAIRerank
}


Expand Down
7 changes: 7 additions & 0 deletions rag/llm/chat_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,13 @@ def __init__(self, key, model_name, base_url=None):
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:
Expand Down
7 changes: 7 additions & 0 deletions rag/llm/cv_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,3 +649,10 @@ def __init__(self, key, model_name, base_url, lang="Chinese"):
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)
8 changes: 8 additions & 0 deletions rag/llm/embedding_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,8 +555,16 @@ def encode_queries(self, text):
)


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)

8 changes: 8 additions & 0 deletions rag/llm/rerank_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,11 @@ def similarity(self, query: str, texts: list):
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")
15 changes: 15 additions & 0 deletions web/src/assets/svg/llm/together-ai.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion web/src/pages/user-setting/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ export const UserSettingIconMap = {

export * from '@/constants/setting';

export const LocalLlmFactories = ['Ollama', 'Xinference','LocalAI','LM-Studio',"OpenAI-API-Compatible"];
export const LocalLlmFactories = ['Ollama', 'Xinference','LocalAI','LM-Studio',"OpenAI-API-Compatible",'TogetherAI'];
1 change: 1 addition & 0 deletions web/src/pages/user-setting/setting-model/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const IconMap = {
'OpenAI-API-Compatible': 'openai-api',
cohere: 'cohere',
Lepton: 'lepton',
TogetherAI:'together-ai',
PerfXCould: 'perfx-could'
};

Expand Down