(ChatSession)
Create and manage chat sessions for users. Chat history and continuation of chat is automatically done.
Create Chat Session
package main
import(
aiapigo "github.com/inkeep/ai-api-go"
"context"
"github.com/inkeep/ai-api-go/models/components"
"log"
)
func main() {
s := aiapigo.New(
aiapigo.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
)
ctx := context.Background()
res, err := s.ChatSession.Create(ctx, components.CreateChatSessionWithChatResultInput{
IntegrationID: "<value>",
ChatSession: components.ChatSessionInput{
Messages: []components.Message{
components.CreateMessageUserMessage(
components.UserMessage{
Content: "<value>",
},
),
},
},
})
if err != nil {
log.Fatal(err)
}
if res.ChatResult != nil {
defer res.ChatResultStream.Close()
for res.ChatResultStream.Next() {
event := res.ChatResultStream.Value()
log.Print(event)
// Handle the event
}
}
}
Parameter | Type | Required | Description |
---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
request |
components.CreateChatSessionWithChatResultInput | ✔️ | The request object to use for the request. |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.CreateResponse, error
Error Object | Status Code | Content Type |
---|---|---|
sdkerrors.HTTPValidationError | 422 | application/json |
sdkerrors.SDKError | 4xx-5xx | / |
Continue Chat Session
package main
import(
aiapigo "github.com/inkeep/ai-api-go"
"context"
"github.com/inkeep/ai-api-go/models/components"
"log"
)
func main() {
s := aiapigo.New(
aiapigo.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
)
ctx := context.Background()
res, err := s.ChatSession.Continue(ctx, "<value>", components.ContinueChatSessionWithChatResultInput{
IntegrationID: "<value>",
Message: components.CreateMessageAssistantMessage(
components.AssistantMessage{
Content: "<value>",
},
),
})
if err != nil {
log.Fatal(err)
}
if res.ChatResult != nil {
defer res.ChatResultStream.Close()
for res.ChatResultStream.Next() {
event := res.ChatResultStream.Value()
log.Print(event)
// Handle the event
}
}
}
Parameter | Type | Required | Description |
---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
chatSessionID |
string | ✔️ | N/A |
continueChatSessionWithChatResultInput |
components.ContinueChatSessionWithChatResultInput | ✔️ | N/A |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.ContinueResponse, error
Error Object | Status Code | Content Type |
---|---|---|
sdkerrors.HTTPValidationError | 422 | application/json |
sdkerrors.SDKError | 4xx-5xx | / |