Skip to content

Commit 091a33d

Browse files
committed
[0.6.0] Turbo with distributed_chat
1 parent ffcbf3b commit 091a33d

File tree

12 files changed

+298
-9
lines changed

12 files changed

+298
-9
lines changed

docs/changelog.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ minor versions.
77

88
All relevant steps to be taken will be mentioned here.
99

10+
0.6.0
11+
-----
12+
13+
- ``distributed_chat`` functionality in ``tuneapi.apis.turbo`` support. In all APIs search for ``model.distributed_chat()``
14+
method. This enables **fault tolerant LLM API calls**.
15+
1016
0.5.13
1117
-----
1218

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "tuneapi"
3-
version = "0.5.13"
3+
version = "0.6.0"
44
description = "Tune AI APIs."
55
authors = ["Frello Technology Private Limited <[email protected]>"]
66
license = "MIT"

tuneapi/apis/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
from tuneapi.apis.model_groq import Groq
88
from tuneapi.apis.model_mistral import Mistral
99
from tuneapi.apis.model_gemini import Gemini
10+
from tuneapi.apis.turbo import distributed_chat

tuneapi/apis/model_anthropic.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import tuneapi.utils as tu
1313
import tuneapi.types as tt
14+
from tuneapi.apis.turbo import distributed_chat
1415

1516

1617
class Anthropic(tt.ModelInterface):
@@ -236,6 +237,23 @@ def stream_chat(
236237
break
237238
return
238239

240+
def distributed_chat(
241+
self,
242+
prompts: List[tt.Thread],
243+
post_logic: Optional[callable] = None,
244+
max_threads: int = 10,
245+
retry: int = 3,
246+
pbar=True,
247+
):
248+
return distributed_chat(
249+
self,
250+
prompts=prompts,
251+
post_logic=post_logic,
252+
max_threads=max_threads,
253+
retry=retry,
254+
pbar=pbar,
255+
)
256+
239257

240258
# helper methods
241259

tuneapi/apis/model_gemini.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77

88
import json
99
import requests
10-
from typing import Optional, Any, Dict
10+
from typing import Optional, Any, Dict, List
1111

1212
import tuneapi.utils as tu
1313
import tuneapi.types as tt
14+
from tuneapi.apis.turbo import distributed_chat
1415

1516

1617
class Gemini(tt.ModelInterface):
@@ -276,3 +277,20 @@ def stream_chat(
276277
fn_call["arguments"] = fn_call.pop("args")
277278
yield fn_call
278279
block_lines = ""
280+
281+
def distributed_chat(
282+
self,
283+
prompts: List[tt.Thread],
284+
post_logic: Optional[callable] = None,
285+
max_threads: int = 10,
286+
retry: int = 3,
287+
pbar=True,
288+
):
289+
return distributed_chat(
290+
self,
291+
prompts=prompts,
292+
post_logic=post_logic,
293+
max_threads=max_threads,
294+
retry=retry,
295+
pbar=pbar,
296+
)

tuneapi/apis/model_groq.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import tuneapi.utils as tu
1212
import tuneapi.types as tt
13+
from tuneapi.apis.turbo import distributed_chat
1314

1415

1516
class Groq(tt.ModelInterface):
@@ -190,3 +191,20 @@ def stream_chat(
190191
fn_call["arguments"] = tu.from_json(fn_call["arguments"])
191192
yield fn_call
192193
return
194+
195+
def distributed_chat(
196+
self,
197+
prompts: List[tt.Thread],
198+
post_logic: Optional[callable] = None,
199+
max_threads: int = 10,
200+
retry: int = 3,
201+
pbar=True,
202+
):
203+
return distributed_chat(
204+
self,
205+
prompts=prompts,
206+
post_logic=post_logic,
207+
max_threads=max_threads,
208+
retry=retry,
209+
pbar=pbar,
210+
)

tuneapi/apis/model_mistral.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010

1111
import tuneapi.utils as tu
1212
import tuneapi.types as tt
13-
from tuneapi.utils import ENV, SimplerTimes as stime, from_json, to_json
14-
from tuneapi.types import Thread, human, Message
13+
from tuneapi.apis.turbo import distributed_chat
1514

1615

1716
class Mistral(tt.ModelInterface):
@@ -23,7 +22,7 @@ def __init__(
2322
):
2423
self.model_id = id
2524
self.base_url = base_url
26-
self.api_token = ENV.MISTRAL_TOKEN("")
25+
self.api_token = tu.ENV.MISTRAL_TOKEN("")
2726
self.extra_headers = extra_headers
2827

2928
def set_api_token(self, token: str) -> None:
@@ -95,7 +94,7 @@ def _process_input(self, chats, token: Optional[str] = None):
9594

9695
def chat(
9796
self,
98-
chats: Thread | str,
97+
chats: tt.Thread | str,
9998
model: Optional[str] = None,
10099
max_tokens: int = 1024,
101100
temperature: float = 1,
@@ -124,7 +123,7 @@ def chat(
124123

125124
def stream_chat(
126125
self,
127-
chats: Thread | str,
126+
chats: tt.Thread | str,
128127
model: Optional[str] = None,
129128
max_tokens: int = 1024,
130129
temperature: float = 1,
@@ -135,7 +134,7 @@ def stream_chat(
135134
extra_headers: Optional[Dict[str, str]] = None,
136135
):
137136
tools = []
138-
if isinstance(chats, Thread):
137+
if isinstance(chats, tt.Thread):
139138
tools = [{"type": "function", "function": x.to_dict()} for x in chats.tools]
140139
headers, messages = self._process_input(chats, token)
141140
extra_headers = extra_headers or self.extra_headers
@@ -191,6 +190,23 @@ def stream_chat(
191190
except:
192191
break
193192
if fn_call:
194-
fn_call["arguments"] = from_json(fn_call["arguments"])
193+
fn_call["arguments"] = tu.from_json(fn_call["arguments"])
195194
yield fn_call
196195
return
196+
197+
def distributed_chat(
198+
self,
199+
prompts: List[tt.Thread],
200+
post_logic: Optional[callable] = None,
201+
max_threads: int = 10,
202+
retry: int = 3,
203+
pbar=True,
204+
):
205+
return distributed_chat(
206+
self,
207+
prompts=prompts,
208+
post_logic=post_logic,
209+
max_threads=max_threads,
210+
retry=retry,
211+
pbar=pbar,
212+
)

tuneapi/apis/model_openai.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import tuneapi.utils as tu
1313
import tuneapi.types as tt
14+
from tuneapi.apis.turbo import distributed_chat
1415

1516

1617
class Openai(tt.ModelInterface):
@@ -190,6 +191,23 @@ def stream_chat(
190191
yield fn_call
191192
return
192193

194+
def distributed_chat(
195+
self,
196+
prompts: List[tt.Thread],
197+
post_logic: Optional[callable] = None,
198+
max_threads: int = 10,
199+
retry: int = 3,
200+
pbar=True,
201+
):
202+
return distributed_chat(
203+
self,
204+
prompts=prompts,
205+
post_logic=post_logic,
206+
max_threads=max_threads,
207+
retry=retry,
208+
pbar=pbar,
209+
)
210+
193211
def embedding(
194212
self,
195213
chats: tt.Thread | List[str] | str,

tuneapi/apis/model_tune.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import tuneapi.utils as tu
1212
import tuneapi.types as tt
13+
from tuneapi.apis.turbo import distributed_chat
1314

1415

1516
class TuneModel(tt.ModelInterface):
@@ -217,3 +218,20 @@ def stream_chat(
217218
fn_call["arguments"] = tu.from_json(fn_call["arguments"])
218219
yield fn_call
219220
return
221+
222+
def distributed_chat(
223+
self,
224+
prompts: List[tt.Thread],
225+
post_logic: Optional[callable] = None,
226+
max_threads: int = 10,
227+
retry: int = 3,
228+
pbar=True,
229+
):
230+
return distributed_chat(
231+
self,
232+
prompts=prompts,
233+
post_logic=post_logic,
234+
max_threads=max_threads,
235+
retry=retry,
236+
pbar=pbar,
237+
)

0 commit comments

Comments
 (0)