Tích hợp ngữ cảnh bên ngoài

Kỹ thuật Prompt với OpenAI API

Fouad Trad

Machine Learning Engineer

Nhu cầu về ngữ cảnh bên ngoài

  • Mô hình ngôn ngữ tiền huấn luyện nhận ra thông tin đã được học
  • Cần cung cấp thêm ngữ cảnh
  • Tăng độ chính xác và hiệu quả

Biểu tượng chatbot trên điện thoại.

Kỹ thuật Prompt với OpenAI API

Thiếu thông tin trong LLM

  • Giới hạn thời điểm kiến thức
system_prompt = "Act as a financial expert that knows about the latest trends."

user_prompt = "What are the top financial trends in 2023?"

print(get_response(system_prompt, user_prompt))
I apologize for any inconvenience, but as of my last knowledge update in 
September 2021, I don't have information about financial trends in 2023.
Kỹ thuật Prompt với OpenAI API

Thiếu thông tin trong LLM

  • Yêu cầu thông tin không công khai
system_prompt = "Act as a study buddy that helps me with my studies to succeed 
in exams."

user_prompt = "What is the name of my favorite instructor?" print(get_response(system_prompt, user_prompt))
I don't have personal information about you, including the name of your 
favorite instructor.
Kỹ thuật Prompt với OpenAI API

Cách cung cấp thông tin bổ sung?

  • Mẫu hội thoại trước đó
  • Lời nhắc hệ thống

Biểu tượng hai hộp thoại thể hiện hội thoại.

Kỹ thuật Prompt với OpenAI API

Hội thoại mẫu

  • Hướng dẫn mô hình trả lời câu hỏi cụ thể
response = client.chat.completions.create(
  model="gpt-4o-mini",
  messages=[{"role": "system",
             "content": "You are a customer service chatbot that responds to user queries in a gentle way"},

{"role": "user", "content": "What services do you offer?"},
{"role": "assistant", "content": "We provide services for web application development, mobile app development, and custom software solutions."},
{"role": "user", "content": "How many services do you have?"}])
print(response.choices[0].message.content)
We have 3 services including web application development, mobile app development, and custom software solutions.
  • Nhược điểm: có thể cần nhiều mẫu
Kỹ thuật Prompt với OpenAI API

Lời nhắc hệ thống

  • Bao gồm ngữ cảnh cần thiết cho câu trả lời của chatbot
services = "ABC Tech Solutions, a leading IT company, offers a range of services: 
application development, mobile app development, and custom software solutions."

system_prompt = f"""You are a customer service chatbot that responds to user queries in a gentle way. Some information about our services are delimited by triple backticks. ```{services}```"""
user_prompt = "How many services do you offer?" print(get_response(system_prompt, user_prompt))
We have 3 services including web application development, mobile app development, 
and custom software solutions.
Kỹ thuật Prompt với OpenAI API

Lưu ý cuối

  • Cách trước phù hợp với ngữ cảnh nhỏ
  • Ngữ cảnh lớn cần kỹ thuật tinh vi hơn

Biểu tượng cảnh báo.

Kỹ thuật Prompt với OpenAI API

Ayo berlatih!

Kỹ thuật Prompt với OpenAI API

Preparing Video For Download...