Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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;
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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
The question appears to provide a block of C code for a Unity application designed to interact with the OpenAI API specifically mimicking a chat inter...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started