Skip to content
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
4 changes: 4 additions & 0 deletions devchat/_cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import os
from .log import log
from .prompt import prompt
from .run import run
from .topic import topic
from .route import route
from .command import commands, command, Command

script_dir = os.path.dirname(os.path.realpath(__file__))
os.environ['TIKTOKEN_CACHE_DIR'] = os.path.join(script_dir, '..', 'tiktoken_cache')

__all__ = [
'log',
'prompt',
Expand Down
15 changes: 11 additions & 4 deletions devchat/llm/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,7 @@ def chunks_call(chunks):

def content_to_json(content):
try:
# json will format as ```json ... ``` in 1106 model
response_content = _try_remove_markdown_block_flag(content)
response_obj = json.loads(response_content)
response_obj = json.loads(content)
return response_obj
except json.JSONDecodeError as err:
raise RetryException(err) from err
Expand Down Expand Up @@ -148,14 +146,23 @@ def to_dict_content_and_call(content, tool_calls=None):
pipeline(chat_completion_stream_commit, retry_timeout, chunks_call), times=3
)

chat_completion_no_stream_return_json = exception_handle(
chat_completion_no_stream_return_json_with_retry = exception_handle(
retry(
pipeline(chat_completion_stream_commit, retry_timeout, chunks_content, content_to_json),
times=3,
),
exception_output_handle(lambda err: None),
)

def chat_completion_no_stream_return_json(
messages: List[Dict], llm_config: Dict):
"""call llm without stream, return json object"""
llm_config["response_format"]={"type": "json_object"}
return chat_completion_no_stream_return_json_with_retry(
messages=messages,
llm_config=llm_config)


chat_completion_stream = exception_handle(
retry(
pipeline(
Expand Down