Implementing Retrieval-Augmented Generation (RAG) on ZC Technologies' Inference Exchange (ZCX) can significantly enhance your application's ability to generate context-aware responses. This guide focuses on three minimalistic patterns that leverage the OpenAI-compatible API, ensuring seamless integration with frameworks like Llamaindex and Langchain. By following these examples, developers can quickly build RAG applications that benefit from ZCX's cost-effective pricing and powerful Qwen 2.5 models.
For a straightforward RAG implementation, the Qwen 2.5:32b model offers a balance between performance and cost. Here's a basic example using the OpenAI-compatible API:
import requests
headers = {
'Authorization': 'Bearer YOUR_ZCX_API_KEY',
'Content-Type': 'application/json'
}
payload = {
'model': 'qwen2.5:32b',
'messages': [{'role': 'user', 'content': 'What is the capital of France?'}],
'temperature': 0.7
}
response = requests.post('https://zcx.zctechnologies.org/v1/chat', headers=headers, json=payload)
print(response.json())
For more complex queries, the Qwen 2.5:72b model provides superior context understanding and response generation. This pattern demonstrates how to integrate the larger model into your RAG application:
import requests
headers = {
'Authorization': 'Bearer YOUR_ZCX_API_KEY',
'Content-Type': 'application/json'
}
payload = {
'model': 'qwen2.5:72b',
'messages': [{'role': 'user', 'content': 'Explain the theory of relativity in simple terms.'}],
'temperature': 0.5
}
response = requests.post('https://zcx.zctechnologies.org/v1/chat', headers=headers, json=payload)
print(response.json())
Integrating an external knowledge base into your RAG application can further enrich the responses. This pattern shows how to incorporate a custom knowledge base with the Qwen 2.5 models:
import requests
headers = {
'Authorization': 'Bearer YOUR_ZCX_API_KEY',
'Content-Type': 'application/json'
}
payload = {
'model': 'qwen2.5:32b',
'messages': [{'role': 'user', 'content': 'Retrieve information about the latest developments in AI ethics.'}],
'temperature': 0.6,
'knowledge_base': 'https://example.com/ai-ethics-knowledge-base'
}
response = requests.post('https://zcx.zctechnologies.org/v1/chat', headers=headers, json=payload)
print(response.json())
By following these patterns, developers can effectively implement RAG on ZCX, taking advantage of the platform's competitive pricing and powerful models. Whether you're working on a basic or advanced RAG application, ZCX offers the flexibility and performance needed to deliver high-quality results. To get started, sign up for a prepaid LLM credit line at https://zcx.zctechnologies.org#plans.