Skip to content

Latest commit

 

History

History
145 lines (112 loc) · 8.36 KB

README.md

File metadata and controls

145 lines (112 loc) · 8.36 KB

ChatSession

(ChatSession)

Overview

Create and manage chat sessions for users. Chat history and continuation of chat is automatically done.

Available Operations

Create

Create Chat Session

Example Usage

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
	      }
    }
}

Parameters

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.

Response

*operations.CreateResponse, error

Errors

Error Object Status Code Content Type
sdkerrors.HTTPValidationError 422 application/json
sdkerrors.SDKError 4xx-5xx /

Continue

Continue Chat Session

Example Usage

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
	      }
    }
}

Parameters

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.

Response

*operations.ContinueResponse, error

Errors

Error Object Status Code Content Type
sdkerrors.HTTPValidationError 422 application/json
sdkerrors.SDKError 4xx-5xx /