Skip to content

Commit

Permalink
v0.12
Browse files Browse the repository at this point in the history
  • Loading branch information
yeokm1 committed May 10, 2023
1 parent cdb19ce commit 5ab69aa
Show file tree
Hide file tree
Showing 16 changed files with 253 additions and 35 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Change Log
* v0.12 (10 May 2023):
* * (New feature) Ability to read using SmoothTalker by Firstbyte and Creative Text-to-Speech Reader
* * Word wrap function to avoid breaking up words at the end of line
* * Consolidate some of the parsed arguments
* v0.11 (30 Apr 2023):
* * Support for Hugging Face API
* * (New feature) Support for Hugging Face API
* v0.10 (30 Apr 2023):
* * Can customise path to configuration file
* v0.9 (27 Apr 2023):
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Application binary can be found in the `releases` directory or Github Releases s
* Packet Driver
* MTCP Config Environment variable `MTCPCFG`
* MTCP Config file configured by DHCP
* Text-to-speech feature requires the use of a Sound Blaster-compatible sound card and the `BLASTER` variable such as `SET BLASTER=A220 I5 T1 D1 T4` to be set.

5. Just launch `doschgpt.exe` in your machine and fire away. Press the ESC key to quit the application. You may use the following optional command line arguments.

Expand All @@ -49,6 +50,7 @@ Application binary can be found in the `releases` directory or Github Releases s
* `-drt`: Display the timestamp of the latest request/reply
* `-cp737`: Supports Greek [Code Page 737](https://en.wikipedia.org/wiki/Code_page_737). Ensure code page is loaded before starting the program.
* `-fhistory.txt`: Append conversation history to new/existing text file. File will also include debug messages if specified. Replace `history.txt` with any other filepath you desire. There is no space between the `-f` and the filepath.
* `-sbtts`: Able to read server reply using a text-to-speech driver used by Dr. Sbaitso.

Example usage:

Expand Down Expand Up @@ -147,3 +149,8 @@ curl https://api-inference.huggingface.co/models/facebook/blenderbot-400M-distil
# Changelog

Go to [CHANGELOG.md](CHANGELOG.md).

# Third party sources

1. [MTCP TCP stack by Michal Brutman](http://brutmanlabs.org/mTCP/)
2. [Text to speech from SmoothTalker by Firstbyte and Creative Text-to-Speech Reader](https://winworldpc.com/product/dr-sbaitso/2x)
2 changes: 1 addition & 1 deletion api-data/reply.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"id":"chatcmpl-73JoAf0rMfuEnKjayuVg0BBqWb18O","object":"chat.completion","created":1681025482,"model":"gpt-3.5-turbo-0301","usage":{"prompt_tokens":23,"completion_tokens":234,"total_tokens":257},"choices":[{"message":{"role":"assistant","content":"As an AI language model, I cannot display characters in a visual format as they are shown in a computer. However, I can list the characters included in the Greek Code Page 737:Α,Β,Γ,Δ,Ε,Ζ,Η,Θ,Ι,Κ,Λ,Μ,Ν,Ξ,Ο,Π,Ρ,Σ,Τ,Υ,Φ,Χ,Ψ,Ω,α,β,γ,δ,ε,ζ,η,θ,ι,κ,λ,μ,ν,ξ,ο,π,ρ,σ,ς,τ,υ,φ,χ,ψ,░,▒,▓,│,┤,╡,╢,╖,╕,╣,║,╗,╝,╜,╛,┐,└,┴,┬,├,─,┼,╞,╟,╚,╔,╩,╦,╠,═,╬,╧,╨,╤,╥,╙,╘,╒,╓,╫,╪,┘,┌,█,▄,▌,▐,▀,ω,ά,έ,ή,ϊ,ί,ό,ύ,ϋ,ώ,Ά,Έ,Ή,Ί,Ό,Ύ,Ώ,±,≥,≤,Ϊ,Ϋ,÷,≈,°,∙,·,√,ⁿ,²,■"},"finish_reason":"stop","index":0}]}
{"id":"chatcmpl-XXXXX","object":"chat.completion","created":1679326062,"model":"gpt-3.5-turbo-0301","usage":{"prompt_tokens":13,"completion_tokens":114,"total_tokens":127},"choices":[{"message":{"role":"assistant","content":"MS-DOS (Microsoft Disk Operating System) is a command-line operating system developed by Microsoft Corporation. It was first released in 1981 and was widely used in personal computers until the mid-1990s. MS-DOS is known for its command-line interface, which requires users to type in specific commands to execute tasks. It was also the predecessor to modern graphical user interface (GUI) operating systems, such as Windows. MS-DOS is no longer in common use today but is still used in some embedded systems and as a boot disk for troubleshooting purposes."},"finish_reason":"stop","index":0}]}
2 changes: 1 addition & 1 deletion doschgpt-code/MAKEFILE
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ compile_options += -i=$(tcp_h_dir) -i=$(common_h_dir)


tcpobjs = packet.obj arp.obj eth.obj ip.obj tcp.obj tcpsockm.obj udp.obj utils.obj dns.obj timer.obj ipasm.obj trace.obj
objs = doschgpt.obj network.obj utf2cp.obj utfcp437.obj utfcp737.obj textio.obj
objs = doschgpt.obj network.obj utf2cp.obj utfcp437.obj utfcp737.obj textio.obj sound.obj

all : clean doschgpt.exe

Expand Down
104 changes: 80 additions & 24 deletions doschgpt-code/doschgpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@
#include "network.h"
#include "utf2cp.h"
#include "textio.h"
#include "sound.h"

#define VERSION "0.11"
#define VERSION "0.12"

#define DOS_CHATGPT_WELCOME_MSG "Welcome to DOS ChatGPT client"
#define DOS_HUGGING_FACE_WELCOME_MSG "Welcome to DOS Hugging Face client"

#define DOS_CHATGPT_WELCOME_SND "Welcome to dos Chat G P T client"
#define DOS_HUGGING_FACE_WELCOME_SND "Welcome to dos Hugging Face client"

#define GOODBYE_SND "Good bye!"

// User configuration
#define CONFIG_FILENAME_DEFAULT "doschgpt.ini"
Expand All @@ -17,6 +26,8 @@
#define CONV_HISTORY_PATH_SIZE 256
#define CONFIG_PATH_SIZE 256

#define MESSAGE_SIZE 5000

char config_apikey[API_KEY_LENGTH_MAX];
char config_model[MODEL_LENGTH_MAX];
float config_req_temperature;
Expand All @@ -34,6 +45,7 @@ bool debug_showTimeStamp = false;
int codePageInUse = CODE_PAGE_437;
bool convHistoryGiven = false;
char convHistoryPath[CONV_HISTORY_PATH_SIZE];
bool sound_blaster_tts = false;

bool configPathGiven = false;
char configPath[CONFIG_PATH_SIZE];
Expand All @@ -47,17 +59,31 @@ char * messageToSendToNet;
#define SIZE_MESSAGE_IN_BUFFER 1600
char * messageInBuffer;

#define REPLY_DISPLAY_SIZE 5000
char * replyDisplayBuffer = NULL;
int replyDisplayPos = 0;

volatile bool inProgress = true;

// Called when ending the app
void endFunction(){
free(messageToSendToNet);
free(messageInBuffer);
free(replyDisplayBuffer);
network_stop();

io_close_history_file();

printf("Ended DOS ChatGPT/Hugging Face client\n");
if(sound_blaster_tts){
sbtts_read_str(GOODBYE_SND, strlen(GOODBYE_SND), true);
sbtts_end();
}

if(huggingFace){
printf("Ended DOS Hugging Face client\n");
} else {
printf("Ended DOS ChatGPT client\n");
}
}

// When network received a Break
Expand Down Expand Up @@ -175,6 +201,8 @@ int main(int argc, char * argv[]){
memcpy(configPath, arg + 2, strlen(arg) - 2);
} else if(strstr(arg, "-hf") && strlen(arg) == 3){
huggingFace = true;
} else if(strstr(arg, "-sbtts") && strlen(arg) == 6){
sound_blaster_tts = true;
}
}

Expand All @@ -189,18 +217,11 @@ int main(int argc, char * argv[]){
if(configFileOpenStatus){

printf("API/token key contains %d characters\n", strlen(config_apikey));
printf("Model: %s\n", config_model);
printf("Request temperature: %0.1f\n", config_req_temperature);
printf("Proxy hostname: %s\n", config_proxy_hostname);
printf("Proxy port: %d\n", config_proxy_port);
printf("Outgoing start port: %u\n", config_outgoing_start_port);
printf("Outgoing end port: %u\n", config_outgoing_end_port);
printf("Socket connect timeout: %u ms\n", config_socketConnectTimeout);
printf("Socket response timeout: %u ms\n", config_socketResponseTimeout);
printf("\n");
printf("Show request info -dri: %d\n", debug_showRequestInfo);
printf("Show raw reply -drr: %d\n", debug_showRawReply);
printf("Show timestamps -drt: %d\n", debug_showTimeStamp);
printf("Proxy hostname,port: %s:%d\n", config_proxy_hostname, config_proxy_port);
printf("Outgoing start port: %u, end port: %u\n", config_outgoing_start_port, config_outgoing_end_port);
printf("Socket connect timeout: %u ms, response timeout: %u ms\n", config_socketConnectTimeout, config_socketResponseTimeout);
printf("Show request info -dri: %d, raw reply -drr: %d, timestamps -drt: %d\n", debug_showRequestInfo, debug_showRawReply, debug_showTimeStamp);
printf("Code page -cpXXX: %d\n", codePageInUse);
printf("Config Path -cX: %s\n", configPathGiven ? configPath : CONFIG_FILENAME_DEFAULT);

Expand All @@ -210,6 +231,11 @@ int main(int argc, char * argv[]){
printf("Conversation history path -fX: Not specified\n");
}

if(sound_blaster_tts == false){
printf("Sound Blaster TTS -sbtts: %d\n", sound_blaster_tts);
}


} else {
printf("Cannot open %s config file containing:\nAPI/Token key\nModel\nRequest Temperature\nProxy hostname\nProxy port\nOutgoing start port\nOutgoing end port\nSocket connect timeout (ms)\nSocket response timeout (ms)\n", configPathGiven ? configPath : CONFIG_FILENAME_DEFAULT);
return -2;
Expand Down Expand Up @@ -245,13 +271,37 @@ int main(int argc, char * argv[]){
return -1;
}

replyDisplayBuffer = (char *) calloc (REPLY_DISPLAY_SIZE, sizeof(char));

if(replyDisplayBuffer == NULL){
printf("Cannot allocate memory for message Display\n");
free(messageToSendToNet);
free(messageInBuffer);
network_stop();
return -1;
}

if(sound_blaster_tts){
sbtts_init();
}

if(sound_blaster_tts){

if(huggingFace){
sbtts_read_str(DOS_HUGGING_FACE_WELCOME_SND, strlen(DOS_HUGGING_FACE_WELCOME_SND), false);
} else {
sbtts_read_str(DOS_CHATGPT_WELCOME_SND, strlen(DOS_CHATGPT_WELCOME_SND), false);
}
}

if(huggingFace){
printf("\nUsing Hugging Face (%s). Press ESC to quit.\n", config_model);
printf("\n%s (%s). Press ESC to quit.\n", DOS_HUGGING_FACE_WELCOME_MSG, config_model);
} else {
printf("\nUsing ChatGPT (%s). Press ESC to quit.\n", config_model);
printf("\n%s (%s). Press ESC to quit.\n", DOS_CHATGPT_WELCOME_MSG, config_model);
}



io_str_newline("Me:");

int currentMessagePos = 0;
Expand Down Expand Up @@ -294,7 +344,6 @@ int main(int argc, char * argv[]){
network_get_chatgpt_completion(config_proxy_hostname, config_proxy_port, config_apikey, config_model, messageToSendToNet, config_req_temperature, &output);
}


if(output.error == COMPLETION_OUTPUT_ERROR_OK){

if(huggingFace){
Expand All @@ -303,6 +352,9 @@ int main(int argc, char * argv[]){
io_str_newline("\nChatGPT:");
}

memset(replyDisplayBuffer, 0, REPLY_DISPLAY_SIZE);
replyDisplayPos = 0;

//To scan for the special format to convert to formatted text
for(int i = 0; i < output.contentLength; i++){
char currentChar = output.content[i];
Expand All @@ -311,15 +363,15 @@ int main(int argc, char * argv[]){

//Given \n print the newline then advance 2 steps
if(currentChar == '\\' && nextChar == 'n'){
io_char('\n');
replyDisplayBuffer[replyDisplayPos++] = '\n';
i++;
// Given " print the " then advance 2 steps
} else if(currentChar == '\\' && nextChar == '\"'){
io_char('\"');
replyDisplayBuffer[replyDisplayPos++] = '\"';
i++;
// Given \ print the \ then advance 2 steps
} else if(currentChar == '\\' && nextChar == '\\'){
io_char('\\');
replyDisplayBuffer[replyDisplayPos++] = '\\';
i++;
} else {

Expand All @@ -329,18 +381,22 @@ int main(int argc, char * argv[]){
unsigned char characterToPrint = conversionResult.character;
int numCharactersToAdvance = conversionResult.charactersUsed - 1;

io_char(characterToPrint);
replyDisplayBuffer[replyDisplayPos++] = characterToPrint;
i += numCharactersToAdvance;

}
}
io_char('\n');

io_str_newline(replyDisplayBuffer);

if(debug_showRequestInfo){
io_request_info(output.outPort, output.prompt_tokens, output.completion_tokens);
}


if(sound_blaster_tts){
sbtts_read_str(replyDisplayBuffer, replyDisplayPos, true);
}

} else if(output.error == COMPLETION_OUTPUT_ERROR_CHATGPT){
io_char('\n');
io_server_error(output.content, output.contentLength);
Expand Down Expand Up @@ -398,4 +454,4 @@ int main(int argc, char * argv[]){

endFunction();
return 0;
}
}
71 changes: 71 additions & 0 deletions doschgpt-code/sound.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include <stdio.h>
#include <stdlib.h>

#define READ_STR_FORMAT "read %.*s"
#define READ_SIZE_COMMAND 120

#define MAX_TO_READ 100

char commandToRead[READ_SIZE_COMMAND];

int sbtts_run_command(char * command, bool redirectStdout){

if(redirectStdout){
// Send stdout to nul
freopen("nul", "r", stdout);
}

int returnCode = system(command);

if(redirectStdout){
fflush(stdout);

//Restore the stdout
freopen("con", "a", stdout);
}

return returnCode;

}

void sbtts_init(){
sbtts_run_command("SBTALKER /dBLASTER", false);
}

void sbtts_end(){
sbtts_run_command("REMOVE", false);
}

void sbtts_read_this_phrase(char * phrase, int length, bool redirectStdout){
snprintf(commandToRead, READ_SIZE_COMMAND, READ_STR_FORMAT, length, phrase);
sbtts_run_command(commandToRead, redirectStdout);
}

void sbtts_read_str(char * str_to_read, int length, bool redirectStdout){

int currentStartPointer = 0;

if(length < MAX_TO_READ){
sbtts_read_this_phrase(str_to_read, length, redirectStdout);
} else {
//Look for first break
for(int i = 0; i < length; i++){
char currentChar = str_to_read[i];
int currentLength = i - currentStartPointer;

// Split along the punctuation
if('!' <= currentChar && currentChar <= '/'
|| ':' <= currentChar && currentChar <= '@'
|| '[' <= currentChar && currentChar <= '`'
|| '{' <= currentChar && currentChar <= '~'
|| currentLength > MAX_TO_READ){

//printf("start %d length %d stop at %c\n", currentStartPointer, i - currentStartPointer, currentChar);
sbtts_read_this_phrase(str_to_read + currentStartPointer, i - currentStartPointer, redirectStdout);
currentStartPointer = i;
}
}
}


}
3 changes: 3 additions & 0 deletions doschgpt-code/sound.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
void sbtts_init();
void sbtts_end();
void sbtts_read_str(char * str_to_read, int length, bool redirectStdout);
Loading

0 comments on commit 5ab69aa

Please sign in to comment.