diff --git a/lastConvo.txt b/lastConvo.txt new file mode 100644 index 0000000..d793a45 --- /dev/null +++ b/lastConvo.txt @@ -0,0 +1 @@ +[ {"role": "system", "content": "You are ChatGPT, an AI that assists with conversations."} ] diff --git a/openAI.v2 b/openAI.v2 new file mode 100755 index 0000000..111d5b9 --- /dev/null +++ b/openAI.v2 @@ -0,0 +1,44 @@ +#!/bin/bash + +OPENAI_API_KEY=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 +ORG_ID=org-JbtjrxWLQ3WNLtcNGXfQGp49 +PROJECT_ID=proj_pCrxzr6NUI5WkiqMF5JNp2Ou + +let conversation_history=$(echo "$conversation_history" | jq --arg content "$user_input" '. + [{"role": "user", "content": $content}]') + + +function exit_func() { + echo $conversation_history > lastConvo.txt + exit 0 +} + +trap exit_func SIGINT + +conversation_history='[ + {"role": "system", "content": "You are ChatGPT, an AI that assists with conversations."} +]' + +while true; do + # Read user input + read -p "You: " user_input + + # Add user message to the conversation history + + # Make the API request with the updated conversation history + response=$(curl -s https://api.openai.com/v1/chat/completions \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + -d '{ + "model": "gpt-4o", + "messages": '"$conversation_history"' + }') + + # Extract the assistant's response + assistant_reply=$(echo "$response" | jq -r '.choices[0].message.content') + + # Output the assistant's reply + echo "ChatGPT: $assistant_reply" + + # Add assistant response to the conversation history + conversation_history=$(echo "$conversation_history" | jq --arg content "$assistant_reply" '. + [{"role": "assistant", "content": $content}]') +done