جمنائي
محول Gemini يمكّن نماذج Gemini من Google من التفاعل مع Asset Core من خلال إعلانات الوظائف، مما يعكس نفس واجهة الأدوات مثل المحولات الأخرى.
المتطلبات المسبقة
- تشغيل خدمات Asset Core
- الوصول إلى واجهة برمجة التطبيقات الخاصة بـ Google AI (Gemini)
- بايثون أو راست للتكامل
الخطوة 1 - الحصول على إعلانات الوظائف
يوفر المحول إعلانات وظائف متوافقة مع Gemini:
use assetcore_adapters::gemini::GeminiToolDefinition;
let tools = GeminiToolDefinition::all();
تتبع هذه التصريحات مخطط استدعاء الوظائف الخاص بـ Google.
الخطوة 2 - تعريف الوظائف لـ Gemini
أدوات التنسيق لواجهة برمجة التطبيقات Gemini:
إرشادات إضافية:
نبرة: رسمية سجل: تقني
السياق:
- المجال: بنية تحتية للبلوكشين
- الجمهور: مهندسو الأمان وقادة البنية التحتية
- الغرض: وثائق تقنية
- اللغة: ar
- الاتجاه: من اليمين إلى اليسار
القيود:
- استخدام لغة محايدة من حيث الجنس
- الحفاظ على أسماء العلامات التجارية
- الحفاظ على الدقة التقنية
- التأكد من أن علامات الترقيم والترقيم تبقى مناسبة من حيث الاتجاه
- الاحتفاظ بأسماء العلامات التجارية والمصطلحات دون ترجمة
الحفاظ على هذه المصطلحات بالضبط (لا تترجم): Asset Core، Asset‑Core، CSP، API، Docker، ECS، daemon، L1، L2، L3، OpenGraph، GitHub، Astro، TypeScript، JavaScript، ℤ، ℤ²، ℤ³، ℝ²، ℝ³، 0D، 1D، 2D، 3D
from google.generativeai.types import FunctionDeclaration, Tool
commit_function = FunctionDeclaration(
name="assetcore_commit",
description="Submit a transaction to Asset Core",
parameters={
"type": "object",
"properties": {
"operations": {
"type": "array",
"items": {
"type": "object",
"properties": {
"op": {"type": "string"},
"args": {"type": "object"}
},
"required": ["op", "args"]
},
"description": "List of operations to execute"
},
"idempotency_key": {
"type": "string",
"description": "Optional deduplication key"
}
},
"required": ["operations"]
}
)
health_function = FunctionDeclaration(
name="assetcore_write_health",
description="Check Asset Core write daemon health",
parameters={"type": "object", "properties": {}}
)
tools = Tool(function_declarations=[commit_function, health_function])
الخطوة 3 - تنفيذ استدعاءات الدوال
عند عودة Gemini لاستدعاء دالة، نفذها ضد Asset Core:
import httpx
import json
async def execute_function(name: str, args: dict) -> dict:
if name == "assetcore_commit":
async with httpx.AsyncClient() as client:
response = await client.post(
"http://localhost:8080/v1/commit",
json=args
)
return response.json()
elif name == "assetcore_write_health":
async with httpx.AsyncClient() as client:
response = await client.get(
"http://localhost:8080/v1/health"
)
return response.json()
else:
return {"error": f"Unknown function: {name}"}
الخطوة 4 - إكمال حلقة المحادثة
دمج مع واجهة برمجة التطبيقات Gemini:
import google.generativeai as genai
genai.configure(api_key="your-api-key")
model = genai.GenerativeModel(
"gemini-pro",
tools=[tools]
)
chat = model.start_chat()
response = chat.send_message(
"Create a container with ID 1001"
)
# Check for function calls
if response.candidates[0].content.parts[0].function_call:
fc = response.candidates[0].content.parts[0].function_call
# Execute the function
result = await execute_function(fc.name, dict(fc.args))
# Send the result back
response = chat.send_message(
genai.protos.Content(
parts=[
genai.protos.Part(
function_response=genai.protos.FunctionResponse(
name=fc.name,
response={"result": result}
)
)
]
)
)
print(response.text)
الخطوة 5 - استخدم منفذ Rust
إرشادات إضافية:
لتطبيقات Rust:
إرشادات إضافية:
use assetcore_adapters::gemini::GeminiToolExecutor;
use assetcore_adapters::http_client::DaemonClient;
let client = DaemonClient::new(
"http://localhost:8080",
"http://localhost:8081"
);
let executor = GeminiToolExecutor::new(client);
let result = executor.execute(
"assetcore_commit",
serde_json::json!({
"operations": [
{
"op": "CreateContainer",
"args": {
"container_id": 1001,
"kind": "Standard"
}
}
]
})
).await?;
استكشاف الأخطاء وإصلاحها
الوظيفة غير معروفة
تأكد من أن اسم الدالة يتطابق تمامًا. Gemini حساسة لحالة الأحرف.
حجج غير صالحة
قد يولد Gemini حججًا لا تتطابق مع المخطط. أضف التحقق قبل التنفيذ.
استدعاءات دالة متعددة
قد تطلب Gemini استدعاءات متعددة للوظائف. نفذها بالتتابع لـ Asset Core.
الخطوات التالية
- نظرة عامة على الوكلاء - الهندسة والتصميم
- MCP Integration - بديل لـ Claude
- OpenAI Tools - بديل لـ GPT