QUESTION:
Please show me actual purebasic code to read a file named “input_text.txt”
then write out contents of “input_text.txt” to a file named “output_text.txt” .
ANSWER:
Sure, here’s an example program that reads input text from input_text.txt and writes it to output text to output_text.txt:
’ Open the input file in read mode
dim inpFile as new file
inpFile.open(“input_text.txt”, fmRead)
’ Open the output file in write mode
dim outFile as new file
outFile.open(“output_text.txt”, fmWrite)
’ Read each line from the input file
do until inpFile.eof()
'et the next line of input
dim line as string = inpFile.readline
'rite the line to the output file
outFile.writeline(line)
loop
’ Close the files
inpFile.close
outFile.close
THE PROBLEM:
The above is not PureBasis code ,
it is more of an outline of what needs to be done .
Am I doing something wrong ?
From your reply I gather that you have been able to use a publicly available model.
From your next problem I gather that you are looking for support with one of the lesser known languages. Have you checked first if the model you want to use has been trained on data for this language? The Starcoder models are surely great, but I wouldn’t expect it to be honest.
Either way, this is what GPT 3.5 thinks is the right answer:
; Open the input file for reading
If OpenFile(1, "input_text.txt")
; Read the entire content of the file into a string
ReadString(1, FileSize(1), FileBuffer())
; Close the input file
CloseFile(1)
Else
; Handle error if the file couldn't be opened
MessageRequester("Error", "Failed to open input_text.txt")
EndIf
; Open the output file for writing
If OpenFile(2, "output_text.txt", #PB_File_Write)
; Write the contents from FileBuffer (read from input_text.txt) to the output file
WriteString(2, FileBuffer())
; Close the output file
CloseFile(2)
Else
; Handle error if the file couldn't be opened for writing
MessageRequester("Error", "Failed to open output_text.txt for writing")
EndIf
Honestly I wouldn’t expect that any of the big models knows how to code this specific language well.
It would need a large set of training data that can be scraped from the web and maybe even some RLHF but it is not likely that anyone would spend extra cash on this specific language, unless they are building a specialized model for this language.