From 2d990c19bda4361fbe108a3329ae76f2083e9cfb Mon Sep 17 00:00:00 2001 From: fern-api <115122769+fern-api[bot]@users.noreply.github.com> Date: Wed, 12 Jun 2024 21:05:26 +0000 Subject: [PATCH] SDK regeneration --- core/request_option.go | 2 +- errors.go | 24 +++++ memory.go | 37 ++++---- memory/client.go | 160 ++++++++++++++++++++++++-------- types.go | 201 +++++++++++++++++++++++++++++++++-------- 5 files changed, 330 insertions(+), 94 deletions(-) diff --git a/core/request_option.go b/core/request_option.go index 0eb1ee8..1773188 100644 --- a/core/request_option.go +++ b/core/request_option.go @@ -52,7 +52,7 @@ func (r *RequestOptions) cloneHeader() http.Header { headers := r.HTTPHeader.Clone() headers.Set("X-Fern-Language", "Go") headers.Set("X-Fern-SDK-Name", "github.com/getzep/zep-go") - headers.Set("X-Fern-SDK-Version", "v1.0.3") + headers.Set("X-Fern-SDK-Version", "v1.0.4") return headers } diff --git a/errors.go b/errors.go index d1c24c6..25187ec 100644 --- a/errors.go +++ b/errors.go @@ -31,6 +31,30 @@ func (b *BadRequestError) Unwrap() error { return b.APIError } +// Conflict +type ConflictError struct { + *core.APIError + Body *APIError +} + +func (c *ConflictError) UnmarshalJSON(data []byte) error { + var body *APIError + if err := json.Unmarshal(data, &body); err != nil { + return err + } + c.StatusCode = 409 + c.Body = body + return nil +} + +func (c *ConflictError) MarshalJSON() ([]byte, error) { + return json.Marshal(c.Body) +} + +func (c *ConflictError) Unwrap() error { + return c.APIError +} + // Internal Server Error type InternalServerError struct { *core.APIError diff --git a/memory.go b/memory.go index d7e3194..6b6bb35 100644 --- a/memory.go +++ b/memory.go @@ -24,26 +24,14 @@ type CreateSessionRequest struct { UserID *string `json:"user_id,omitempty" url:"user_id,omitempty"` } -type ClassifySessionRequest struct { - // The classes to use for classification. - Classes []string `json:"classes,omitempty" url:"classes,omitempty"` - // Custom instruction to use for classification. - Instruction *string `json:"instruction,omitempty" url:"instruction,omitempty"` - // The number of session messages to consider for classification. Defaults to 4. - LastN *int `json:"last_n,omitempty" url:"last_n,omitempty"` - // The name of the classifier. Will be used to store the classification in session metadata if persist is True. - Name string `json:"name" url:"name"` - // Whether to persist the classification to session metadata. Defaults to True. - Persist *bool `json:"persist,omitempty" url:"persist,omitempty"` -} - type EndSessionRequest struct { - Instruction *string `json:"instruction,omitempty" url:"instruction,omitempty"` + Classify *ClassifySessionRequest `json:"classify,omitempty" url:"classify,omitempty"` + Instruction *string `json:"instruction,omitempty" url:"instruction,omitempty"` } -type ModelsExtractDataRequest struct { - LastNMessages *int `json:"last_n_messages,omitempty" url:"last_n_messages,omitempty"` - ZepDataClasses []*ModelsZepDataClass `json:"zep_data_classes,omitempty" url:"zep_data_classes,omitempty"` +type EndSessionsRequest struct { + Instruction *string `json:"instruction,omitempty" url:"instruction,omitempty"` + SessionIDs []string `json:"session_ids,omitempty" url:"session_ids,omitempty"` } type MemoryGetRequest struct { @@ -83,6 +71,21 @@ type MemorySearchPayload struct { Text *string `json:"text,omitempty" url:"text,omitempty"` } +type SessionSearchQuery struct { + // The maximum number of search results to return. Defaults to None (no limit). + Limit *int `json:"-" url:"limit,omitempty"` + MinScore *float64 `json:"min_score,omitempty" url:"min_score,omitempty"` + MmrLambda *float64 `json:"mmr_lambda,omitempty" url:"mmr_lambda,omitempty"` + // filter on the metadata + RecordFilter map[string]interface{} `json:"record_filter,omitempty" url:"record_filter,omitempty"` + SearchScope *SearchScope `json:"search_scope,omitempty" url:"search_scope,omitempty"` + SearchType *SearchType `json:"search_type,omitempty" url:"search_type,omitempty"` + // the session ids to search + SessionIDs []string `json:"session_ids,omitempty" url:"session_ids,omitempty"` + Text *string `json:"text,omitempty" url:"text,omitempty"` + UserID *string `json:"user_id,omitempty" url:"user_id,omitempty"` +} + type MemorySynthesizeQuestionRequest struct { // The number of messages to use for question synthesis. LastNMessages *int `json:"-" url:"lastNMessages,omitempty"` diff --git a/memory/client.go b/memory/client.go index d7878ab..6e524d1 100644 --- a/memory/client.go +++ b/memory/client.go @@ -173,13 +173,12 @@ func (c *Client) ListSessions( return response, nil } -// get session by id -func (c *Client) GetSession( +// End multiple sessions by their IDs +func (c *Client) EndSessions( ctx context.Context, - // Session ID - sessionID string, + request *zepgo.EndSessionsRequest, opts ...option.RequestOption, -) (*zepgo.Session, error) { +) (*zepgo.EndSessionsResponse, error) { options := core.NewRequestOptions(opts...) baseURL := "https://api.getzep.com/api/v2" @@ -189,7 +188,7 @@ func (c *Client) GetSession( if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := core.EncodeURL(baseURL+"/sessions/%v", sessionID) + endpointURL := baseURL + "/sessions/end" headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -201,6 +200,13 @@ func (c *Client) GetSession( apiError := core.NewAPIError(statusCode, errors.New(string(raw))) decoder := json.NewDecoder(bytes.NewReader(raw)) switch statusCode { + case 400: + value := new(zepgo.BadRequestError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 404: value := new(zepgo.NotFoundError) value.APIError = apiError @@ -219,15 +225,16 @@ func (c *Client) GetSession( return apiError } - var response *zepgo.Session + var response *zepgo.EndSessionsResponse if err := c.caller.Call( ctx, &core.CallParams{ URL: endpointURL, - Method: http.MethodGet, + Method: http.MethodPost, MaxAttempts: options.MaxAttempts, Headers: headers, Client: options.HTTPClient, + Request: request, Response: &response, ErrorDecoder: errorDecoder, }, @@ -237,14 +244,12 @@ func (c *Client) GetSession( return response, nil } -// Update Session Metadata -func (c *Client) UpdateSession( +// Search sessions for the specified query. +func (c *Client) SearchSessions( ctx context.Context, - // Session ID - sessionID string, - request *zepgo.UpdateSessionRequest, + request *zepgo.SessionSearchQuery, opts ...option.RequestOption, -) (*zepgo.Session, error) { +) (*zepgo.SessionSearchResponse, error) { options := core.NewRequestOptions(opts...) baseURL := "https://api.getzep.com/api/v2" @@ -254,7 +259,15 @@ func (c *Client) UpdateSession( if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := core.EncodeURL(baseURL+"/sessions/%v", sessionID) + endpointURL := baseURL + "/sessions/search" + + queryParams, err := core.QueryValues(request) + if err != nil { + return nil, err + } + if len(queryParams) > 0 { + endpointURL += "?" + queryParams.Encode() + } headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -266,13 +279,64 @@ func (c *Client) UpdateSession( apiError := core.NewAPIError(statusCode, errors.New(string(raw))) decoder := json.NewDecoder(bytes.NewReader(raw)) switch statusCode { - case 400: - value := new(zepgo.BadRequestError) + case 500: + value := new(zepgo.InternalServerError) value.APIError = apiError if err := decoder.Decode(value); err != nil { return apiError } return value + } + return apiError + } + + var response *zepgo.SessionSearchResponse + if err := c.caller.Call( + ctx, + &core.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + MaxAttempts: options.MaxAttempts, + Headers: headers, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: errorDecoder, + }, + ); err != nil { + return nil, err + } + return response, nil +} + +// get session by id +func (c *Client) GetSession( + ctx context.Context, + // Session ID + sessionID string, + opts ...option.RequestOption, +) (*zepgo.Session, error) { + options := core.NewRequestOptions(opts...) + + baseURL := "https://api.getzep.com/api/v2" + if c.baseURL != "" { + baseURL = c.baseURL + } + if options.BaseURL != "" { + baseURL = options.BaseURL + } + endpointURL := core.EncodeURL(baseURL+"/sessions/%v", sessionID) + + headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + + errorDecoder := func(statusCode int, body io.Reader) error { + raw, err := io.ReadAll(body) + if err != nil { + return err + } + apiError := core.NewAPIError(statusCode, errors.New(string(raw))) + decoder := json.NewDecoder(bytes.NewReader(raw)) + switch statusCode { case 404: value := new(zepgo.NotFoundError) value.APIError = apiError @@ -296,11 +360,10 @@ func (c *Client) UpdateSession( ctx, &core.CallParams{ URL: endpointURL, - Method: http.MethodPatch, + Method: http.MethodGet, MaxAttempts: options.MaxAttempts, Headers: headers, Client: options.HTTPClient, - Request: request, Response: &response, ErrorDecoder: errorDecoder, }, @@ -310,14 +373,14 @@ func (c *Client) UpdateSession( return response, nil } -// classify a session by session id -func (c *Client) ClassifySession( +// Update Session Metadata +func (c *Client) UpdateSession( ctx context.Context, // Session ID sessionID string, - request *zepgo.ClassifySessionRequest, + request *zepgo.UpdateSessionRequest, opts ...option.RequestOption, -) (*zepgo.ClassifySessionResponse, error) { +) (*zepgo.Session, error) { options := core.NewRequestOptions(opts...) baseURL := "https://api.getzep.com/api/v2" @@ -327,7 +390,7 @@ func (c *Client) ClassifySession( if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := core.EncodeURL(baseURL+"/sessions/%v/classify", sessionID) + endpointURL := core.EncodeURL(baseURL+"/sessions/%v", sessionID) headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -339,6 +402,13 @@ func (c *Client) ClassifySession( apiError := core.NewAPIError(statusCode, errors.New(string(raw))) decoder := json.NewDecoder(bytes.NewReader(raw)) switch statusCode { + case 400: + value := new(zepgo.BadRequestError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 404: value := new(zepgo.NotFoundError) value.APIError = apiError @@ -346,6 +416,13 @@ func (c *Client) ClassifySession( return apiError } return value + case 409: + value := new(zepgo.ConflictError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 500: value := new(zepgo.InternalServerError) value.APIError = apiError @@ -357,12 +434,12 @@ func (c *Client) ClassifySession( return apiError } - var response *zepgo.ClassifySessionResponse + var response *zepgo.Session if err := c.caller.Call( ctx, &core.CallParams{ URL: endpointURL, - Method: http.MethodPost, + Method: http.MethodPatch, MaxAttempts: options.MaxAttempts, Headers: headers, Client: options.HTTPClient, @@ -376,14 +453,14 @@ func (c *Client) ClassifySession( return response, nil } -// End a session by ID -func (c *Client) EndSession( +// classify a session by session id +func (c *Client) ClassifySession( ctx context.Context, // Session ID sessionID string, - request *zepgo.EndSessionRequest, + request *zepgo.ClassifySessionRequest, opts ...option.RequestOption, -) (*zepgo.Session, error) { +) (*zepgo.ClassifySessionResponse, error) { options := core.NewRequestOptions(opts...) baseURL := "https://api.getzep.com/api/v2" @@ -393,7 +470,7 @@ func (c *Client) EndSession( if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := core.EncodeURL(baseURL+"/sessions/%v/end", sessionID) + endpointURL := core.EncodeURL(baseURL+"/sessions/%v/classify", sessionID) headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -423,7 +500,7 @@ func (c *Client) EndSession( return apiError } - var response *zepgo.Session + var response *zepgo.ClassifySessionResponse if err := c.caller.Call( ctx, &core.CallParams{ @@ -442,14 +519,14 @@ func (c *Client) EndSession( return response, nil } -// extract data from a session by session id -func (c *Client) ExtractSessionData( +// End a session by ID +func (c *Client) EndSession( ctx context.Context, // Session ID sessionID string, - request *zepgo.ModelsExtractDataRequest, + request *zepgo.EndSessionRequest, opts ...option.RequestOption, -) (map[string]string, error) { +) (*zepgo.EndSessionResponse, error) { options := core.NewRequestOptions(opts...) baseURL := "https://api.getzep.com/api/v2" @@ -459,7 +536,7 @@ func (c *Client) ExtractSessionData( if options.BaseURL != "" { baseURL = options.BaseURL } - endpointURL := core.EncodeURL(baseURL+"/sessions/%v/extract", sessionID) + endpointURL := core.EncodeURL(baseURL+"/sessions/%v/end", sessionID) headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) @@ -471,6 +548,13 @@ func (c *Client) ExtractSessionData( apiError := core.NewAPIError(statusCode, errors.New(string(raw))) decoder := json.NewDecoder(bytes.NewReader(raw)) switch statusCode { + case 400: + value := new(zepgo.BadRequestError) + value.APIError = apiError + if err := decoder.Decode(value); err != nil { + return apiError + } + return value case 404: value := new(zepgo.NotFoundError) value.APIError = apiError @@ -489,7 +573,7 @@ func (c *Client) ExtractSessionData( return apiError } - var response map[string]string + var response *zepgo.EndSessionResponse if err := c.caller.Call( ctx, &core.CallParams{ diff --git a/types.go b/types.go index 7d421d0..588d5fe 100644 --- a/types.go +++ b/types.go @@ -37,6 +37,44 @@ func (a *APIError) String() string { return fmt.Sprintf("%#v", a) } +type ClassifySessionRequest struct { + // The classes to use for classification. + Classes []string `json:"classes,omitempty" url:"classes,omitempty"` + // Custom instruction to use for classification. + Instruction *string `json:"instruction,omitempty" url:"instruction,omitempty"` + // The number of session messages to consider for classification. Defaults to 4. + LastN *int `json:"last_n,omitempty" url:"last_n,omitempty"` + // The name of the classifier. Will be used to store the classification in session metadata if persist is True. + Name string `json:"name" url:"name"` + // Whether to persist the classification to session metadata. Defaults to True. + Persist *bool `json:"persist,omitempty" url:"persist,omitempty"` + + _rawJSON json.RawMessage +} + +func (c *ClassifySessionRequest) UnmarshalJSON(data []byte) error { + type unmarshaler ClassifySessionRequest + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *c = ClassifySessionRequest(value) + c._rawJSON = json.RawMessage(data) + return nil +} + +func (c *ClassifySessionRequest) String() string { + if len(c._rawJSON) > 0 { + if value, err := core.StringifyJSON(c._rawJSON); err == nil { + return value + } + } + if value, err := core.StringifyJSON(c); err == nil { + return value + } + return fmt.Sprintf("%#v", c) +} + type ClassifySessionResponse struct { Class *string `json:"class,omitempty" url:"class,omitempty"` Name *string `json:"name,omitempty" url:"name,omitempty"` @@ -68,9 +106,8 @@ func (c *ClassifySessionResponse) String() string { } type CreateDocumentRequest struct { - Content *string `json:"content,omitempty" url:"content,omitempty"` + Content string `json:"content" url:"content"` DocumentID *string `json:"document_id,omitempty" url:"document_id,omitempty"` - Embedding []float64 `json:"embedding,omitempty" url:"embedding,omitempty"` Metadata map[string]interface{} `json:"metadata,omitempty" url:"metadata,omitempty"` _rawJSON json.RawMessage @@ -248,6 +285,65 @@ func (d *DocumentSearchResultPage) String() string { return fmt.Sprintf("%#v", d) } +type EndSessionResponse struct { + Classification *ClassifySessionResponse `json:"classification,omitempty" url:"classification,omitempty"` + Session *Session `json:"session,omitempty" url:"session,omitempty"` + + _rawJSON json.RawMessage +} + +func (e *EndSessionResponse) UnmarshalJSON(data []byte) error { + type unmarshaler EndSessionResponse + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *e = EndSessionResponse(value) + e._rawJSON = json.RawMessage(data) + return nil +} + +func (e *EndSessionResponse) String() string { + if len(e._rawJSON) > 0 { + if value, err := core.StringifyJSON(e._rawJSON); err == nil { + return value + } + } + if value, err := core.StringifyJSON(e); err == nil { + return value + } + return fmt.Sprintf("%#v", e) +} + +type EndSessionsResponse struct { + Sessions []*Session `json:"sessions,omitempty" url:"sessions,omitempty"` + + _rawJSON json.RawMessage +} + +func (e *EndSessionsResponse) UnmarshalJSON(data []byte) error { + type unmarshaler EndSessionsResponse + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *e = EndSessionsResponse(value) + e._rawJSON = json.RawMessage(data) + return nil +} + +func (e *EndSessionsResponse) String() string { + if len(e._rawJSON) > 0 { + if value, err := core.StringifyJSON(e._rawJSON); err == nil { + return value + } + } + if value, err := core.StringifyJSON(e); err == nil { + return value + } + return fmt.Sprintf("%#v", e) +} + type Memory struct { // Most recent list of facts derived from the session. Included only with perpetual memory type. Facts []string `json:"facts,omitempty" url:"facts,omitempty"` @@ -287,11 +383,10 @@ func (m *Memory) String() string { } type MemorySearchResult struct { - Embedding []float64 `json:"embedding,omitempty" url:"embedding,omitempty"` - Message *Message `json:"message,omitempty" url:"message,omitempty"` - Metadata map[string]interface{} `json:"metadata,omitempty" url:"metadata,omitempty"` - Score *float64 `json:"score,omitempty" url:"score,omitempty"` - Summary *Summary `json:"summary,omitempty" url:"summary,omitempty"` + Message *Message `json:"message,omitempty" url:"message,omitempty"` + Metadata map[string]interface{} `json:"metadata,omitempty" url:"metadata,omitempty"` + Score *float64 `json:"score,omitempty" url:"score,omitempty"` + Summary *Summary `json:"summary,omitempty" url:"summary,omitempty"` _rawJSON json.RawMessage } @@ -397,37 +492,6 @@ func (m *MessageListResponse) String() string { return fmt.Sprintf("%#v", m) } -type ModelsZepDataClass struct { - Description *string `json:"description,omitempty" url:"description,omitempty"` - Name *string `json:"name,omitempty" url:"name,omitempty"` - Type *string `json:"type,omitempty" url:"type,omitempty"` - - _rawJSON json.RawMessage -} - -func (m *ModelsZepDataClass) UnmarshalJSON(data []byte) error { - type unmarshaler ModelsZepDataClass - var value unmarshaler - if err := json.Unmarshal(data, &value); err != nil { - return err - } - *m = ModelsZepDataClass(value) - m._rawJSON = json.RawMessage(data) - return nil -} - -func (m *ModelsZepDataClass) String() string { - if len(m._rawJSON) > 0 { - if value, err := core.StringifyJSON(m._rawJSON); err == nil { - return value - } - } - if value, err := core.StringifyJSON(m); err == nil { - return value - } - return fmt.Sprintf("%#v", m) -} - type Question struct { Question *string `json:"question,omitempty" url:"question,omitempty"` @@ -607,6 +671,67 @@ func (s *SessionListResponse) String() string { return fmt.Sprintf("%#v", s) } +type SessionSearchResponse struct { + Results []*SessionSearchResult `json:"results,omitempty" url:"results,omitempty"` + + _rawJSON json.RawMessage +} + +func (s *SessionSearchResponse) UnmarshalJSON(data []byte) error { + type unmarshaler SessionSearchResponse + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *s = SessionSearchResponse(value) + s._rawJSON = json.RawMessage(data) + return nil +} + +func (s *SessionSearchResponse) String() string { + if len(s._rawJSON) > 0 { + if value, err := core.StringifyJSON(s._rawJSON); err == nil { + return value + } + } + if value, err := core.StringifyJSON(s); err == nil { + return value + } + return fmt.Sprintf("%#v", s) +} + +type SessionSearchResult struct { + Message *Message `json:"message,omitempty" url:"message,omitempty"` + Score *float64 `json:"score,omitempty" url:"score,omitempty"` + SessionID *string `json:"session_id,omitempty" url:"session_id,omitempty"` + Summary *Summary `json:"summary,omitempty" url:"summary,omitempty"` + + _rawJSON json.RawMessage +} + +func (s *SessionSearchResult) UnmarshalJSON(data []byte) error { + type unmarshaler SessionSearchResult + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *s = SessionSearchResult(value) + s._rawJSON = json.RawMessage(data) + return nil +} + +func (s *SessionSearchResult) String() string { + if len(s._rawJSON) > 0 { + if value, err := core.StringifyJSON(s._rawJSON); err == nil { + return value + } + } + if value, err := core.StringifyJSON(s); err == nil { + return value + } + return fmt.Sprintf("%#v", s) +} + type SuccessResponse struct { Message *string `json:"message,omitempty" url:"message,omitempty"`