using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;
using System.Threading.Tasks;
using OpenAI;
namespace OpenAI
public class ChatGPT : MonoBehaviour
SerializeField private InputField inputField;
SerializeField private Button button;
SerializeField private ScrollRect scroll;
SerializeField private RectTransform sent;
SerializeField private RectTransform received;
private float height;
private OpenAIApi openai;
private string apiKey skprojNalBPSBWHIWpPWGlbElTBlbkFJZYwEGKEWNQijyAmFkTa"; API anahtarnz buraya yazn
private List messages new List;
private string prompt "you're a python teaching assistant. you have mastered the rules of python.You will answer the questions asked to you clearly and clearly according to the oython rules.";
private void Start
openai new OpenAIApiapiKey;
button.onClick.AddListenerSendReply;
private void AppendMessageChatMessage message
scroll.content.SetSizeWithCurrentAnchorsRectTransformAxis.Vertical, ;
var item InstantiatemessageRole "user" sent : received, scroll.content;
item.GetChildGetChildGetComponenttext message.Content;
item.anchoredPosition new Vectorheight;
LayoutRebuilder.ForceRebuildLayoutImmediateitem;
height item.sizeDelta.y;
scroll.content.SetSizeWithCurrentAnchorsRectTransformAxis.Vertical, height;
scroll.verticalNormalizedPosition ;
private async void SendReply
var newMessage new ChatMessage
Role "user",
Content inputField.text
;
AppendMessagenewMessage;
if messagesCount newMessage.Content prompt
inputField.text;
messages.AddnewMessage;
button.enabled false;
inputField.text ;
inputField.enabled false;
Dosya aramas iin API istei oluturma
var fileSearchRequest new FileSearchRequest
Model gptturbo",
Query "search query", Arama sorgusu buraya yazlmal
MaxExamples En fazla karnek alnacan belirtin
;
var fileSearchResponse await openai.FileSearchfileSearchRequest;
Dosya arama sonularn ileme ve sohbet akna ekleyerek gsterme
foreach var result in fileSearchResponse.Data
var fileSearchMessage new ChatMessage
Role "assistant",
Content result.Text
;
AppendMessagefileSearchMessage;
button.enabled true;
inputField.enabled true;
FileSearchRequest CS