Skip to content

Commit 15f58f8

Browse files
committed
[0.4.11][fix] TuneModel function calling error
1 parent 3631ce8 commit 15f58f8

File tree

4 files changed

+22
-13
lines changed

4 files changed

+22
-13
lines changed

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.4.10"
3+
version = "0.4.11"
44
description = "Tune AI APIs."
55
authors = ["Frello Technology Private Limited <[email protected]>"]
66
license = "MIT"

tuneapi/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Copyright © 2023- Frello Technology Private Limited
22

3-
__version__ = "0.4.10"
3+
__version__ = "0.4.11"

tuneapi/apis/model_tune.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def stream_chat(
154154
}
155155
if stop_sequence:
156156
data["stop_sequence"] = stop_sequence
157-
if isinstance(chats, tt.Thread):
157+
if isinstance(chats, tt.Thread) and len(chats.tools):
158158
data["tools"] = [
159159
{"type": "function", "function": x.to_dict()} for x in chats.tools
160160
]
@@ -185,15 +185,20 @@ def stream_chat(
185185
line = line.decode().strip()
186186
if line:
187187
try:
188-
x = json.loads(line.replace("data: ", ""))["choices"][0]["delta"]
189-
if "tool_calls" in x:
190-
y = x["tool_calls"][0]["function"]
188+
delta = json.loads(line.replace("data: ", ""))["choices"][0][
189+
"delta"
190+
]
191+
if "tool_calls" in delta:
192+
y = delta["tool_calls"][0]["function"]
191193
if fn_call is None:
192-
fn_call = {"name": y["name"], "arguments": y["arguments"]}
194+
fn_call = {
195+
"name": y["name"],
196+
"arguments": y.get("arguments", ""),
197+
}
193198
else:
194199
fn_call["arguments"] += y["arguments"]
195-
elif "content" in x:
196-
yield x["content"]
200+
elif "content" in delta:
201+
yield delta["content"]
197202
except:
198203
break
199204
if fn_call:

tuneapi/utils/fs.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ def get_files_in_folder(
3333
if _all:
3434
for f in files:
3535
_fp = joinp(root, f)
36-
if not ignore_pat.search(_fp).group():
36+
_ig_pat = ignore_pat.search(_fp)
37+
if not _ig_pat or not _ig_pat.group():
3738
all_paths.append(_fp)
3839
continue
3940

@@ -42,21 +43,24 @@ def get_files_in_folder(
4243
print(e)
4344
if f.endswith(e):
4445
_fp = joinp(root, f)
45-
if not ignore_pat.search(_fp).group():
46+
_ig_pat = ignore_pat.search(_fp)
47+
if not _ig_pat or not _ig_pat.group():
4648
all_paths.append(_fp)
4749

4850
else:
4951
for f in os.listdir(folder_abs):
5052
if _all:
5153
_fp = joinp(folder_abs, f)
52-
if not ignore_pat.search(_fp).group():
54+
_ig_pat = ignore_pat.search(_fp)
55+
if not _ig_pat or not _ig_pat.group():
5356
all_paths.append(_fp)
5457
continue
5558

5659
for e in ext:
5760
if f.endswith(e):
5861
_fp = joinp(folder_abs, f)
59-
if not ignore_pat.search(_fp).group():
62+
_ig_pat = ignore_pat.search(_fp)
63+
if not _ig_pat or not _ig_pat.group():
6064
all_paths.append(_fp)
6165

6266
return all_paths

0 commit comments

Comments
 (0)