Skip to content

Commit

Permalink
Fall back to gpt-3.5 if gpt-4 isn't available
Browse files Browse the repository at this point in the history
  • Loading branch information
kercre123 committed Apr 7, 2024
1 parent 29e12a8 commit ce39281
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
4 changes: 4 additions & 0 deletions chipper/pkg/wirepod/config-ws/webserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ func apiHandler(w http.ResponseWriter, r *http.Request) {
vars.APIConfig.Knowledge.Model = kgModel
vars.APIConfig.Knowledge.ID = kgAPIID
}
if kgModel == "" && kgProvider == "together" {
logger.Println("Together model wasn't provided, using default meta-llama/Llama-2-70b-chat-hf")
kgModel = "meta-llama/Llama-2-70b-chat-hf"
}
if kgProvider == "openai" || kgProvider == "together" {
if strings.TrimSpace(r.FormValue("openai_prompt")) != "" {
vars.APIConfig.Knowledge.OpenAIPrompt = r.FormValue("openai_prompt")
Expand Down
26 changes: 18 additions & 8 deletions chipper/pkg/wirepod/ttr/kgsim.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func StreamingKGSim(req interface{}, esn string, transcribedText string) (string
} else {
robName = "Vector"
}
defaultPrompt := "You are a helpful robot called " + robName + ". You will be given a question asked by a user and you must provide the best answer you can. It may not be punctuated or spelled correctly as the STT model is small. The answer will be put through TTS, so it should be a speakable string. Keep the answer concise yet informative."
defaultPrompt := "You are a helpful robot called " + robName + ". The prompt may not be punctuated or spelled correctly as the STT model is small. The answer will be put through TTS, so it should be a speakable string. Keep the answer concise yet informative."

var nChat []openai.ChatCompletionMessage

Expand Down Expand Up @@ -118,16 +118,26 @@ func StreamingKGSim(req interface{}, esn string, transcribedText string) (string
Stream: true,
}
if vars.APIConfig.Knowledge.Provider == "openai" {
logger.Println("Using " + openai.GPT4Turbo1106)
aireq.Model = openai.GPT4Turbo1106
logger.Println("Using " + aireq.Model)
} else {
logger.Println("Using " + vars.APIConfig.Knowledge.Model)
aireq.Model = vars.APIConfig.Knowledge.Model
}
stream, err := c.CreateChatCompletionStream(ctx, aireq)
if err != nil {
fmt.Printf("ChatCompletionStream error: %v\n", err)
return "", err
if strings.Contains(err.Error(), "does not exist") && vars.APIConfig.Knowledge.Provider == "openai" {
logger.Println("GPT-4 model cannot be accessed with this API key. You likely need to add more than $5 dollars of funds to your OpenAI account.")
aireq.Model = openai.GPT3Dot5Turbo
logger.Println("Falling back to " + aireq.Model)
stream, err = c.CreateChatCompletionStream(ctx, aireq)
if err != nil {
logger.Println("OpenAI still not returning a response even after falling back. Erroring.")
return "", err
}
} else {
return "", err
}
}
//defer stream.Close()

Expand All @@ -148,12 +158,12 @@ func StreamingKGSim(req interface{}, esn string, transcribedText string) (string
Remember(transcribedText, newStr, esn)
}
logger.LogUI("LLM response for " + esn + ": " + newStr)
fmt.Println("LLM stream finished")
logger.Println("LLM stream finished")
return
}

if err != nil {
fmt.Printf("Stream error: %v\n", err)
logger.Println("Stream error: " + err.Error())
return
}

Expand Down Expand Up @@ -255,7 +265,7 @@ func StreamingKGSim(req interface{}, esn string, transcribedText string) (string
},
},
); err != nil {
log.Println(err)
logger.Println(err)
return
}
return
Expand Down Expand Up @@ -310,7 +320,7 @@ func StreamingKGSim(req interface{}, esn string, transcribedText string) (string
break
}
}
fmt.Println(respSlice[numInResp])
logger.Println(respSlice[numInResp])
_, err := robot.Conn.SayText(
ctx,
&vectorpb.SayTextRequest{
Expand Down
2 changes: 1 addition & 1 deletion chipper/webroot/initial.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ <h3>Knowledge Graph Setup</h3>
<label for="togetherKey">Together Key:</label>
<input type="text" name="togetherKey" id="togetherKey"><br>
<label for="togetherAIPrompt">GPT Prompt (leave blank for default):</label><br>
<small><label for="togetherAIPrompt">(default: "You are a helpful robot called Vector. You will be given a question asked by a user and you must provide the best answer you can. It may not be punctuated or spelled correctly as the STT model is small. The answer will be put through TTS, so it should be a speakable string. Keep the answer concise yet informative.)</label></small>
<small><label for="togetherAIPrompt">(default: "You are a helpful robot called Vector. The prompt may not be punctuated or spelled correctly as the STT model is small. The answer will be put through TTS, so it should be a speakable string. Keep the answer concise yet informative.")</label></small>
<input type="text" name="togetherAIPrompt" id="togetherAIPrompt"><br>
<small>Would you like to enable the intent graph feature? This forwards the request to Together if the regular intent processor didn't understand what you said.</small><br>
<label for="togetherintentyes">Yes</label>
Expand Down
4 changes: 2 additions & 2 deletions chipper/webroot/setup.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ <h3>Knowledge Graph Setup</h3>
</span>
<span id="togetherInput" style="display:none">
<small>To use Together, create an account at <a href="https://www.together.xyz">together.com</a>, create a free domain, and enter the Model Name and Together Key here.</small><br>
<label for="togetherModel">Together Model Name: e.g. meta-llama/Llama-2-70b-chat-hf</label>
<label for="togetherModel">Together Model Name: (leave blank for default: meta-llama/Llama-2-70b-chat-hf)</label>
<input type="text" name="togetherModel" id="togetherModel"><br>
<label for="togetherKey">Together Key:</label>
<input type="text" name="togetherKey" id="togetherKey"><br>
Expand All @@ -93,7 +93,7 @@ <h3>Knowledge Graph Setup</h3>
<label for="openAIKey">OpenAI Key:</label>
<input type="text" name="openAIKey" id="openAIKey"><br>
<label for="openAIPrompt">GPT Prompt (leave blank for default):</label><br>
<small><label for="openAIPrompt">(default: "You are a helpful robot called Vector. You will be given a question asked by a user and you must provide the best answer you can. It may not be punctuated or spelled correctly as the STT model is small. The answer will be put through TTS, so it should be a speakable string. Keep the answer concise yet informative.)</label></small>
<small><label for="openAIPrompt">(default: "You are a helpful robot called Vector. The prompt may not be punctuated or spelled correctly as the STT model is small. The answer will be put through TTS, so it should be a speakable string. Keep the answer concise yet informative.")</label></small>
<input type="text" name="openAIPrompt" id="openAIPrompt"><br>
<small>Would you like to enable the intent graph feature? This forwards the request to OpenAI if the regular intent processor didn't understand what you said.</small><br>
<label for="intentyes">Yes</label>
Expand Down

0 comments on commit ce39281

Please sign in to comment.