Question: using UnityEngine; using UnityEngine.UI; using System.Collections.Generic; using System.Threading.Tasks; using OpenAI; namespace OpenAl { public class ChatGPT : MonoBehaviour { [ SerializeField ] private InputField inputField;
using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;
using System.Threading.Tasks;
using OpenAI;
namespace OpenAl
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
sk
proj
NalBPSBWHIWpPWGIbEl
T
BIbkFJZ
w
EGKEWNQijyAmFkTa";
Your API key here
private List messages
new List
;
private string prompt
youre 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 python rules.";
private void Start
openai
new OpenAIApi
apiKey
;
button.onClick.AddListener
SendReply
;
private void AppendMessage
ChatMessage message
scroll.content.SetSizeWithCurrentAnchors
RectTransform
Axis.Vertical,
;
var item
Instantiate
message
Role
user
sent : received, scroll.content
;
item.GetChild
GetChild
GetComponent
text
messageContent;
item.anchoredPosition
new Vector
height
;
LayoutRebuilder.ForceRebuildLayoutImmediate
item
;
height
itemsizeDelta.y;
scroll.content.SetSizeWithCurrentAnchors
RectTransform
Axis.Vertical, height
;
scroll.verticalNormalizedPosition
;
private async void SendReply
var newMessage
new ChatMessage
Role
user Content
inputFieldtext
;
AppendMessage
newMessage
;
if
messages
Count
newMessage.Content
prompt
inputFieldtext;
messages.Add
newMessage
;
button.enabled
false;
inputField.text
;
inputField.enabled
false;
Create API request for file search
var fileSearchRequest
new FileSearchRequest
Model
gpt
turbo",
Query
search query",
Set your search query here
MaxExamples
Set maximum number of examples to retrieve
;
var fileSearchResponse
await openai.FileSearch
fileSearchRequest
;
Process file search results and display in chat flow
foreach
var result in fileSearchResponse.Data
var fileSearchMessage
new ChatMessage
Role
assistant Content
resultText
;
AppendMessage
fileSearchMessage
;
button.enabled
true;
inputField.enabled
true;
i want to write the code I threw at the beginning like the code I threw at the end, will you make the necessary arrangementsusing UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;
using System.IO;
using System.Collections;
using OpenAI;
public class FileManager : MonoBehaviour
public InputField inputField;
public Text outputText;
private string apiKey "yourapikeyhere"; OpenAI API anahtarnz buraya ekleyin
private OpenAIApi openai;
void Start
openai new OpenAIApiapiKey;
public async void LoadAndAnswerQuestions
string filePath Path.CombineApplicationpersistentDataPath, "savedFile.txt;
Dosya var m kontrol et
if FileExistsfilePath
Dosyay oku
string loadedText File.ReadAllTextfilePath;
Okunan metni ekrana yazdr
outputText.text loadedText;
OpenAI API'si ile metni analiz edip sorular yantla
var completionResponse await openai.CreateCompletionnew CreateCompletionRequest
Model "textdavinci Kullanmak istediiniz modeli sein
Prompt loadedText,
MaxTokens
;
Yantlar al ve ekrana yazdr
foreach var choice in completionResponse.Choices
outputText.text
choice.Text;
Debug.LogFile loaded from: filePath;
else
Debug.LogWarningFile not found at path: filePath;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
