Spaces:
Runtime error
Runtime error
fix bug
Browse files- bmtools/agent/executor.py +2 -2
- bmtools/agent/translator.py +18 -18
bmtools/agent/executor.py
CHANGED
@@ -20,8 +20,8 @@ class AgentExecutorWithTranslation(AgentExecutor):
|
|
20 |
except ValueError as e:
|
21 |
return outputs
|
22 |
else:
|
23 |
-
if "input" in outputs:
|
24 |
-
|
25 |
return outputs
|
26 |
|
27 |
class Executor(AgentExecutorWithTranslation):
|
|
|
20 |
except ValueError as e:
|
21 |
return outputs
|
22 |
else:
|
23 |
+
# if "input" in outputs:
|
24 |
+
# outputs = self.translator(outputs)
|
25 |
return outputs
|
26 |
|
27 |
class Executor(AgentExecutorWithTranslation):
|
bmtools/agent/translator.py
CHANGED
@@ -31,24 +31,24 @@ class Translator:
|
|
31 |
self.chain = LLMChain(llm=llm, prompt=prompt)
|
32 |
|
33 |
def __call__(self, inputs: Dict[str, str]) -> Dict[str, str]:
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
return inputs
|
52 |
|
53 |
def create_openai_model(self, openai_api_key: str, model_name: str) -> OpenAI:
|
54 |
if openai_api_key is None:
|
|
|
31 |
self.chain = LLMChain(llm=llm, prompt=prompt)
|
32 |
|
33 |
def __call__(self, inputs: Dict[str, str]) -> Dict[str, str]:
|
34 |
+
if not self.is_create:
|
35 |
+
self.create_chain()
|
36 |
+
self.is_create = True
|
37 |
+
|
38 |
+
question = inputs["input"]
|
39 |
+
answer = inputs["output"]
|
40 |
+
|
41 |
+
src_lang = detect_lang(answer)
|
42 |
+
tgt_lang = detect_lang(question)
|
43 |
+
|
44 |
+
if src_lang != tgt_lang:
|
45 |
+
translated_answer = self.chain.run(text=answer, language=tgt_lang)
|
46 |
+
outputs = deepcopy(inputs)
|
47 |
+
outputs["output"] = translated_answer
|
48 |
+
return outputs
|
49 |
+
else:
|
50 |
+
return inputs
|
51 |
+
# return inputs
|
52 |
|
53 |
def create_openai_model(self, openai_api_key: str, model_name: str) -> OpenAI:
|
54 |
if openai_api_key is None:
|