-
Notifications
You must be signed in to change notification settings - Fork 174
/
Copy pathtranslate.py
40 lines (28 loc) · 980 Bytes
/
translate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""This module contains a LangChain application to translate English into French
This module requies the following environment variable:
* LLM_ENDPOINT, the model deployment endpoint for LLM.
"""
import os
import ads
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
from ads.llm import ChatOCIModelDeploymentVLLM
ads.set_auth(auth="resource_principal")
llm = ChatOCIModelDeploymentVLLM(
model="odsc-llm",
endpoint=os.environ["LLM_ENDPOINT"],
# Optionally you can specify additional keyword arguments for the model, e.g. temperature.
temperature=0.1,
)
prompt = ChatPromptTemplate.from_messages(
[
(
"human",
"You are a helpful assistant to translate English into French. Response only the translation.\n"
"{input}",
),
]
)
chain = prompt | llm | StrOutputParser()
def invoke(message):
return chain.invoke({"input": message})