Skip to content

Commit

Permalink
Adding Anthropic Claude Support(initial tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
SanHacks committed Mar 26, 2024
1 parent 4e981ca commit 80e1767
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 5 deletions.
5 changes: 3 additions & 2 deletions Variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package main
// I REPEAT, DO NOT LEAK YOUR KEYS.
// NOW REPEAT WITH ME, "I WILL NOT LEAK MY TOKENS"!
const (
openKeys = "OPENAI"
speechKeys = "AZURE"
openKeys = "OPENAI"
speechKeys = "AZURE"
anthropicKeys = "ANTHROPIC"
)
53 changes: 53 additions & 0 deletions aigenRest/callAnthropic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package aigenRest

import (
"encoding/json"
"fmt"
"net/http"
"os"
"strings"
)

func CallClaude(message string) (string, error) {

url := "https://api.anthropic.com/v1/complete"
method := "POST"

payload := fmt.Sprintf(`{
"model": "claude-2.1",
"max_tokens_to_sample": 1024,
"prompt": "\n\nHuman: %s\n\nAssistant:"
}`, message)

client := &http.Client{}
req, err := http.NewRequest(method, url, strings.NewReader(payload))

if err != nil {
fmt.Println(err)
return "", err
}
req.Header.Add("x-api-key", os.Getenv("ANTHROPIC"))
req.Header.Add("anthropic-version", "2023-06-01")
req.Header.Add("content-type", "application/json")

res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return "", err
}
defer res.Body.Close()

var response map[string]interface{}
err = json.NewDecoder(res.Body).Decode(&response)
if err != nil {
fmt.Println(err)
return "", err
}

completion, ok := response["completion"].(string)
if !ok {
return "", fmt.Errorf("completion not found in response")
}

return completion, nil
}
5 changes: 3 additions & 2 deletions converseLogic.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ package main

import (
"aigen/aigenRest"
"fyne.io/fyne/v2"
"log"

"fyne.io/fyne/v2"
)

// Default logic to handle communication with GPT
func defaultCallConverseLogic(message string, tab1 *fyne.Container) {

//message = longTermMemory(message)

messageCall, err := aigenRest.MakeApiCall(message)
messageCall, err := aigenRest.CallClaude(message)
limit := 120
notificationMessage := messageCall

Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
module aigen

go 1.20
go 1.18

require (
fyne.io/fyne/v2 v2.4.1
github.com/atotto/clipboard v0.1.4
github.com/gen2brain/malgo v0.11.10
github.com/go-sql-driver/mysql v1.7.0
github.com/gordonklaus/portaudio v0.0.0-20230709114228-aafa478834f5
github.com/hajimehoshi/go-mp3 v0.3.4
github.com/mattn/go-sqlite3 v1.14.16
github.com/sashabaranov/go-openai v1.5.2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORR
github.com/gopherjs/gopherjs v0.0.0-20211219123610-ec9572f70e60/go.mod h1:cz9oNYuRUWGdHmLF2IodMLkAhcPtXeULvcBNagUrxTI=
github.com/gopherjs/gopherjs v1.17.2 h1:fQnZVsXk8uxXIStYb0N4bGk7jeyTalG/wsZjQ25dO0g=
github.com/gopherjs/gopherjs v1.17.2/go.mod h1:pRRIvn/QzFLrKfvEz3qUuEhtE/zLCWfreZ6J5gM2i+k=
github.com/gordonklaus/portaudio v0.0.0-20230709114228-aafa478834f5 h1:5AlozfqaVjGYGhms2OsdUyfdJME76E6rx5MdGpjzZpc=
github.com/gordonklaus/portaudio v0.0.0-20230709114228-aafa478834f5/go.mod h1:WY8R6YKlI2ZI3UyzFk7P6yGSuS+hFwNtEzrexRyD7Es=
github.com/goxjs/gl v0.0.0-20210104184919-e3fafc6f8f2a/go.mod h1:dy/f2gjY09hwVfIyATps4G2ai7/hLwLkc5TrPqONuXY=
github.com/goxjs/glfw v0.0.0-20191126052801-d2efb5f20838/go.mod h1:oS8P8gVOT4ywTcjV6wZlOU4GuVFQ8F5328KY3MJ79CY=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
Expand Down
1 change: 1 addition & 0 deletions openDoors.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ func setUpPlatformEnvVars() {
SetEnvironmentVariable("OPENAI", openKeys)
SetEnvironmentVariable("SPEECH_KEY", speechKeys)
SetEnvironmentVariable("OPENWEATHER", openWeatherKeys)
SetEnvironmentVariable("ANTHROPIC", anthropicKeys)
}

0 comments on commit 80e1767

Please sign in to comment.