ChatOpenAI 객체 생성 옵션

  • 랭체인(langchain)의 OpenAI GPT 모델(ChatOpenAI)temperature
    • 사용할 샘플링 온도는 0과 2 사이에서 선택합니다. 0.8과 같은 높은 값은 출력을 더 무작위하게 만들고, 0.2와 같은 낮은 값은 출력을 더 집중되고 결정론적으로 만듭니다.

max_tokens

  • 채팅에서 생성할 토큰의 최대 개수

model_name

  • 적용 가능한 모델 리스트
    import openai
    

model_list = sorted([m['id'] for m in openai.Model.list()['data']])
for m in model_list:
print(m)

```python
from langchain_core.messages import HumanMessage, SystemMessage
from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(model="gpt-3.5-turbo-0125", temperature=0)

messages = [  
("system", "You are a helpful assistant that translates English to French."), 
("human", "Translate this sentence from English to French. I love programming."),  
]  

llm.invoke(messages)

ChatPromptTemplate

from langchain.prompts import ChatPromptTemplate

template = ChatPromptTemplate.from_messages([
    ("system", "You are a helpful AI bot. Your name is {name}."),
    ("human", "Hello, how are you doing?"),
    ("ai", "I'm doing well, thanks!"),
    ("human", "{user_input}"),
])

prompt_value = template.invoke(
    {
        "name": "Bob",
        "user_input": "What is your name?"
    }
)

Chaining


- Runnables를 '|'을사용해서 Chaining 할 수 있다

prompt = ChatPromptTemplate.from_messages(
    [
        (
            "system",
            "You are a helpful assistant that translates {input_language} to {output_language}.",
        ),
        ("human", "{input}"),
    ]
)

chain = prompt | llm
chain.invoke(
    {
        "input_language": "English",
        "output_language": "German",
        "input": "I love programming.",
    }
)

참고


'GPT' 카테고리의 다른 글

AI EXPO KOREA SUMMIT 참석 후 기억에 남는 이야기 정리  (0) 2024.05.07
🦜️🔗 Model I/O  (0) 2024.05.01
🦜 랭체인(LangChain)  (0) 2024.04.29
GPT 프로젝트를 위한 Python 환경설정  (0) 2024.04.29

+ Recent posts