mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-09-06 19:40:13 +00:00
feat(core): Support multi round conversation operator (#986)
This commit is contained in:
@@ -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)
|
||||
|
@@ -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)
|
||||
|
||||
|
||||
|
@@ -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:
|
||||
|
@@ -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.**"
|
||||
)
|
||||
|
Reference in New Issue
Block a user