-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e0c1333
commit 06e5a05
Showing
6 changed files
with
227 additions
and
67 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
"context" | ||
"fmt" | ||
"io" | ||
"log" | ||
"os" | ||
"strings" | ||
|
||
"github.com/dleviminzi/anthrogo" | ||
) | ||
|
||
func main() { | ||
c, err := anthrogo.NewClient() | ||
if err != nil { | ||
log.Fatal(err) | ||
os.Exit(1) | ||
} | ||
|
||
systemPrompt := "you are an expert in all things bananas" | ||
|
||
// Read user input for the prompt | ||
reader := bufio.NewReader(os.Stdin) | ||
fmt.Print("Enter your prompt: ") | ||
userPrompt, _ := reader.ReadString('\n') | ||
userPrompt = strings.TrimSuffix(userPrompt, "\n") | ||
|
||
r, _, err := c.MessageStreamRequest(context.Background(), anthrogo.MessagePayload{ | ||
Model: anthrogo.ModelClaude3Opus, | ||
Messages: []anthrogo.Message{{ | ||
Role: anthrogo.RoleTypeUser, | ||
Content: []anthrogo.MessageContent{{ | ||
Type: anthrogo.ContentTypeText, | ||
Text: &userPrompt, | ||
}}, | ||
}}, | ||
System: &systemPrompt, | ||
MaxTokens: 1000, | ||
}) | ||
if err != nil { | ||
log.Fatal(err) | ||
os.Exit(1) | ||
} | ||
defer r.Close() | ||
|
||
// Create an SSEDecoder | ||
decoder := anthrogo.NewMessageSSEDecoder(r) | ||
for { | ||
message, err := decoder.Decode(anthrogo.DecodeOptions{ContentOnly: true}) | ||
if err != nil { | ||
if err == io.EOF { | ||
break | ||
} | ||
fmt.Print(err) | ||
continue | ||
} | ||
|
||
if message.Event == "message_stop" { | ||
break | ||
} | ||
|
||
fmt.Print(message.Data.Content) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.