黄腾 aopstudio Kevin Hu commited on
Commit
5036aed
·
1 Parent(s): ce69533

add support for TogetherAI (#1890)

Browse files

### 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 <[email protected]>
Co-authored-by: Kevin Hu <[email protected]>

api/apps/llm_app.py CHANGED
@@ -135,7 +135,7 @@ def add_llm():
135
  api_key = req.get("api_key","xxxxxxxxxxxxxxx")
136
  else:
137
  llm_name = req["llm_name"]
138
- api_key = "xxxxxxxxxxxxxxx"
139
 
140
  llm = {
141
  "tenant_id": current_user.id,
 
135
  api_key = req.get("api_key","xxxxxxxxxxxxxxx")
136
  else:
137
  llm_name = req["llm_name"]
138
+ api_key = req.get("api_key","xxxxxxxxxxxxxxx")
139
 
140
  llm = {
141
  "tenant_id": current_user.id,
conf/llm_factories.json CHANGED
@@ -2443,6 +2443,13 @@
2443
  }
2444
  ]
2445
  },
 
 
 
 
 
 
 
2446
  {
2447
  "name": "PerfXCloud",
2448
  "logo": "",
@@ -2594,6 +2601,6 @@
2594
  "model_type": "embedding"
2595
  }
2596
  ]
2597
- }
2598
  ]
2599
  }
 
2443
  }
2444
  ]
2445
  },
2446
+ {
2447
+ "name": "TogetherAI",
2448
+ "logo": "",
2449
+ "tags": "LLM,TEXT EMBEDDING,IMAGE2TEXT",
2450
+ "status": "1",
2451
+ "llm": []
2452
+ },
2453
  {
2454
  "name": "PerfXCloud",
2455
  "logo": "",
 
2601
  "model_type": "embedding"
2602
  }
2603
  ]
2604
+ }
2605
  ]
2606
  }
rag/llm/__init__.py CHANGED
@@ -39,6 +39,7 @@ EmbeddingModel = {
39
  "LM-Studio": LmStudioEmbed,
40
  "OpenAI-API-Compatible": OpenAI_APIEmbed,
41
  "cohere": CoHereEmbed,
 
42
  "PerfXCloud": PerfXCloudEmbed,
43
  }
44
 
@@ -57,7 +58,8 @@ CvModel = {
57
  "NVIDIA": NvidiaCV,
58
  "LM-Studio": LmStudioCV,
59
  "StepFun":StepFunCV,
60
- "OpenAI-API-Compatible": OpenAI_APICV
 
61
  }
62
 
63
 
@@ -86,6 +88,7 @@ ChatModel = {
86
  "OpenAI-API-Compatible": OpenAI_APIChat,
87
  "cohere": CoHereChat,
88
  "LeptonAI": LeptonAIChat,
 
89
  "PerfXCloud": PerfXCloudChat
90
  }
91
 
@@ -98,7 +101,8 @@ RerankModel = {
98
  "NVIDIA": NvidiaRerank,
99
  "LM-Studio": LmStudioRerank,
100
  "OpenAI-API-Compatible": OpenAI_APIRerank,
101
- "cohere": CoHereRerank
 
102
  }
103
 
104
 
 
39
  "LM-Studio": LmStudioEmbed,
40
  "OpenAI-API-Compatible": OpenAI_APIEmbed,
41
  "cohere": CoHereEmbed,
42
+ "TogetherAI": TogetherAIEmbed,
43
  "PerfXCloud": PerfXCloudEmbed,
44
  }
45
 
 
58
  "NVIDIA": NvidiaCV,
59
  "LM-Studio": LmStudioCV,
60
  "StepFun":StepFunCV,
61
+ "OpenAI-API-Compatible": OpenAI_APICV,
62
+ "TogetherAI": TogetherAICV
63
  }
64
 
65
 
 
88
  "OpenAI-API-Compatible": OpenAI_APIChat,
89
  "cohere": CoHereChat,
90
  "LeptonAI": LeptonAIChat,
91
+ "TogetherAI": TogetherAIChat,
92
  "PerfXCloud": PerfXCloudChat
93
  }
94
 
 
101
  "NVIDIA": NvidiaRerank,
102
  "LM-Studio": LmStudioRerank,
103
  "OpenAI-API-Compatible": OpenAI_APIRerank,
104
+ "cohere": CoHereRerank,
105
+ "TogetherAI": TogetherAIRerank
106
  }
107
 
108
 
rag/llm/chat_model.py CHANGED
@@ -990,6 +990,13 @@ class LeptonAIChat(Base):
990
  super().__init__(key, model_name, base_url)
991
 
992
 
 
 
 
 
 
 
 
993
  class PerfXCloudChat(Base):
994
  def __init__(self, key, model_name, base_url="https://cloud.perfxlab.cn/v1"):
995
  if not base_url:
 
990
  super().__init__(key, model_name, base_url)
991
 
992
 
993
+ class TogetherAIChat(Base):
994
+ def __init__(self, key, model_name, base_url="https://api.together.xyz/v1"):
995
+ if not base_url:
996
+ base_url = "https://api.together.xyz/v1"
997
+ super().__init__(key, model_name, base_url)
998
+
999
+
1000
  class PerfXCloudChat(Base):
1001
  def __init__(self, key, model_name, base_url="https://cloud.perfxlab.cn/v1"):
1002
  if not base_url:
rag/llm/cv_model.py CHANGED
@@ -649,3 +649,10 @@ class OpenAI_APICV(GptV4):
649
  self.client = OpenAI(api_key=key, base_url=base_url)
650
  self.model_name = model_name.split("___")[0]
651
  self.lang = lang
 
 
 
 
 
 
 
 
649
  self.client = OpenAI(api_key=key, base_url=base_url)
650
  self.model_name = model_name.split("___")[0]
651
  self.lang = lang
652
+
653
+
654
+ class TogetherAICV(GptV4):
655
+ def __init__(self, key, model_name, base_url="https://api.together.xyz/v1"):
656
+ if not base_url:
657
+ base_url = "https://api.together.xyz/v1"
658
+ super().__init__(key, model_name, base_url)
rag/llm/embedding_model.py CHANGED
@@ -555,8 +555,16 @@ class CoHereEmbed(Base):
555
  )
556
 
557
 
 
 
 
 
 
 
 
558
  class PerfXCloudEmbed(OpenAIEmbed):
559
  def __init__(self, key, model_name, base_url="https://cloud.perfxlab.cn/v1"):
560
  if not base_url:
561
  base_url = "https://cloud.perfxlab.cn/v1"
562
  super().__init__(key, model_name, base_url)
 
 
555
  )
556
 
557
 
558
+ class TogetherAIEmbed(OllamaEmbed):
559
+ def __init__(self, key, model_name, base_url="https://api.together.xyz/v1"):
560
+ if not base_url:
561
+ base_url = "https://api.together.xyz/v1"
562
+ super().__init__(key, model_name, base_url)
563
+
564
+
565
  class PerfXCloudEmbed(OpenAIEmbed):
566
  def __init__(self, key, model_name, base_url="https://cloud.perfxlab.cn/v1"):
567
  if not base_url:
568
  base_url = "https://cloud.perfxlab.cn/v1"
569
  super().__init__(key, model_name, base_url)
570
+
rag/llm/rerank_model.py CHANGED
@@ -245,3 +245,11 @@ class CoHereRerank(Base):
245
  rank = np.array([d.relevance_score for d in res.results])
246
  indexs = [d.index for d in res.results]
247
  return rank[indexs], token_count
 
 
 
 
 
 
 
 
 
245
  rank = np.array([d.relevance_score for d in res.results])
246
  indexs = [d.index for d in res.results]
247
  return rank[indexs], token_count
248
+
249
+
250
+ class TogetherAIRerank(Base):
251
+ def __init__(self, key, model_name, base_url):
252
+ pass
253
+
254
+ def similarity(self, query: str, texts: list):
255
+ raise NotImplementedError("The api has not been implement")
web/src/assets/svg/llm/together-ai.svg ADDED
web/src/pages/user-setting/constants.tsx CHANGED
@@ -17,4 +17,4 @@ export const UserSettingIconMap = {
17
 
18
  export * from '@/constants/setting';
19
 
20
- export const LocalLlmFactories = ['Ollama', 'Xinference','LocalAI','LM-Studio',"OpenAI-API-Compatible"];
 
17
 
18
  export * from '@/constants/setting';
19
 
20
+ export const LocalLlmFactories = ['Ollama', 'Xinference','LocalAI','LM-Studio',"OpenAI-API-Compatible",'TogetherAI'];
web/src/pages/user-setting/setting-model/constant.ts CHANGED
@@ -25,6 +25,7 @@ export const IconMap = {
25
  'OpenAI-API-Compatible': 'openai-api',
26
  cohere: 'cohere',
27
  Lepton: 'lepton',
 
28
  PerfXCould: 'perfx-could'
29
  };
30
 
 
25
  'OpenAI-API-Compatible': 'openai-api',
26
  cohere: 'cohere',
27
  Lepton: 'lepton',
28
+ TogetherAI:'together-ai',
29
  PerfXCould: 'perfx-could'
30
  };
31