diff --git a/README.md b/README.md index 14a7c13..0d4b146 100644 --- a/README.md +++ b/README.md @@ -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) +} ```