Documentation ¶
Index ¶
- Variables
- func AddUserToGroup(om *GroupMember) error
- func ChatCreate(w http.ResponseWriter, r *http.Request)
- func ChatDelete(w http.ResponseWriter, r *http.Request)
- func ChatIndex(w http.ResponseWriter, r *http.Request)
- func ChatPrompt(w http.ResponseWriter, r *http.Request)
- func ChatRead(w http.ResponseWriter, r *http.Request)
- func ChatStream(w http.ResponseWriter, r *http.Request)
- func ChatUpdate(w http.ResponseWriter, r *http.Request)
- func ChatUserAdd(w http.ResponseWriter, r *http.Request)
- func ChatUserRemove(w http.ResponseWriter, r *http.Request)
- func CreateGroup(group *Group) error
- func GroupCreate(w http.ResponseWriter, r *http.Request)
- func GroupDelete(w http.ResponseWriter, r *http.Request)
- func GroupIndex(w http.ResponseWriter, r *http.Request)
- func GroupMembers(w http.ResponseWriter, r *http.Request)
- func GroupMembersAdd(w http.ResponseWriter, r *http.Request)
- func GroupMembersRemove(w http.ResponseWriter, r *http.Request)
- func GroupRead(w http.ResponseWriter, r *http.Request)
- func GroupUpdate(w http.ResponseWriter, r *http.Request)
- func IsInGroup(groupID, userID string) bool
- func LogsHandler(w http.ResponseWriter, r *http.Request)
- func SetHeaders(w http.ResponseWriter, r *http.Request)
- func UserLogin(w http.ResponseWriter, r *http.Request)
- func UserLogout(w http.ResponseWriter, r *http.Request)
- func UserPasswordUpdate(w http.ResponseWriter, r *http.Request)
- func UserRead(w http.ResponseWriter, r *http.Request)
- func UserSession(w http.ResponseWriter, r *http.Request)
- func UserSignup(w http.ResponseWriter, r *http.Request)
- func UserUpdate(w http.ResponseWriter, r *http.Request)
- func WithAdmin(user, pass string) func(http.Handler) http.Handler
- func WithAuth(h http.Handler) http.Handler
- func WithCors(h http.Handler) http.Handler
- func WithLogger(h http.Handler) http.Handler
- type Chat
- type ChatCreateRequest
- type ChatCreateResponse
- type ChatDeleteRequest
- type ChatDeleteResponse
- type ChatIndexRequest
- type ChatIndexResponse
- type ChatPromptRequest
- type ChatPromptResponse
- type ChatReadRequest
- type ChatReadResponse
- type ChatStreamRequest
- type ChatStreamResponse
- type ChatUpdateRequest
- type ChatUpdateResponse
- type ChatUser
- type ChatUserAddRequest
- type ChatUserAddResponse
- type ChatUserRemoveRequest
- type ChatUserRemoveResponse
- type Event
- type Group
- type GroupCreateRequest
- type GroupDeleteRequest
- type GroupDeleteResponse
- type GroupIndexRequest
- type GroupIndexResponse
- type GroupMember
- type GroupMembersAddRequest
- type GroupMembersAddResponse
- type GroupMembersInviteRequest
- type GroupMembersInviteResponse
- type GroupMembersRemoveRequest
- type GroupMembersRemoveResponse
- type GroupMembersRequest
- type GroupMembersResponse
- type GroupReadRequest
- type GroupReadResponse
- type GroupUpdateRequest
- type GroupUpdateResponse
- type Message
- type Options
- type Proxy
- type Session
- type User
- type UserDeleteRequest
- type UserDeleteResponse
- type UserIndexRequest
- type UserIndexResponse
- type UserLoginRequest
- type UserLoginResponse
- type UserLogoutRequest
- type UserLogoutResponse
- type UserPasswordUpdateRequest
- type UserPasswordUpdateResponse
- type UserReadRequest
- type UserReadResponse
- type UserSessionRequest
- type UserSessionResponse
- type UserSignupRequest
- type UserSignupResponse
- type UserUpdateRequest
- type UserUpdateResponse
Constants ¶
This section is empty.
Variables ¶
var (
// Default number of prompt/replies to send to the llm
DefaultContext = 10
)
var ( // Excludes paths from authentication / logging request-response Excludes = []string{ "/user/signup", "/user/login", "/user/logout", "/user/password/update", } )
var ( Routes = map[string]http.HandlerFunc{ "/chat/create": ChatCreate, "/chat/read": ChatRead, "/chat/update": ChatUpdate, "/chat/delete": ChatDelete, "/chat/prompt": ChatPrompt, "/chat/index": ChatIndex, "/chat/stream": ChatStream, "/chat/user/add": ChatUserAdd, "/chat/user/remove": ChatUserRemove, "/group/create": GroupCreate, "/group/delete": GroupDelete, "/group/read": GroupRead, "/group/update": GroupUpdate, "/group/index": GroupIndex, "/group/members": GroupMembers, "/group/members/add": GroupMembersAdd, "/group/members/remove": GroupMembersRemove, "/user/signup": UserSignup, "/user/login": UserLogin, "/user/logout": UserLogout, "/user/read": UserRead, "/user/update": UserUpdate, "/user/session": UserSession, "/user/password/update": UserPasswordUpdate, } )
var (
SessionCookie = "sess"
)
Functions ¶
func AddUserToGroup ¶
func AddUserToGroup(om *GroupMember) error
func ChatCreate ¶
func ChatCreate(w http.ResponseWriter, r *http.Request)
CreateChat enables the creation of a new chat
func ChatIndex ¶
func ChatIndex(w http.ResponseWriter, r *http.Request)
ChatIndex returns all chats for a user
func ChatPrompt ¶
func ChatPrompt(w http.ResponseWriter, r *http.Request)
ChatPrompt is for making a request to the ChatGPT platform
func ChatRead ¶
func ChatRead(w http.ResponseWriter, r *http.Request)
ChatRead returns the messages for a chat
func ChatStream ¶
func ChatStream(w http.ResponseWriter, r *http.Request)
ChatStream is for streaming SSE events from a chat
func ChatUpdate ¶
func ChatUpdate(w http.ResponseWriter, r *http.Request)
func ChatUserAdd ¶
func ChatUserAdd(w http.ResponseWriter, r *http.Request)
func ChatUserRemove ¶
func ChatUserRemove(w http.ResponseWriter, r *http.Request)
func CreateGroup ¶
func GroupCreate ¶
func GroupCreate(w http.ResponseWriter, r *http.Request)
func GroupDelete ¶
func GroupDelete(w http.ResponseWriter, r *http.Request)
func GroupIndex ¶
func GroupIndex(w http.ResponseWriter, r *http.Request)
func GroupMembers ¶
func GroupMembers(w http.ResponseWriter, r *http.Request)
func GroupMembersAdd ¶
func GroupMembersAdd(w http.ResponseWriter, r *http.Request)
func GroupMembersRemove ¶
func GroupMembersRemove(w http.ResponseWriter, r *http.Request)
func GroupUpdate ¶
func GroupUpdate(w http.ResponseWriter, r *http.Request)
func LogsHandler ¶
func LogsHandler(w http.ResponseWriter, r *http.Request)
func SetHeaders ¶
func SetHeaders(w http.ResponseWriter, r *http.Request)
SetHeaders sets the CORS headers
func UserLogin ¶
func UserLogin(w http.ResponseWriter, r *http.Request)
UserLogin logs in a user using a username and password
func UserLogout ¶
func UserLogout(w http.ResponseWriter, r *http.Request)
UserLogout logs out a user using a session token
func UserPasswordUpdate ¶
func UserPasswordUpdate(w http.ResponseWriter, r *http.Request)
UserPasswordUpdate updates the password of a user
func UserSession ¶
func UserSession(w http.ResponseWriter, r *http.Request)
UserSession reads the current user session and returns the user
func UserSignup ¶
func UserSignup(w http.ResponseWriter, r *http.Request)
func UserUpdate ¶
func UserUpdate(w http.ResponseWriter, r *http.Request)
Types ¶
type Chat ¶
type Chat struct { gorm.Model ID string `json:"id" valid:"required" gorm:"index:idx_chat_user,priority:2"` Name string `json:"name" valid:"required"` // name of the chat given by the user LLM string `json:"model" valid:"required"` UserID string `json:"user_id" gorm:"index:idx_chat_user,priority:1"` GroupID string `json:"group_id" gorm:"index"` // TODO new composite index with user }
Chat is the base type for a conversation
type ChatCreateRequest ¶
type ChatCreateResponse ¶
type ChatCreateResponse struct {
Chat
}
type ChatDeleteRequest ¶
type ChatDeleteRequest struct { // Unique chat id ID string `json:"id" valid:"required"` }
type ChatDeleteResponse ¶
type ChatDeleteResponse struct { }
type ChatIndexRequest ¶
type ChatIndexRequest struct { }
type ChatIndexResponse ¶
type ChatIndexResponse struct {
Chats []*Chat `json:"chats"`
}
type ChatPromptRequest ¶
type ChatPromptResponse ¶
type ChatPromptResponse struct { // If stream is specified in request then Reply in response message is nil Message Message `json:"message"` }
type ChatReadRequest ¶
type ChatReadRequest struct {
ID string `json:"id" valid:"required"`
}
type ChatReadResponse ¶
type ChatStreamRequest ¶
type ChatStreamRequest struct {
ID string `json:"id" valid:"required"`
}
type ChatStreamResponse ¶
type ChatUpdateRequest ¶
type ChatUpdateResponse ¶
type ChatUser ¶
type ChatUser struct { gorm.Model ChatID string `json:"chat_id" gorm:"uniqueIndex:idx_chat_user_member,priority:2"` UserID string `json:"user_id" gorm:"uniqueIndex:idx_chat_user_member,priority:1"` }
func GetChatUser ¶
func GetChatUsers ¶
func GetChatsForUser ¶
type ChatUserAddRequest ¶
type ChatUserAddResponse ¶
type ChatUserAddResponse struct{}
type ChatUserRemoveRequest ¶
type ChatUserRemoveResponse ¶
type ChatUserRemoveResponse struct{}
type Event ¶
type Event struct { // TODO: gorm validation gorm.Model ID string `json:"ID"` Timestamp time.Time `json:"Timestamp"` ClientIP string `json:"ClientIP"` Endpoint string `json:"Endpoint"` Request string `json:"Request"` Response string `json:"Response"` Status int `json:"Status"` Message string `json:"Message"` Duration time.Duration `json:"Duration"` Method string `json:"Method"` Params string `json:"Params"` UserID string `json:"UserID"` }
Event is a request summary
type Group ¶
type Group struct { gorm.Model ID string `json:"id" valid:"required"` Name string `json:"name" valid:"length(1|30)"` Description string `json:"description" valid:"length(1|256)"` OwnerID string `json:"owner_id" gorm:"index"` }
Group who users are members of
func GetGroupByID ¶
type GroupCreateRequest ¶
type GroupCreateRequest struct { Name string `json:"name" valid:"length(1|30)"` Description string `json:"description" valid:"length(1|256)"` Members []string `json:"members"` }
GroupCreateRequest for group/create
type GroupDeleteRequest ¶
type GroupDeleteRequest struct {
ID string `json:"id" valid:"required"`
}
type GroupDeleteResponse ¶
type GroupDeleteResponse struct {
Group Group `json:"group"`
}
type GroupIndexRequest ¶
type GroupIndexRequest struct{}
GroupIndexRequest for group/index Get token for userID and list all groups that user is in This is overkill as users will only have one group to start with but worth building for future
type GroupIndexResponse ¶
type GroupIndexResponse struct {
Groups []Group `json:"groups"`
}
GroupIndexResponse for group/index
type GroupMember ¶
type GroupMembersAddRequest ¶
type GroupMembersAddRequest struct { ID string `json:"id" valid:"required,length(1|254)"` UserIDs []string `json:"user_ids"` }
GroupUsersCreateRequest for group/users/create adds a users to an group. TODO: permissions
type GroupMembersAddResponse ¶
type GroupMembersAddResponse struct{}
type GroupMembersInviteResponse ¶
type GroupMembersInviteResponse struct{}
type GroupMembersRemoveResponse ¶
type GroupMembersRemoveResponse struct{}
type GroupMembersRequest ¶
type GroupMembersRequest struct {
ID string `json:"id" valid:"required"`
}
GroupMembersRequest for group/users returns all users in an group
type GroupMembersResponse ¶
type GroupMembersResponse struct {
Users []User `json:"users"`
}
GroupUsersResponse for group/users
type GroupReadRequest ¶
type GroupReadRequest struct {
ID string `json:"id" valid:"required"`
}
GroupReadRequest for group/read
type GroupReadResponse ¶
type GroupReadResponse struct {
Group
}
type GroupUpdateRequest ¶
type GroupUpdateRequest struct { ID string `json:"id" valid:"required"` Name string `json:"name" valid:"length(1|30)"` Description string `json:"description" valid:"length(1|256)"` }
GroupUpdateRequest for group/update
type GroupUpdateResponse ¶
type GroupUpdateResponse struct {
Group
}
GroupUpdateResponse for group/update
type Message ¶
type Message struct { gorm.Model ID string `json:"id" valid:"required"` ChatID string `json:"chat_id" gorm:"index:idx_chat_message,priority:2"` UserID string `json:"user_id" gorm:"index:idx_chat_message,priority:1"` GroupID string `json:"group_id" gorm:"index"` Prompt string `json:"prompt"` Reply string `json:"reply"` LLM string `json:"model"` OTR bool `json:"otr"` }
Message represents the messages in a Chat
type Proxy ¶
type Proxy struct {
// contains filtered or unexported fields
}
Proxy handles all inbound requests
type Session ¶
type Session struct { gorm.Model Token string `json:"token" gorm:"index"` ExpiresAt time.Time `json:"expires_at"` Username string `json:"username"` UserID string `json:"user_id"` }
The session for a given user
type User ¶
type User struct { // TODO: gorm validation gorm.Model ID string `json:"id" valid:"required"` FirstName string `json:"first_name" valid:"length(1|30)"` LastName string `json:"last_name" valid:"length(1|30)"` Username string `json:"username" valid:"required,username,length(6|254)" gorm:"unique_index;not null"` Password string `json:"-"` Groups []Group `json:"groups" gorm:"many2many:user_groups;"` }
User who signs up
func CreateUser ¶
type UserDeleteRequest ¶
type UserDeleteRequest struct {
ID string `json:"id" valid:"required"`
}
UserDeleteRequest for deleting
type UserIndexRequest ¶
type UserIndexRequest struct {
GroupID uint `json:"group_id" valid:"length(1|30)"`
}
UserIndexRequest for user/index TODO: worry about pagination later.
type UserIndexResponse ¶
type UserIndexResponse struct {
Users []User `json:"users"`
}
UserIndexResponse for user/index
type UserLoginRequest ¶
type UserLoginRequest struct { Username string `json:"username" valid:"required,length(1|254)"` // currently username Password string `json:"password" valid:"required"` // ^[a-z0-9@.-_+]+$ - no validation }
UserLoginRequest struct for auth/login
type UserLoginResponse ¶
UserLoginResponse struct for auth/login
type UserLogoutRequest ¶
type UserLogoutRequest struct {
Token string
}
UserLogoutRequest struct for auth/logout Just need valid header
type UserLogoutResponse ¶
type UserLogoutResponse struct{}
UserLogoutResponse struct for auth/logout Just need valid header
type UserPasswordUpdateRequest ¶
type UserPasswordUpdateRequest struct { OldPassword string `json:"old_password" valid:"required"` NewPassword string `json:"new_password" valid:"required"` }
UserPasswordUpdateRequest is for updating a password by logged in user
type UserPasswordUpdateResponse ¶
type UserPasswordUpdateResponse struct{}
type UserReadRequest ¶
type UserReadRequest struct {
ID string `json:"id" valid:"required"`
}
UserReadRequest for user/read
type UserReadResponse ¶
type UserReadResponse struct {
User User `json:"user"`
}
UserReadResponse full user with id Response for user/create, user/read & user/update
type UserSessionRequest ¶
type UserSessionRequest struct{}
User session request to get the current user
type UserSessionResponse ¶
type UserSessionResponse struct {
User User `json:"user"`
}
type UserSignupRequest ¶
type UserSignupRequest struct { // ID created in backend FirstName string `json:"first_name,omitempty"` LastName string `json:"last_name,omitempty"` Username string `json:"username" valid:"required,length(1|254)" gorm:"unique_index;not null"` Password string `json:"password" valid:"required"` GroupName string `json:"group_name,omitempty"` }
UserSignupRequest for user/register Need to create group from first+last name
type UserSignupResponse ¶
UserSignupResponse for user/register same as authResponse
type UserUpdateRequest ¶
type UserUpdateRequest struct { ID string `json:"id" valid:"required"` FirstName string `json:"first_name" valid:"length(1|30)"` LastName string `json:"last_name" valid:"length(1|30)"` Username string `json:"username" valid:"required,username,length(6|254)"` }
UserUpdateRequest for user/update TODO: validate username and check is unique
type UserUpdateResponse ¶
type UserUpdateResponse struct{}