https://github.com/mr-destructive/hugging-chat-go
https://github.com/mr-destructive/hugging-chat-go
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/mr-destructive/hugging-chat-go
- Owner: Mr-Destructive
- License: mit
- Created: 2023-05-17T14:51:21.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-07-03T14:39:46.000Z (almost 3 years ago)
- Last Synced: 2025-01-29T20:37:20.683Z (over 1 year ago)
- Language: Go
- Size: 14.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Hugging Face Chatbot Example
This is a basic example of using the HuggingFace Chat Client in Go.
## Installation
```
go get github.com/mr-destructive/hugging-chat-go
```
## Usage
Add a `.env` file with the credentials of the hugchat application.
```
email=abc@def.com
password=superSecret
```
Use the `hugchat.NewChatBot(email, password)` method to instantiate the chat bot object by authenticating the sesssion. Further with that object, request the api with the `Chat` method by fine tuning the parameters provided in the below example:
```go
package main
import (
"bufio"
"fmt"
"os"
"github.com/mr-destructive/hugging-chat-go/hugchat"
)
func main() {
err := hugchat.LoadEnvFromFile(".env")
//cookies_map := map[string]string{"hf-chat": os.Getenv("hf-chat")}
email := os.Getenv("email")
password := os.Getenv("password")
var inp string
reader := bufio.NewReader(os.Stdin)
fmt.Println("Enter the prompt:")
inp, _ = reader.ReadString('\n')
bot, err := hugchat.NewChatBot(email, password)
if err != nil {
fmt.Println(err)
}
text := inp
temperature := 0.9
topP := 0.95
repetitionPenalty := 1.2
topK := 50
truncate := 1024
watermark := false
maxNewTokens := 1024
stop := []string{""}
returnFullText := false
stream := true
useCache := false
isRetry := false
retryCount := 5
response, err := bot.Chat(text, temperature, topP, repetitionPenalty, topK, truncate, watermark, maxNewTokens, stop, returnFullText, stream, useCache, isRetry, retryCount)
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
fmt.Println(response)
}
```
OR
```go
package main
import (
"bufio"
"fmt"
"os"
"github.com/mr-destructive/hugging-chat-go/hugchat"
)
func main() {
err := hugchat.LoadEnvFromFile(".env")
email := os.Getenv("email")
password := os.Getenv("password")
text = "What is universe?"
bot, err := hugchat.NewChatBot(email, password)
if err != nil {
fmt.Println(err)
}
response, err := bot.ChatPrompt(text)
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
fmt.Println(response)
```