first commit
This commit is contained in:
58
openAI.bak
Executable file
58
openAI.bak
Executable file
@@ -0,0 +1,58 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
OPENAI_API_KEY=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
|
||||||
|
ORG_ID=org-JbtjrxWLQ3WNLtcNGXfQGp49
|
||||||
|
PROJECT_ID=proj_pCrxzr6NUI5WkiqMF5JNp2Ou
|
||||||
|
|
||||||
|
##curl https://api.openai.com/v1/models \
|
||||||
|
## -H "Authorization: Bearer $OPENAI_API_KEY" \
|
||||||
|
## -H "OpenAI-Organization: org-JbtjrxWLQ3WNLtcNGXfQGp49" \
|
||||||
|
## -H "OpenAI-Project: $PROJECT_ID"
|
||||||
|
|
||||||
|
#curl https://api.openai.com/v1/chat/completions \
|
||||||
|
# -H "Content-Type: application/json" \
|
||||||
|
# -H "Authorization: Bearer $OPENAI_API_KEY" \
|
||||||
|
# -d '{
|
||||||
|
# "model": "gpt-4o",
|
||||||
|
# "messages": [
|
||||||
|
# {
|
||||||
|
# "role": "system",
|
||||||
|
# "content": "You are a helpfull asistant that will stop at nothing to help the user."
|
||||||
|
# },
|
||||||
|
# {
|
||||||
|
# "role": "user",
|
||||||
|
# "content": "what kind of financial data do i have to keep?"
|
||||||
|
# }
|
||||||
|
## ]
|
||||||
|
# }'
|
||||||
|
|
||||||
|
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
|
||||||
|
conversation_history=$(echo "$conversation_history" | jq --arg content "$user_input" '. + [{"role": "user", "content": $content}]')
|
||||||
|
|
||||||
|
# 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-3.5-turbo",
|
||||||
|
"messages": '"$conversation_history"',
|
||||||
|
"max_tokens": 150
|
||||||
|
}')
|
||||||
|
|
||||||
|
# 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
|
||||||
@@ -17,7 +17,7 @@ PROJECT_ID=proj_pCrxzr6NUI5WkiqMF5JNp2Ou
|
|||||||
# "messages": [
|
# "messages": [
|
||||||
# {
|
# {
|
||||||
# "role": "system",
|
# "role": "system",
|
||||||
# "content": "You are a helpful assistant."
|
# "content": "You are a helpfull asistant that will stop at nothing to help the user."
|
||||||
# },
|
# },
|
||||||
# {
|
# {
|
||||||
# "role": "user",
|
# "role": "user",
|
||||||
@@ -42,9 +42,8 @@ while true; do
|
|||||||
-H "Authorization: Bearer $OPENAI_API_KEY" \
|
-H "Authorization: Bearer $OPENAI_API_KEY" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d '{
|
-d '{
|
||||||
"model": "gpt-3.5-turbo",
|
"model": "o1-preview",
|
||||||
"messages": '"$conversation_history"',
|
"messages": '"$conversation_history"'
|
||||||
"max_tokens": 150
|
|
||||||
}')
|
}')
|
||||||
|
|
||||||
# Extract the assistant's response
|
# Extract the assistant's response
|
||||||
@@ -55,4 +54,4 @@ while true; do
|
|||||||
|
|
||||||
# Add assistant response to the conversation history
|
# Add assistant response to the conversation history
|
||||||
conversation_history=$(echo "$conversation_history" | jq --arg content "$assistant_reply" '. + [{"role": "assistant", "content": $content}]')
|
conversation_history=$(echo "$conversation_history" | jq --arg content "$assistant_reply" '. + [{"role": "assistant", "content": $content}]')
|
||||||
done
|
done
|
||||||
|
|||||||
Reference in New Issue
Block a user