congxin95 commited on
Commit
bbe7416
·
1 Parent(s): 7afe9d4
Files changed (1) hide show
  1. bmtools/agent/translator.py +10 -1
bmtools/agent/translator.py CHANGED
@@ -21,11 +21,20 @@ class Translator:
21
  def __init__(self,
22
  openai_api_key: str = None,
23
  model_name: str = "gpt-3.5-turbo"):
24
- llm = self.create_openai_model(openai_api_key, model_name)
 
 
 
 
 
25
  prompt = self.create_prompt()
26
  self.chain = LLMChain(llm=llm, prompt=prompt)
27
 
28
  def __call__(self, inputs: Dict[str, str]) -> Dict[str, str]:
 
 
 
 
29
  question = inputs["input"]
30
  answer = inputs["output"]
31
 
 
21
  def __init__(self,
22
  openai_api_key: str = None,
23
  model_name: str = "gpt-3.5-turbo"):
24
+ self.openai_api_key = openai_api_key
25
+ self.model_name = model_name
26
+ self.is_create = False
27
+
28
+ def create_chain(self):
29
+ llm = self.create_openai_model(self.openai_api_key, self.model_name)
30
  prompt = self.create_prompt()
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