diff --git a/.speakeasy/gen.lock b/.speakeasy/gen.lock index 7dba57c..7e3a59f 100755 --- a/.speakeasy/gen.lock +++ b/.speakeasy/gen.lock @@ -3,10 +3,10 @@ id: 75084268-f421-4ea6-8995-12fee2bcfd75 management: docChecksum: 3421b267db90c24a6b62d0b3559978bc docVersion: 0.1.0 - speakeasyVersion: 1.382.0 - generationVersion: 2.404.11 - releaseVersion: 0.9.4 - configChecksum: 88afee7466720a7db49a55eaf6ae67e1 + speakeasyVersion: 1.392.1 + generationVersion: 2.411.9 + releaseVersion: 0.9.5 + configChecksum: 151e0685f6d52b78c07cb069ddbe3db4 repoURL: https://github.com/inkeep/ai-api-go.git repoSubDirectory: . installationURL: https://github.com/inkeep/ai-api-go @@ -16,7 +16,7 @@ features: acceptHeaders: 2.81.2 additionalDependencies: 0.1.0 constsAndDefaults: 0.1.6 - core: 3.5.5 + core: 3.5.6 defaultEnabledRetries: 0.2.0 envVarSecurityUsage: 0.3.1 flattening: 2.81.1 @@ -32,78 +32,90 @@ features: serverEvents: 0.1.2 unions: 2.85.9 generatedFiles: - - chatsession.go - - chatapigo.go - - go.mod - - models/sdkerrors/sdkerror.go - - retry/config.go - - types/bigint.go - - types/date.go - - types/datetime.go - - types/decimal.go - - types/pointers.go - - types/stream/stream.go - - internal/utils/contenttype.go - - internal/utils/form.go - - internal/utils/headers.go - - internal/utils/json.go - - internal/utils/pathparams.go - - internal/utils/queryparams.go - - internal/utils/requestbody.go - - internal/utils/retries.go - - internal/utils/security.go - - internal/utils/utils.go - - /models/operations/create.go - - /models/operations/continue.go - - /models/components/chatresultstream.go + - .gitattributes + - /models/components/assistantmessage.go + - /models/components/chatresult.go - /models/components/chatresultmessagechunkevent.go - - /models/components/messagechunk.go - /models/components/chatresultrecordscitedevent.go - - /models/components/recordscited.go + - /models/components/chatresultstream.go + - /models/components/chatsessioninput.go - /models/components/citation.go - - /models/components/record.go - - /models/components/recordtype.go - - /models/components/chatresult.go - - /models/components/assistantmessage.go - - /models/components/validationerror.go + - /models/components/continuechatsessionwithchatresultinput.go - /models/components/createchatsessionwithchatresultinput.go - - /models/components/chatsessioninput.go - /models/components/message.go - - /models/components/usermessage.go - - /models/components/continuechatsessionwithchatresultinput.go + - /models/components/messagechunk.go + - /models/components/record.go + - /models/components/recordscited.go + - /models/components/recordtype.go - /models/components/security.go + - /models/components/usermessage.go + - /models/components/validationerror.go + - /models/operations/continue.go + - /models/operations/create.go - /models/sdkerrors/httpvalidationerror.go - - docs/models/operations/createresponse.md - - docs/models/operations/continuerequest.md - - docs/models/operations/continueresponse.md - - docs/models/components/chatresultstream.md + - CONTRIBUTING.md + - USAGE.md + - chatapigo.go + - chatsession.go + - docs/models/components/assistantmessage.md + - docs/models/components/chatmode.md + - docs/models/components/chatmodeoptions.md + - docs/models/components/chatresult.md - docs/models/components/chatresultmessagechunkevent.md - - docs/models/components/four.md - - docs/models/components/messagechunk.md - docs/models/components/chatresultrecordscitedevent.md - - docs/models/components/recordscited.md + - docs/models/components/chatresultstream.md + - docs/models/components/chatsessioninput.md - docs/models/components/citation.md - - docs/models/components/record.md - - docs/models/components/recordtypeenumerated.md - - docs/models/components/recordtype.md - - docs/models/components/chatresult.md - - docs/models/components/assistantmessage.md - - docs/models/components/loc.md - - docs/models/components/validationerror.md - - docs/models/components/chatmodeoptions.md - - docs/models/components/chatmode.md + - docs/models/components/continuechatsessionwithchatresultinput.md - docs/models/components/createchatsessionwithchatresultinput.md - - docs/models/components/chatsessioninput.md + - docs/models/components/four.md + - docs/models/components/loc.md - docs/models/components/message.md - - docs/models/components/usermessage.md - - docs/models/components/continuechatsessionwithchatresultinput.md + - docs/models/components/messagechunk.md + - docs/models/components/record.md + - docs/models/components/recordscited.md + - docs/models/components/recordtype.md + - docs/models/components/recordtypeenumerated.md - docs/models/components/security.md + - docs/models/components/usermessage.md + - docs/models/components/validationerror.md + - docs/models/operations/continuerequest.md + - docs/models/operations/continueresponse.md + - docs/models/operations/createresponse.md + - docs/models/operations/option.md - docs/models/sdkerrors/httpvalidationerror.md - docs/sdks/chatapigo/README.md - - docs/models/operations/option.md - docs/sdks/chatsession/README.md - - USAGE.md - - models/operations/options.go - - .gitattributes + - go.mod - internal/hooks/hooks.go - - CONTRIBUTING.md + - internal/utils/contenttype.go + - internal/utils/form.go + - internal/utils/headers.go + - internal/utils/json.go + - internal/utils/pathparams.go + - internal/utils/queryparams.go + - internal/utils/requestbody.go + - internal/utils/retries.go + - internal/utils/security.go + - internal/utils/utils.go + - models/operations/options.go + - models/sdkerrors/sdkerror.go + - retry/config.go + - types/bigint.go + - types/date.go + - types/datetime.go + - types/decimal.go + - types/pointers.go + - types/stream/stream.go +examples: + create: + speakeasy-default-create: + requestBody: + application/json: {"integration_id": "", "chat_session": {"messages": []}} + continue: + speakeasy-default-continue: + parameters: + path: + chat_session_id: "" + requestBody: + application/json: {"integration_id": "", "message": {"content": ""}} diff --git a/README.md b/README.md index 61721cb..2100902 100644 --- a/README.md +++ b/README.md @@ -16,9 +16,31 @@ It has been generated successfully based on your OpenAPI spec. However, it is no - [ ] 🎁 Publish your SDK to package managers by [configuring automatic publishing](https://www.speakeasyapi.dev/docs/productionize-sdks/publish-sdks) - [ ] ✨ When ready to productionize, delete this section from the README + +## Summary + +Inkeep Search and Chat API: Leverage the Inkeep APIs to create your own AI-powered search and chat experiences built on top of your own content. + + + +## Table of Contents + +* [SDK Installation](#sdk-installation) +* [SDK Example Usage](#sdk-example-usage) +* [Available Resources and Operations](#available-resources-and-operations) +* [Server-sent event streaming](#server-sent-event-streaming) +* [Retries](#retries) +* [Error Handling](#error-handling) +* [Server Selection](#server-selection) +* [Custom HTTP Client](#custom-http-client) +* [Authentication](#authentication) +* [Special Types](#special-types) + + ## SDK Installation +To add the SDK as a dependency to your project: ```bash go get github.com/inkeep/ai-api-go ``` @@ -43,7 +65,9 @@ func main() { s := aiapigo.New( aiapigo.WithSecurity(""), ) - request := components.CreateChatSessionWithChatResultInput{ + + ctx := context.Background() + res, err := s.ChatSession.Create(ctx, components.CreateChatSessionWithChatResultInput{ IntegrationID: "", ChatSession: components.ChatSessionInput{ Messages: []components.Message{ @@ -54,9 +78,7 @@ func main() { ), }, }, - } - ctx := context.Background() - res, err := s.ChatSession.Create(ctx, request) + }) if err != nil { log.Fatal(err) } @@ -106,7 +128,9 @@ func main() { s := aiapigo.New( aiapigo.WithSecurity(""), ) - request := components.CreateChatSessionWithChatResultInput{ + + ctx := context.Background() + res, err := s.ChatSession.Create(ctx, components.CreateChatSessionWithChatResultInput{ IntegrationID: "", ChatSession: components.ChatSessionInput{ Messages: []components.Message{ @@ -117,9 +141,7 @@ func main() { ), }, }, - } - ctx := context.Background() - res, err := s.ChatSession.Create(ctx, request) + }) if err != nil { log.Fatal(err) } @@ -167,7 +189,9 @@ func main() { s := aiapigo.New( aiapigo.WithSecurity(""), ) - request := components.CreateChatSessionWithChatResultInput{ + + ctx := context.Background() + res, err := s.ChatSession.Create(ctx, components.CreateChatSessionWithChatResultInput{ IntegrationID: "", ChatSession: components.ChatSessionInput{ Messages: []components.Message{ @@ -178,9 +202,7 @@ func main() { ), }, }, - } - ctx := context.Background() - res, err := s.ChatSession.Create(ctx, request) + }) if err != nil { var e *sdkerrors.HTTPValidationError @@ -228,7 +250,9 @@ func main() { aiapigo.WithServerIndex(0), aiapigo.WithSecurity(""), ) - request := components.CreateChatSessionWithChatResultInput{ + + ctx := context.Background() + res, err := s.ChatSession.Create(ctx, components.CreateChatSessionWithChatResultInput{ IntegrationID: "", ChatSession: components.ChatSessionInput{ Messages: []components.Message{ @@ -239,9 +263,7 @@ func main() { ), }, }, - } - ctx := context.Background() - res, err := s.ChatSession.Create(ctx, request) + }) if err != nil { log.Fatal(err) } @@ -277,7 +299,9 @@ func main() { aiapigo.WithServerURL("https://api.inkeep.com"), aiapigo.WithSecurity(""), ) - request := components.CreateChatSessionWithChatResultInput{ + + ctx := context.Background() + res, err := s.ChatSession.Create(ctx, components.CreateChatSessionWithChatResultInput{ IntegrationID: "", ChatSession: components.ChatSessionInput{ Messages: []components.Message{ @@ -288,9 +312,7 @@ func main() { ), }, }, - } - ctx := context.Background() - res, err := s.ChatSession.Create(ctx, request) + }) if err != nil { log.Fatal(err) } @@ -363,7 +385,9 @@ func main() { s := aiapigo.New( aiapigo.WithSecurity(""), ) - request := components.CreateChatSessionWithChatResultInput{ + + ctx := context.Background() + res, err := s.ChatSession.Create(ctx, components.CreateChatSessionWithChatResultInput{ IntegrationID: "", ChatSession: components.ChatSessionInput{ Messages: []components.Message{ @@ -374,9 +398,7 @@ func main() { ), }, }, - } - ctx := context.Background() - res, err := s.ChatSession.Create(ctx, request) + }) if err != nil { log.Fatal(err) } @@ -422,7 +444,9 @@ func main() { s := aiapigo.New( aiapigo.WithSecurity(""), ) - request := components.CreateChatSessionWithChatResultInput{ + + ctx := context.Background() + res, err := s.ChatSession.Create(ctx, components.CreateChatSessionWithChatResultInput{ IntegrationID: "", ChatSession: components.ChatSessionInput{ Messages: []components.Message{ @@ -433,9 +457,7 @@ func main() { ), }, }, - } - ctx := context.Background() - res, err := s.ChatSession.Create(ctx, request, operations.WithRetries( + }, operations.WithRetries( retry.Config{ Strategy: "backoff", Backoff: &retry.BackoffStrategy{ @@ -489,7 +511,9 @@ func main() { }), aiapigo.WithSecurity(""), ) - request := components.CreateChatSessionWithChatResultInput{ + + ctx := context.Background() + res, err := s.ChatSession.Create(ctx, components.CreateChatSessionWithChatResultInput{ IntegrationID: "", ChatSession: components.ChatSessionInput{ Messages: []components.Message{ @@ -500,9 +524,7 @@ func main() { ), }, }, - } - ctx := context.Background() - res, err := s.ChatSession.Create(ctx, request) + }) if err != nil { log.Fatal(err) } diff --git a/RELEASES.md b/RELEASES.md index 027db92..670903b 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -428,4 +428,14 @@ Based on: ### Generated - [go v0.9.4] . ### Releases -- [Go v0.9.4] https://github.com/inkeep/ai-api-go/releases/tag/v0.9.4 - . \ No newline at end of file +- [Go v0.9.4] https://github.com/inkeep/ai-api-go/releases/tag/v0.9.4 - . + +## 2024-09-07 00:03:30 +### Changes +Based on: +- OpenAPI Doc 0.1.0 +- Speakeasy CLI 1.392.1 (2.411.9) https://github.com/speakeasy-api/speakeasy +### Generated +- [go v0.9.5] . +### Releases +- [Go v0.9.5] https://github.com/inkeep/ai-api-go/releases/tag/v0.9.5 - . \ No newline at end of file diff --git a/USAGE.md b/USAGE.md index 48b4d7e..eb1948b 100644 --- a/USAGE.md +++ b/USAGE.md @@ -13,7 +13,9 @@ func main() { s := aiapigo.New( aiapigo.WithSecurity(""), ) - request := components.CreateChatSessionWithChatResultInput{ + + ctx := context.Background() + res, err := s.ChatSession.Create(ctx, components.CreateChatSessionWithChatResultInput{ IntegrationID: "", ChatSession: components.ChatSessionInput{ Messages: []components.Message{ @@ -24,9 +26,7 @@ func main() { ), }, }, - } - ctx := context.Background() - res, err := s.ChatSession.Create(ctx, request) + }) if err != nil { log.Fatal(err) } diff --git a/chatapigo.go b/chatapigo.go index fa9e220..e740a40 100644 --- a/chatapigo.go +++ b/chatapigo.go @@ -147,9 +147,9 @@ func New(opts ...SDKOption) *ChatAPIGo { sdkConfiguration: sdkConfiguration{ Language: "go", OpenAPIDocVersion: "0.1.0", - SDKVersion: "0.9.4", - GenVersion: "2.404.11", - UserAgent: "speakeasy-sdk/go 0.9.4 2.404.11 0.1.0 github.com/inkeep/ai-api-go", + SDKVersion: "0.9.5", + GenVersion: "2.411.9", + UserAgent: "speakeasy-sdk/go 0.9.5 2.411.9 0.1.0 github.com/inkeep/ai-api-go", Hooks: hooks.New(), }, } diff --git a/chatsession.go b/chatsession.go index 2cc21aa..1da2191 100644 --- a/chatsession.go +++ b/chatsession.go @@ -205,7 +205,6 @@ func (s *ChatSession) Create(ctx context.Context, request components.CreateChatS if err != nil { return nil, fmt.Errorf("error reading response body: %w", err) } - return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) } case httpRes.StatusCode == 422: @@ -222,7 +221,6 @@ func (s *ChatSession) Create(ctx context.Context, request components.CreateChatS if err != nil { return nil, fmt.Errorf("error reading response body: %w", err) } - return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) } case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: @@ -232,14 +230,12 @@ func (s *ChatSession) Create(ctx context.Context, request components.CreateChatS if err != nil { return nil, fmt.Errorf("error reading response body: %w", err) } - return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) default: rawBody, err := io.ReadAll(httpRes.Body) if err != nil { return nil, fmt.Errorf("error reading response body: %w", err) } - return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) } @@ -428,7 +424,6 @@ func (s *ChatSession) Continue(ctx context.Context, chatSessionID string, contin if err != nil { return nil, fmt.Errorf("error reading response body: %w", err) } - return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) } case httpRes.StatusCode == 422: @@ -445,7 +440,6 @@ func (s *ChatSession) Continue(ctx context.Context, chatSessionID string, contin if err != nil { return nil, fmt.Errorf("error reading response body: %w", err) } - return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) } case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500: @@ -455,14 +449,12 @@ func (s *ChatSession) Continue(ctx context.Context, chatSessionID string, contin if err != nil { return nil, fmt.Errorf("error reading response body: %w", err) } - return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes) default: rawBody, err := io.ReadAll(httpRes.Body) if err != nil { return nil, fmt.Errorf("error reading response body: %w", err) } - return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) } diff --git a/docs/sdks/chatsession/README.md b/docs/sdks/chatsession/README.md index fc79730..14724be 100644 --- a/docs/sdks/chatsession/README.md +++ b/docs/sdks/chatsession/README.md @@ -21,8 +21,8 @@ package main import( aiapigo "github.com/inkeep/ai-api-go" - "github.com/inkeep/ai-api-go/models/components" "context" + "github.com/inkeep/ai-api-go/models/components" "log" ) @@ -30,7 +30,9 @@ func main() { s := aiapigo.New( aiapigo.WithSecurity(""), ) - request := components.CreateChatSessionWithChatResultInput{ + + ctx := context.Background() + res, err := s.ChatSession.Create(ctx, components.CreateChatSessionWithChatResultInput{ IntegrationID: "", ChatSession: components.ChatSessionInput{ Messages: []components.Message{ @@ -41,9 +43,7 @@ func main() { ), }, }, - } - ctx := context.Background() - res, err := s.ChatSession.Create(ctx, request) + }) if err != nil { log.Fatal(err) } @@ -90,8 +90,8 @@ package main import( aiapigo "github.com/inkeep/ai-api-go" - "github.com/inkeep/ai-api-go/models/components" "context" + "github.com/inkeep/ai-api-go/models/components" "log" ) @@ -99,18 +99,16 @@ func main() { s := aiapigo.New( aiapigo.WithSecurity(""), ) - var chatSessionID string = "" - continueChatSessionWithChatResultInput := components.ContinueChatSessionWithChatResultInput{ + ctx := context.Background() + res, err := s.ChatSession.Continue(ctx, "", components.ContinueChatSessionWithChatResultInput{ IntegrationID: "", Message: components.CreateMessageAssistantMessage( components.AssistantMessage{ Content: "", }, ), - } - ctx := context.Background() - res, err := s.ChatSession.Continue(ctx, chatSessionID, continueChatSessionWithChatResultInput) + }) if err != nil { log.Fatal(err) } diff --git a/gen.yaml b/gen.yaml index fa5d772..dfb2d2a 100644 --- a/gen.yaml +++ b/gen.yaml @@ -23,7 +23,7 @@ features: nameOverrides: 2.81.1 retries: 2.82.0 go: - version: 0.9.4 + version: 0.9.5 additionalDependencies: {} allowUnknownFieldsInWeakUnions: false clientServerStatusCodesAsErrors: true diff --git a/go.mod b/go.mod index 29549e5..2ac488e 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,10 @@ + module github.com/inkeep/ai-api-go go 1.20 require ( github.com/cenkalti/backoff/v4 v4.2.0 - github.com/ericlagergren/decimal v0.0.0-20221120152707-495c53812d05 + github.com/ericlagergren/decimal v0.0.0-20221120152707-495c53812d05 + github.com/spyzhov/ajson v0.8.0 ) diff --git a/internal/utils/json.go b/internal/utils/json.go index bd57d76..26c1ec6 100644 --- a/internal/utils/json.go +++ b/internal/utils/json.go @@ -487,30 +487,29 @@ func unmarshalValue(value json.RawMessage, v reflect.Value, tag reflect.StructTa v.Set(m) return nil case reflect.Slice, reflect.Array: - if bytes.Equal(value, []byte("null")) || !isComplexValueType(dereferenceTypePointer(typ.Elem())) { - if v.CanAddr() { - return json.Unmarshal(value, v.Addr().Interface()) - } else { - return json.Unmarshal(value, v.Interface()) - } - } - - var unmarhsaled []json.RawMessage + var unmarshaled []json.RawMessage - if err := json.Unmarshal(value, &unmarhsaled); err != nil { + if err := json.Unmarshal(value, &unmarshaled); err != nil { return err } - arrVal := v + arrVal := reflect.MakeSlice(typ, len(unmarshaled), len(unmarshaled)) - for _, value := range unmarhsaled { + for index, value := range unmarshaled { itemVal := reflect.New(typ.Elem()) if err := unmarshalValue(value, itemVal, tag, disallowUnknownFields); err != nil { return err } - arrVal = reflect.Append(arrVal, itemVal.Elem()) + arrVal.Index(index).Set(itemVal.Elem()) + } + + if v.Kind() == reflect.Pointer { + if v.IsNil() { + v.Set(reflect.New(typ)) + } + v = v.Elem() } v.Set(arrVal) diff --git a/internal/utils/requestbody.go b/internal/utils/requestbody.go index cee9da2..000226e 100644 --- a/internal/utils/requestbody.go +++ b/internal/utils/requestbody.go @@ -66,15 +66,16 @@ func serializeRequestBody(request interface{}, nullable, optional bool, requestF if tag != nil { // request object (non-flattened) requestVal := requestValType.FieldByName(requestFieldName) + val := reflect.ValueOf(requestVal.Interface()) if isNil(requestField.Type, requestVal) { if !nullable && optional { return nil, "", nil } - return serializeContentType(requestFieldName, tag.MediaType, requestVal, string(requestField.Tag)) + return serializeContentType(requestFieldName, tag.MediaType, val, string(requestField.Tag)) } - return serializeContentType(requestFieldName, tag.MediaType, requestVal, string(requestField.Tag)) + return serializeContentType(requestFieldName, tag.MediaType, val, string(requestField.Tag)) } } diff --git a/internal/utils/security.go b/internal/utils/security.go index c8503f9..19dfa6f 100644 --- a/internal/utils/security.go +++ b/internal/utils/security.go @@ -119,9 +119,14 @@ func parseSecurityScheme(headers, queryParams map[string]string, schemeTag *secu } if schemeType.Kind() == reflect.Struct { - if schemeTag.Type == "http" && schemeTag.SubType == "basic" { - handleBasicAuthScheme(headers, schemeVal.Interface()) - return + if schemeTag.Type == "http" { + switch schemeTag.SubType { + case "basic": + handleBasicAuthScheme(headers, schemeVal.Interface()) + return + case "custom": + return + } } for i := 0; i < schemeType.NumField(); i++ { @@ -171,6 +176,7 @@ func parseSecuritySchemeValue(headers, queryParams map[string]string, schemeTag switch schemeTag.SubType { case "bearer": headers[secTag.Name] = prefixBearer(valToString(val)) + case "custom": default: panic("not supported") }