Heres a chatGPT Talk bot script, use chatGPT from within Nextcloud Talk

#!/bin/bash

#Vars
api_key="your openai key"
today=$(date +%d-%m-%Y)
memory=$(cat /var/www/response.json)

#Prompt
prompt="I am an AI language model"

#Get the talk message and format
message=$(echo "$1" | tr -d '\n' | sed -r 's/[^a-zA-Z0-9 ]+//g')

#If message is restart / empty the response.json file
if [[ "$message" == "restart" ]]; then
    echo -n "" > /var/www/response.json
    echo "Memory wiped $(date +"%Y-%m-%d %H:%M:%S")"
    exit
fi

#Get the response from ChatGPT
response=$(curl https://api.openai.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $(echo "$api_key")" \
  -d "{
  \"model\": \"gpt-3.5-turbo\",
\"messages\": [
                $(echo "$memory")
                {\"role\": \"user\", \"content\": \"$prompt $message\"}]
}"
)

#save messages in the response.json file "Memory"
user="{\"role\": \"user\", \"content\": \"$message\"},"
assistant=$(echo "$response" | jq -r '.choices[0].message' | sed 's/}$/},/')
echo $user >> /var/www/response.json
echo $assistant >> /var/www/response.json

#Check for errors
if [ $? -ne 0 ]; then
    echo "Error: Failed to call the OpenAI API"
    exit 1
fi

http_status=$(echo $response | jq -r '.http_status')
if [ $http_status -ne 200 ]; then
    echo "Error: API returned HTTP status code $http_status"
    echo "Error details: $response"
    exit 1
fi

#Get the response text from the json data
text==$(echo "$response" | jq -r '.choices[0].message.content' | sed 's/}$/},/')
#Output the question and answer
printf "Question: $message\n\n"
printf "Answer: $text"
5 Likes

gpt-3.5-turbo $0.002 / 1K tokens :wink:

a nice example of an implementation, both from ChatGPT itself as from the Talk Commands perspective… :+1:

Thank you for this nice script. But i have a problem. Maybe with jq, my answer is only “null” ?

wow so cool
can i ask where add this please ?
thx

Hi there

I’m looking to translate my mp3 recorded from Nextcloud Talk into a markdown note.

When we look at the OpenAi option, it seems already possible, but I can’t figure how.

Is this you are taking about here ?
Is someone could point me where I could find more info a out what I’m looking for?

NOTE: I’m well aware during the launch of Nextcloud 4 they prensent that feature and it was through Replicate, but I believe specially if we look closely at the option shown in my screenshot, it is possible with OpenAi