Skip to content

Commit

Permalink
fix bug when adding openai or openai-compatible stt model instance (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
zhao85 authored Oct 7, 2024
1 parent e1e2d0b commit fcfa125
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
2 changes: 1 addition & 1 deletion api/core/agent/output_parser/cot_output_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def handle_react_stream_output(
) -> Generator[Union[str, AgentScratchpadUnit.Action], None, None]:
def parse_action(json_str):
try:
action = json.loads(json_str)
action = json.loads(json_str, strict=False)
action_name = None
action_input = None

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from openai import OpenAI

from core.model_runtime.entities.common_entities import I18nObject
from core.model_runtime.entities.model_entities import AIModelEntity, FetchFrom, ModelType
from core.model_runtime.errors.validate import CredentialsValidateFailedError
from core.model_runtime.model_providers.__base.speech2text_model import Speech2TextModel
from core.model_runtime.model_providers.openai._common import _CommonOpenAI
Expand Down Expand Up @@ -58,3 +60,18 @@ def _speech2text_invoke(self, model: str, credentials: dict, file: IO[bytes]) ->
response = client.audio.transcriptions.create(model=model, file=file)

return response.text

def get_customizable_model_schema(self, model: str, credentials: dict) -> AIModelEntity | None:
"""
used to define customizable model schema
"""
entity = AIModelEntity(
model=model,
label=I18nObject(en_US=model),
fetch_from=FetchFrom.CUSTOMIZABLE_MODEL,
model_type=ModelType.SPEECH2TEXT,
model_properties={},
parameter_rules=[],
)

return entity
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import requests

from core.model_runtime.entities.common_entities import I18nObject
from core.model_runtime.entities.model_entities import AIModelEntity, FetchFrom, ModelType
from core.model_runtime.errors.invoke import InvokeBadRequestError
from core.model_runtime.errors.validate import CredentialsValidateFailedError
from core.model_runtime.model_providers.__base.speech2text_model import Speech2TextModel
Expand Down Expand Up @@ -59,3 +61,18 @@ def validate_credentials(self, model: str, credentials: dict) -> None:
self._invoke(model, credentials, audio_file)
except Exception as ex:
raise CredentialsValidateFailedError(str(ex))

def get_customizable_model_schema(self, model: str, credentials: dict) -> AIModelEntity | None:
"""
used to define customizable model schema
"""
entity = AIModelEntity(
model=model,
label=I18nObject(en_US=model),
fetch_from=FetchFrom.CUSTOMIZABLE_MODEL,
model_type=ModelType.SPEECH2TEXT,
model_properties={},
parameter_rules=[],
)

return entity
11 changes: 7 additions & 4 deletions api/core/tools/tool/workflow_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,13 @@ def _invoke(

result = []

outputs = data.get("outputs", {})
outputs, files = self._extract_files(outputs)
for file in files:
result.append(self.create_file_var_message(file))
outputs = data.get("outputs")
if outputs == None:
outputs = {}
else:
outputs, files = self._extract_files(outputs)
for file in files:
result.append(self.create_file_var_message(file))

result.append(self.create_text_message(json.dumps(outputs, ensure_ascii=False)))
result.append(self.create_json_message(outputs))
Expand Down

0 comments on commit fcfa125

Please sign in to comment.