feat(core): Support multi round conversation operator (#986)

This commit is contained in:
Fangyin Cheng
2023-12-27 23:26:28 +08:00
committed by GitHub
parent 9aec636b02
commit b13d3f6d92
63 changed files with 2011 additions and 314 deletions

View File

@@ -1,3 +1,4 @@
import os
from functools import cache
from typing import Any, Dict, Optional
@@ -33,3 +34,19 @@ class AppConfig:
prefix (str): The prefix of config
"""
return {k: v for k, v in self.configs.items() if k.startswith(prefix)}
def get_current_lang(self, default: Optional[str] = None) -> str:
"""Get current language
Args:
default (Optional[str], optional): The default language if not found. Defaults to None.
Returns:
str: The language of user running environment
"""
env_lang = (
"zh"
if os.getenv("LANG") and os.getenv("LANG").startswith("zh")
else default
)
return self.get("dbgpt.app.global.language", env_lang)

View File

@@ -44,11 +44,20 @@ async def _do_chat_completion(
decoded_line = line.split("data: ", 1)[1]
if decoded_line.lower().strip() != "[DONE]".lower():
obj = json.loads(decoded_line)
if obj["choices"][0]["delta"].get("content") is not None:
text = obj["choices"][0]["delta"].get("content")
if "error_code" in obj and obj["error_code"] != 0:
if caller:
await caller(text)
yield text
await caller(obj.get("text"))
yield obj.get("text")
else:
if (
"choices" in obj
and obj["choices"][0]["delta"].get("content")
is not None
):
text = obj["choices"][0]["delta"].get("content")
if caller:
await caller(text)
yield text
await asyncio.sleep(0.02)

View File

@@ -139,7 +139,7 @@ class FileSpanStorage(SpanStorage):
def _write_to_file(self, spans: List[Span]):
self._roll_over_if_needed()
with open(self.filename, "a") as file:
with open(self.filename, "a", encoding="utf8") as file:
for span in spans:
span_data = span.to_dict()
try:

View File

@@ -10,6 +10,14 @@ import asyncio
from dbgpt.configs.model_config import LOGDIR
try:
from termcolor import colored
except ImportError:
def colored(x, *args, **kwargs):
return x
server_error_msg = (
"**NETWORK ERROR DUE TO HIGH TRAFFIC. PLEASE REGENERATE OR REFRESH THIS PAGE.**"
)