LLM - Retrieval¶
Install packages
Import packages
Define knowledge base
Define tools specification
Define messages
- System message, defined once
- User messages
Get chat completion
Call the function and append its result to messages list
[{'role': 'system',
'content': 'You are a helpful assistant that answers questions from the knowledge base about our e-commerce store.'},
{'role': 'user', 'content': 'What is the return policy?'},
Message(content=None, role='assistant', tool_calls=[ChatCompletionMessageToolCall(index=0, function=Function(arguments='{"question": "What is the return policy?"}', name='search_kb'), id='call_2ed16bb9ed424be8aeb1eea38408', type='function')], function_call=None, images=[], thinking_blocks=[], provider_specific_fields=None),
{'role': 'tool',
'tool_call_id': 'call_2ed16bb9ed424be8aeb1eea38408',
'content': '"{\'records\': [{\'id\': 1, \'question\': \'What is the return policy?\', \'answer\': \'Items can be returned within 30 days of purchase with original receipt. Refunds will be processed to the original payment method within 5-7 business days.\'}, {\'id\': 2, \'question\': \'Do you ship internationally?\', \'answer\': \'Yes, we ship to over 50 countries worldwide. International shipping typically takes 7-14 business days and costs vary by destination. Please note that customs fees may apply.\'}, {\'id\': 3, \'question\': \'What payment methods do you accept?\', \'answer\': \'We accept Visa, Mastercard, American Express, PayPal, and Apple Pay. All payments are processed securely through our encrypted payment system.\'}]}"'}]
Define output structure
Supply results and call the model again