職位描述
using System;
using [login to view URL];
using [login to view URL];
using UnityEngine;
using [login to view URL];
public class GeminiService : MonoBehaviour
{
private string apiKey = "YOUR_GEMINI_API_KEY"; // أدخل مفتاح API الخاص بك هنا
private string apiUrl = "[login to view URL]:generateContent?key=";
[Serializable]
private class GeminiRequest { public Content[] contents; }
[Serializable]
private class Content { public Part[] parts; }
[Serializable]
private class Part { public string text; }
public IEnumerator SendPrompt(string userPrompt, Action callback)
{
string fullUrl = apiUrl + apiKey;
GeminiRequest requestData = new GeminiRequest
{
contents = new Content[]
{
new Content { parts = new Part[] { new Part { text = userPrompt } } }
}
};
string jsonPayload = [login to view URL](requestData);
byte[] bodyRaw = [login to view URL](jsonPayload);
using (UnityWebRequest request = new UnityWebRequest(fullUrl, "POST"))
{
[login to view URL] = new UploadHandlerRaw(bodyRaw);
[login to view URL] = new DownloadHandlerBuffer();
[login to view URL]("Content-Type", "application/json");
yield return [login to view URL]();
if ([login to view URL] == [login to view URL])
{
callback?.Invoke([login to view URL]);
}
else
{
callback?.Invoke("خطأ في الاتصال بـ Gemini: " + [login to view URL]);
}
}
}
}
---
來源:Freelancer.com | 出價次數:42 | 剩餘時間:6 日 | 專案類型:固定預算