Oh Gyuhyeok commited on
Commit
0a21623
Β·
unverified Β·
1 Parent(s): 1ff874c

Fix bug fix (#4)

Browse files
Files changed (1) hide show
  1. easyword_translator/run.py +8 -4
easyword_translator/run.py CHANGED
@@ -56,6 +56,7 @@ def recommend_prompt(jargon: str) -> str:
56
 
57
 
58
  llm = ChatUpstage()
 
59
 
60
 
61
  def chainer(messages):
@@ -77,6 +78,9 @@ SAMPLE_TRANSLATION = "값쀑심 ν”„λ‘œκ·Έλž˜λ°[functional programming]μ—μ„œ,
77
 
78
 
79
  def translate(sentence: str) -> str:
 
 
 
80
  messages = [
81
  SystemMessage(content=SYSTEM_PROMPT),
82
  HumanMessage(
@@ -88,7 +92,7 @@ def translate(sentence: str) -> str:
88
  ),
89
  ]
90
 
91
- initial_translation = chainer(messages).invoke({})
92
  logger.info(initial_translation)
93
 
94
  used_jargons = find_jargons(sentence)
@@ -98,7 +102,7 @@ def translate(sentence: str) -> str:
98
  content=f"방금 λ²ˆμ—­ν•œ λ¬Έμž₯μ—μ„œ '{', '.join(used_jargons)}' 쀑 μ‚¬μš©ν•œ μš©μ–΄κ°€ μžˆλ‹€λ©΄, μ–΄λ–€ μš©μ–΄λ“€λ‘œ λ²ˆμ—­ν–ˆλŠ”μ§€ λ§ν•΄μ€˜. μ‚¬μš©ν•˜μ§€ μ•Šμ€ μš©μ–΄λ“€μ€ λ¬΄μ‹œν•΄λ„ 돼."
99
  ),
100
  ]
101
- response = chainer(messages).invoke({})
102
  logger.info(response)
103
 
104
  recommendations = ", ".join(recommend_prompt(jargon) for jargon in used_jargons)
@@ -109,7 +113,7 @@ def translate(sentence: str) -> str:
109
  content=f"μ΄λ²ˆμ—λŠ” 처음 λ²ˆμ—­ν–ˆλ˜ λ¬Έμž₯을 '{sentence}'λ₯Ό λ‹€μ‹œ λ²ˆμ—­ν•΄μ£ΌλŠ”λ°, λ‹€μŒ λͺ©λ‘μ— λ‚˜μ˜¨ μ‰¬μš΄ μ „λ¬Έμš©μ–΄ λ²ˆμ—­ μ˜ˆμ‹œλ₯Ό μ°Έκ³ ν•΄μ„œ λ²ˆμ—­μ„ ν•΄μ€˜: '{recommendations}' μ‚¬μš©ν•˜μ§€ μ•Šμ€ μš©μ–΄λ“€μ€ λ¬΄μ‹œν•΄λ„ 돼. μΆ”κ°€ μ„€λͺ… 없이 λ¬Έμž₯만 λ²ˆμ—­ν•΄. μ‚¬μš©λœ 원어λ₯Ό μš©μ–΄ λ°”λ‘œ 뒀에 κ΄„ν˜Έ []에 λ„£μ–΄μ„œ 따라 λΆ™μ—¬μ€˜."
110
  ),
111
  ]
112
- refined_translation = chainer(messages).invoke({})
113
  logger.info(refined_translation)
114
 
115
  retries = 0
@@ -124,7 +128,7 @@ def translate(sentence: str) -> str:
124
  ),
125
  ]
126
  try:
127
- refined_translation = chainer(messages).invoke({})
128
  except Exception as e:
129
  logger.error(e)
130
  break
 
56
 
57
 
58
  llm = ChatUpstage()
59
+ llm = llm | StrOutputParser()
60
 
61
 
62
  def chainer(messages):
 
78
 
79
 
80
  def translate(sentence: str) -> str:
81
+ # remove "{", "}" in sentence.
82
+ # sentence = sentence.replace("{", "").replace("}", "")
83
+
84
  messages = [
85
  SystemMessage(content=SYSTEM_PROMPT),
86
  HumanMessage(
 
92
  ),
93
  ]
94
 
95
+ initial_translation = llm.invoke(messages)
96
  logger.info(initial_translation)
97
 
98
  used_jargons = find_jargons(sentence)
 
102
  content=f"방금 λ²ˆμ—­ν•œ λ¬Έμž₯μ—μ„œ '{', '.join(used_jargons)}' 쀑 μ‚¬μš©ν•œ μš©μ–΄κ°€ μžˆλ‹€λ©΄, μ–΄λ–€ μš©μ–΄λ“€λ‘œ λ²ˆμ—­ν–ˆλŠ”μ§€ λ§ν•΄μ€˜. μ‚¬μš©ν•˜μ§€ μ•Šμ€ μš©μ–΄λ“€μ€ λ¬΄μ‹œν•΄λ„ 돼."
103
  ),
104
  ]
105
+ response = llm.invoke(messages)
106
  logger.info(response)
107
 
108
  recommendations = ", ".join(recommend_prompt(jargon) for jargon in used_jargons)
 
113
  content=f"μ΄λ²ˆμ—λŠ” 처음 λ²ˆμ—­ν–ˆλ˜ λ¬Έμž₯을 '{sentence}'λ₯Ό λ‹€μ‹œ λ²ˆμ—­ν•΄μ£ΌλŠ”λ°, λ‹€μŒ λͺ©λ‘μ— λ‚˜μ˜¨ μ‰¬μš΄ μ „λ¬Έμš©μ–΄ λ²ˆμ—­ μ˜ˆμ‹œλ₯Ό μ°Έκ³ ν•΄μ„œ λ²ˆμ—­μ„ ν•΄μ€˜: '{recommendations}' μ‚¬μš©ν•˜μ§€ μ•Šμ€ μš©μ–΄λ“€μ€ λ¬΄μ‹œν•΄λ„ 돼. μΆ”κ°€ μ„€λͺ… 없이 λ¬Έμž₯만 λ²ˆμ—­ν•΄. μ‚¬μš©λœ 원어λ₯Ό μš©μ–΄ λ°”λ‘œ 뒀에 κ΄„ν˜Έ []에 λ„£μ–΄μ„œ 따라 λΆ™μ—¬μ€˜."
114
  ),
115
  ]
116
+ refined_translation = llm.invoke(messages)
117
  logger.info(refined_translation)
118
 
119
  retries = 0
 
128
  ),
129
  ]
130
  try:
131
+ refined_translation = llm.invoke(messages)
132
  except Exception as e:
133
  logger.error(e)
134
  break