2024/03 21

[GPT] PipelinePromptTemplate

여러개의 prompt를 하나로 합쳐주는 기능 prompt를 재사용하는데 유용함 pipeline prompt 는 크게 두부분으로 구성 Final prompt: 최종 프롬프트 반환 Pipeline prompts: 문자열 이름과 프롬프트 템플릿으로 구성된 튜플 리스트 각 prompt template은 이미 format이 완료된 상태이며 동일 변수명으로 prompt template 에 전달된다. [결과값] "You are impersonating Elon Musk.\n\nHere's an example of an interaction:\n\nQ: What's your favorite car?\nA: Tesla\n\nNow, do this for real!\n\nQ: What's your favorite soci..

python 2024.03.28

[GPT] LengthBasedExampleSelector

LengthBasedExampleSelector 텍스트 길이를 기준으로 FewShotPromptTemplate 사용시 제시되는 example 들 중에 원하는 example을 선택할수 있음 [결과] 'Human: What do you know about France?\nAI: \n Here is what I know:\n Capital: Paris\n Language: French\n Food: Wine and Cheese\n Currency: Euro\n \n\nHuman: What do you know about Italy?\nAI: \n I know this:\n Capital: Rome\n Language: Italian\n Food: Pizza and Pasta\n Currency: Euro\n ..

python 2024.03.28

[GPT] Few-shot examples for chat models

[결과] AIMessageChunk(content='A triangle does not have a square. The square of a number is the result of multiplying the number by itself.') 템플릿의 기본 구성 요소는 다음과 같습니다. - examples: 최종 프롬프트에 포함할 사전 예제 목록입니다. - example_prompt: format_messages 메서드를 통해 각 예제를 하나 이상의 메시지로 변환합니다. 일반적인 예는 각 예를 하나의 인간 메시지와 하나의 AI 메시지 응답으로 변환하거나 인간 메시지와 함수 호출 메시지로 변환하는 것입니다.

python 2024.03.27

[GPT] FewShotPromptTemplate

[결과] AI: I know this: Capital: Ankara Language: Turkish Food: Kebab and Baklava Currency: Turkish Lira AIMessageChunk(content='AI:\n I know this:\n Capital: Ankara\n Language: Turkish\n Food: Kebab and Baklava\n Currency: Turkish Lira') FewShotPromptTemplate은 GPT-3나 GPT-4 같은 모델에 예제를 제공하고 예제를 기반으로 더 나은 응답을 출력할수 있도록 함 prompt = FewShotPromptTemplate( example_prompt=example_prompt, // 예제 프롬프트 exampl..

python 2024.03.27

[GPT] OutputParser and LCEL

[결과값] ['mercury', 'venus', 'earth', 'mars', 'jupiter', 'saturn', 'uranus', 'neptune'] BaseOutputParser LLM 호출의 출력을 구문 분석하는 기본 클래스 parse 메서드는 추상 메서드임 parse를 하기위한 기본 메서드 CommaOutputParser(BaseOutputParser) CommaOutputParser 클레스에 BaseOutputParser 클래스를 상속시킴 위의 코드를 아래처럼 LCEL(LangChain expression language)형태로 변경할 수 있음LCEL은 다양한 template 와 LLM 호출, response를 사용하게 해줌 [결과값] ['pikachu', 'charmander', 'bulba..

python 2024.03.26

[GPT] Prompt Templates

[결과값] '멕시코와 태국 사이의 직선거리는 약 16,000km 정도입니다. 그러나 실제로 이동할 때에는 항공편을 이용해야 하며, 이에 따라 실제 이동 거리는 더 길어질 수 있습니다.' PromptTemplate 언어 모델에 대한 프롬프트를 생성하기 위해 미리 정의된 방법 문자열 템플릿으로 구성되어 있으며, 프롬프트 생성시 특정 변수를 파라미터로 받을수 있도록 되어 있음 [결과값] AIMessage(content='Γεια σας! Η απόσταση μεταξύ του Μεξικού και της Ταϊλάνδης είναι περίπου 16.000 χιλιόμετρα. Το όνομά μου είναι Σωκράτης. Πώς μπορώ να βοηθήσω;') ChatPromptTemplate c..

python 2024.03.26

[GPT] predict_message

[결과값] AIMessage(content='멕시코와 태국 사이의 거리는 대략 16,000km 정도 되요. 제 이름은 비밀이에요. 어떤 다른 질문이 있나요?') Schema langchain의 input과 output이 될 수 있으며 가장 기본적인 입출력 형태 ChatMessages : 사용자와 모델이 서로 상호 작용하는 형태입니다. 아래와 같이 총 3가지로 이루어져 있습니다. SystemChatMessage : 모델에게 사람이 지시하는 메시지 HumanChatMessage : 사람이 입력하는 메시지 AIChatMessage : AI의 출력 메시지 예를들어 SystemMessage 의 구조를 보면 아래와 같다. class SystemMessage( *, content: str | List[str | Di..

python 2024.03.26

[GPT] LLMs 와 chat Models

[결과값] ('\n\nThere are eight planets in our solar system: Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, and Neptune.', 'There are 8 planets in our solar system: Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, and Neptune.') OpenAI 는 OpenAI의 Large Language Model을 의미하며 매교모의 데이터를 기반으로 학습된 언어 모델 ChatOpenAI 는 대화형 모델이며 주로 대화형 인터페이스를 위해 설계된 모델임 예전에는 llm = OpenAI() 형태로 코드 작성시 text-davinci-0..

python 2024.03.26