Add OpenAI Mock Server (#31)

* add constants for completions, refactor usage, add test server

Signed-off-by: Oleg <97077423+RobotSail@users.noreply.github.com>

* append v1 endpoint to test

Signed-off-by: Oleg <97077423+RobotSail@users.noreply.github.com>

* add makefile for easy targets

Signed-off-by: Oleg <97077423+RobotSail@users.noreply.github.com>

* lint files & add linter

Signed-off-by: Oleg <97077423+RobotSail@users.noreply.github.com>

* disable real API tests in short mode

Signed-off-by: Oleg <97077423+RobotSail@users.noreply.github.com>

Signed-off-by: Oleg <97077423+RobotSail@users.noreply.github.com>
This commit is contained in:
Oleg
2022-08-11 05:29:23 -04:00
committed by GitHub
parent 8b463ceb2b
commit d63df93c65
12 changed files with 619 additions and 61 deletions

View File

@@ -24,7 +24,7 @@ type SearchRequest struct {
User string `json:"user,omitempty"`
}
// SearchResult represents single result from search API
// SearchResult represents single result from search API.
type SearchResult struct {
Document int `json:"document"`
Object string `json:"object"`
@@ -32,14 +32,18 @@ type SearchResult struct {
Metadata string `json:"metadata"` // 2*
}
// SearchResponse represents a response structure for search API
// SearchResponse represents a response structure for search API.
type SearchResponse struct {
SearchResults []SearchResult `json:"data"`
Object string `json:"object"`
}
// Search — perform a semantic search api call over a list of documents.
func (c *Client) Search(ctx context.Context, engineID string, request SearchRequest) (response SearchResponse, err error) {
func (c *Client) Search(
ctx context.Context,
engineID string,
request SearchRequest,
) (response SearchResponse, err error) {
var reqBytes []byte
reqBytes, err = json.Marshal(request)
if err != nil {