fixed anthro
This commit is contained in:
parent
17880f1d0f
commit
fbeb1bc7d9
@ -24,7 +24,7 @@ func GeneratePlaceholderHandler(c *fiber.Ctx) error {
|
||||
// Step 1 I create a User message and send it as output with a placeholder
|
||||
// that will make a request to GenerateMultipleMessagesHandler when loading
|
||||
message := c.FormValue("message", "")
|
||||
selectedLLMIds := []string{"3cd15ca8-1433-11ef-9f22-93f2b78c78de"} // TODO Hanle in the UI
|
||||
selectedLLMIds := []string{"1e5a07c4-12fe-11ef-8da6-67d29b408c53"} // TODO Hanle in the UI
|
||||
|
||||
var selectedLLMs []LLM
|
||||
var selectedLLM LLM
|
||||
|
@ -42,7 +42,6 @@ func addAnthropicMessage(llm LLM, selected bool) edgedb.UUID {
|
||||
if err != nil {
|
||||
fmt.Println("Error:", err)
|
||||
} else if len(chatCompletion.Content) == 0 {
|
||||
fmt.Println(chatCompletion)
|
||||
fmt.Println("No response from Anthropic")
|
||||
id := insertBotMessage("No response from Anthropic", selected, llm.ID)
|
||||
return id
|
||||
@ -108,20 +107,22 @@ func TestAnthropicKey(apiKey string) bool {
|
||||
}
|
||||
|
||||
func RequestAnthropic(model string, messages []Message, maxTokens int, temperature float64) (AnthropicChatCompletionResponse, error) {
|
||||
var apiKey string
|
||||
var apiKey struct {
|
||||
Key string `edgedb:"key"`
|
||||
}
|
||||
err := edgeClient.QuerySingle(edgeCtx, `
|
||||
with
|
||||
filtered_keys := (
|
||||
select Key {
|
||||
key
|
||||
} filter .company.name = <str>$0
|
||||
)
|
||||
select filtered_keys.key limit 1
|
||||
SELECT Key {
|
||||
key
|
||||
}
|
||||
FILTER .<keys[is Setting].<setting[is User] = global currentUser and .company.name = "anthropic"
|
||||
LIMIT 1
|
||||
`, &apiKey, "anthropic")
|
||||
if err != nil {
|
||||
return AnthropicChatCompletionResponse{}, fmt.Errorf("error getting Anthropic API key: %w", err)
|
||||
}
|
||||
|
||||
fmt.Println("apiKey:", apiKey)
|
||||
|
||||
url := "https://api.anthropic.com/v1/messages"
|
||||
|
||||
requestBody := AnthropicChatCompletionRequest{
|
||||
@ -131,7 +132,7 @@ func RequestAnthropic(model string, messages []Message, maxTokens int, temperatu
|
||||
Temperature: temperature,
|
||||
}
|
||||
|
||||
fmt.Println(maxTokens)
|
||||
fmt.Println("Message2RequestMessage(messages):", Message2RequestMessage(messages))
|
||||
|
||||
jsonBody, err := json.Marshal(requestBody)
|
||||
if err != nil {
|
||||
@ -143,9 +144,9 @@ func RequestAnthropic(model string, messages []Message, maxTokens int, temperatu
|
||||
return AnthropicChatCompletionResponse{}, fmt.Errorf("error creating request: %w", err)
|
||||
}
|
||||
|
||||
req.Header.Set("x-api-key", apiKey.Key)
|
||||
req.Header.Set("content-Type", "application/json")
|
||||
req.Header.Set("anthropic-version", "2023-06-01")
|
||||
req.Header.Set("x-api-key", apiKey)
|
||||
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
|
@ -41,7 +41,6 @@ func addOpenaiMessage(llm LLM, selected bool) edgedb.UUID {
|
||||
Messages := getAllSelectedMessages()
|
||||
|
||||
chatCompletion, err := RequestOpenai(llm.Model.ModelID, Messages, float64(llm.Temperature))
|
||||
fmt.Println(chatCompletion)
|
||||
if err != nil {
|
||||
fmt.Println("Error:", err)
|
||||
} else if len(chatCompletion.Choices) == 0 {
|
||||
@ -124,8 +123,6 @@ func RequestOpenai(model string, messages []Message, temperature float64) (Opena
|
||||
return OpenaiChatCompletionResponse{}, fmt.Errorf("error getting OpenAI API key: %w", err)
|
||||
}
|
||||
|
||||
fmt.Println("Messages:", messages)
|
||||
|
||||
url := "https://api.openai.com/v1/chat/completions"
|
||||
|
||||
requestBody := OpenaiChatCompletionRequest{
|
||||
|
Loading…
x
Reference in New Issue
Block a user