Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
zmh-program committed Oct 15, 2023
1 parent 0e630bc commit eed65ad
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,77 @@ instance := chatnio.NewInstanceFromEnv("CHATNIO_TOKEN")

- Chat
```go
chat := instance.NewChat(-1) // id -1: creating new chat

// using hook
chat.AskStream(&chatnio.ChatRequestForm{
Message: "hello",
Model: "gpt-3.5-turbo",
}, func(resp chatnio.ChatPartialResponse) {
fmt.Println(resp.End, resp.Quota, resp.Message, resp.Keyword)
})

// or using channel
channel := make(chan ChatPartialResponse)
chat.Ask(&ChatRequestForm{
Message: "hello",
Model: "gpt-3.5-turbo",
}, channel)

for resp := range channel {
// do something
}
```

- Conversation
```go
// list conversations
if list, err := instance.GetConversationList(); err == nil {
for _, conv := range list {
fmt.Println(conv.Id, conv.Name)
}
}

// get conversation
if conv, err := instance.GetConversation(1); err == nil {
fmt.Println(conv.Id, conv.Name, conv.Message)
}

// delete conversation
if err := instance.DeleteConversation(1); err == nil {
fmt.Println("deleted")
}
```

- Quota
```go
// get quota
if quota, err := instance.GetQuota(); err == nil {
fmt.Println(fmt.Sprintf("current quota is %0.2f", quota))
}

// buy quota
if quota, err := instance.BuyQuota(100); err == nil {
fmt.Println("bought successfully")
}
```

- Subscription and Package
```go
// get subscription
if sub, err := instance.GetSubscription(); err == nil {
fmt.Println(sub.IsSubscribed, sub.Expired)
}

// buy subscription
if err := instance.Subscribe(1); err == nil {
fmt.Println("bought subscription for 1 month successfully")
}

// get package
if pkg, err := instance.GetPackage(); err == nil {
fmt.Println(pkg.Data.Cert, pkg.Data.Teenager)
}
```


Expand Down

0 comments on commit eed65ad

Please sign in to comment.