diff --git a/pkg/openai/modelmgr.py b/pkg/openai/modelmgr.py index 0b287752..cdc51297 100644 --- a/pkg/openai/modelmgr.py +++ b/pkg/openai/modelmgr.py @@ -112,6 +112,7 @@ def count_completion_tokens(messages: list, model: str) -> int: def count_tokens(messages: list, model: str): + if model in CHAT_COMPLETION_MODELS: return count_chat_completion_tokens(messages, model) elif model in COMPLETION_MODELS: diff --git a/pkg/openai/session.py b/pkg/openai/session.py index 2b8a145b..1400a8c6 100644 --- a/pkg/openai/session.py +++ b/pkg/openai/session.py @@ -271,7 +271,7 @@ class Session: } if 'function_call' in resp['choices'][0]['message']: - msg['function_call'] = resp['choices'][0]['message']['function_call'] + msg['function_call'] = json.dumps(resp['choices'][0]['message']['function_call']) pending_msgs.append(msg)