-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update client api with heterogenous structs support (#4)
- Loading branch information
Showing
17 changed files
with
587 additions
and
260 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
## | ||
## Unit Tests & Coverage | ||
## | ||
name: check | ||
on: | ||
pull_request: | ||
types: | ||
- opened | ||
- synchronize | ||
|
||
jobs: | ||
|
||
unit: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
module: ["."] | ||
|
||
|
||
steps: | ||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version: "1.22" | ||
|
||
- uses: actions/checkout@v4 | ||
|
||
- name: go build | ||
working-directory: ${{ matrix.module }} | ||
run: | | ||
go build ./... | ||
- name: go test | ||
working-directory: ${{ matrix.module }} | ||
run: | | ||
go test -coverprofile=profile.cov $(go list ./... | grep -v /examples/) | ||
env: | ||
## GOPATH required to build serverless app inside unittest | ||
GOPATH: /home/runner/work/${{ github.event.repository.name }}/go | ||
|
||
- uses: shogo82148/actions-goveralls@v1 | ||
continue-on-error: true | ||
with: | ||
working-directory: ${{ matrix.module }} | ||
path-to-profile: profile.cov | ||
flag-name: ${{ matrix.module }} | ||
parallel: true | ||
|
||
- uses: dominikh/staticcheck-action@v1.3.1 | ||
with: | ||
install-go: false | ||
working-directory: ${{ matrix.module }} | ||
|
||
finish: | ||
needs: unit | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: shogo82148/actions-goveralls@v1 | ||
with: | ||
parallel-finished: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// | ||
// Copyright (C) 2024 Dmitry Kolesnikov | ||
// | ||
// This file may be modified and distributed under the terms | ||
// of the MIT license. See the LICENSE file for details. | ||
// https://github.com/kshard/optimum | ||
// | ||
|
||
package sentences | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/fogfish/curie" | ||
"github.com/fogfish/gurl/v2/http" | ||
ƒ "github.com/fogfish/gurl/v2/http/recv" | ||
ø "github.com/fogfish/gurl/v2/http/send" | ||
) | ||
|
||
// Client for reading/writing natural language text and searching for nearest neighbor. | ||
type Client struct { | ||
http.Stack | ||
|
||
host ø.Authority | ||
} | ||
|
||
// Creates the client for reading/writing natural language text and searching for nearest neighbor. | ||
func New(stack http.Stack, host string) *Client { | ||
return &Client{ | ||
Stack: stack, | ||
host: ø.Authority(host), | ||
} | ||
} | ||
|
||
// Write the sentence | ||
func (api *Client) Write(ctx context.Context, cask curie.IRI, bag []Sentence) error { | ||
if len(bag) == 0 { | ||
return nil | ||
} | ||
|
||
return api.IO(ctx, | ||
http.POST( | ||
ø.URI("%s/ds/%s/%s/object", api.host, curie.Prefix(cask), curie.Reference(cask)), | ||
ø.Accept.JSON, | ||
ø.ContentType.JSON, | ||
ø.Send(struct { | ||
V []Sentence `json:"object"` | ||
}{ | ||
V: bag, | ||
}), | ||
|
||
ƒ.Status.Accepted, | ||
), | ||
) | ||
} | ||
|
||
// Query nearest neighbor text to the given sample. | ||
func (api *Client) Query(ctx context.Context, cask curie.IRI, q Query) (*Result, error) { | ||
return http.IO[Result]( | ||
api.WithContext(ctx), | ||
http.GET( | ||
ø.URI("%s/ds/%s/%s", api.host, curie.Prefix(cask), curie.Reference(cask)), | ||
ø.Accept.JSON, | ||
ø.ContentType.JSON, | ||
ø.Send(struct { | ||
Q Query `json:"query"` | ||
}{ | ||
Q: q, | ||
}), | ||
|
||
ƒ.Status.OK, | ||
), | ||
) | ||
} |
Oops, something went wrong.