mirror of
https://github.com/hanzo-go/sdk.git
synced 2026-11-20 20:13:42 +00:00
267 lines
9.1 KiB
Go
267 lines
9.1 KiB
Go
/*
|
|
Hanzo Cloud API
|
|
|
|
The Hanzo Cloud API as a customer calls it: every operation under /v1/ except the operator's admin product, relay routes, legacy spellings and capabilities still reached by flag. Tagged by product: the first path segment after /v1/.
|
|
|
|
API version: v1
|
|
*/
|
|
|
|
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
|
|
|
|
package hanzoai
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"io"
|
|
"net/http"
|
|
"net/url"
|
|
)
|
|
|
|
// AskAPIService AskAPI service
|
|
type AskAPIService service
|
|
|
|
type AskAPIPostAskRequest struct {
|
|
ctx context.Context
|
|
ApiService *AskAPIService
|
|
askRequest *AskRequest
|
|
}
|
|
|
|
func (r AskAPIPostAskRequest) AskRequest(askRequest AskRequest) AskAPIPostAskRequest {
|
|
r.askRequest = &askRequest
|
|
return r
|
|
}
|
|
|
|
func (r AskAPIPostAskRequest) Execute() (*http.Response, error) {
|
|
return r.ApiService.PostAskExecute(r)
|
|
}
|
|
|
|
/*
|
|
PostAsk Ask a grounded question about your own org
|
|
|
|
Answers a natural-language question about the CALLER'S OWN org, from real figures rather than from the model's memory.
|
|
|
|
The question is classified to a grounded domain, that domain's read runs IN-PROCESS under the caller's own credentials, and only then is the result narrated. So the figures and their sources are the domain's, resolved before any model call and never altered by one — a wrong answer is a wrong query, never an invention.
|
|
|
|
Domains: books (the org's ledger), projects (what is built and what of it is deployed), git (the org's repositories and what changed in them), and web (search, news, research, deep). A validated principal is required; the answer is scoped to that principal's org and nothing else.
|
|
|
|
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
|
|
@return AskAPIPostAskRequest
|
|
*/
|
|
func (a *AskAPIService) PostAsk(ctx context.Context) AskAPIPostAskRequest {
|
|
return AskAPIPostAskRequest{
|
|
ApiService: a,
|
|
ctx: ctx,
|
|
}
|
|
}
|
|
|
|
// Execute executes the request
|
|
func (a *AskAPIService) PostAskExecute(r AskAPIPostAskRequest) (*http.Response, error) {
|
|
var (
|
|
localVarHTTPMethod = http.MethodPost
|
|
localVarPostBody interface{}
|
|
formFiles []formFile
|
|
)
|
|
|
|
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "AskAPIService.PostAsk")
|
|
if err != nil {
|
|
return nil, &GenericOpenAPIError{error: err.Error()}
|
|
}
|
|
|
|
localVarPath := localBasePath + "/v1/ask"
|
|
|
|
localVarHeaderParams := make(map[string]string)
|
|
localVarQueryParams := url.Values{}
|
|
localVarFormParams := url.Values{}
|
|
|
|
// to determine the Content-Type header
|
|
localVarHTTPContentTypes := []string{"application/json"}
|
|
|
|
// set Content-Type header
|
|
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
|
|
if localVarHTTPContentType != "" {
|
|
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
|
|
}
|
|
|
|
// to determine the Accept header
|
|
localVarHTTPHeaderAccepts := []string{}
|
|
|
|
// set Accept header
|
|
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
|
|
if localVarHTTPHeaderAccept != "" {
|
|
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
|
|
}
|
|
// body params
|
|
localVarPostBody = r.askRequest
|
|
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
localVarHTTPResponse, err := a.client.callAPI(req)
|
|
if err != nil || localVarHTTPResponse == nil {
|
|
return localVarHTTPResponse, err
|
|
}
|
|
|
|
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
|
|
localVarHTTPResponse.Body.Close()
|
|
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
|
|
if err != nil {
|
|
return localVarHTTPResponse, err
|
|
}
|
|
|
|
if localVarHTTPResponse.StatusCode >= 300 {
|
|
newErr := &GenericOpenAPIError{
|
|
body: localVarBody,
|
|
error: localVarHTTPResponse.Status,
|
|
}
|
|
return localVarHTTPResponse, newErr
|
|
}
|
|
|
|
return localVarHTTPResponse, nil
|
|
}
|
|
|
|
type AskAPIResearchWebRequest struct {
|
|
ctx context.Context
|
|
ApiService *AskAPIService
|
|
askWebQuestion *AskWebQuestion
|
|
}
|
|
|
|
func (r AskAPIResearchWebRequest) AskWebQuestion(askWebQuestion AskWebQuestion) AskAPIResearchWebRequest {
|
|
r.askWebQuestion = &askWebQuestion
|
|
return r
|
|
}
|
|
|
|
func (r AskAPIResearchWebRequest) Execute() (*AskReport, *http.Response, error) {
|
|
return r.ApiService.ResearchWebExecute(r)
|
|
}
|
|
|
|
/*
|
|
ResearchWeb Research a question on the live web and answer it with sources cited
|
|
|
|
Researches a question on the live web and answers it with its
|
|
sources cited.
|
|
|
|
This is the DEEP one. It plans the question into topics, runs several web
|
|
searches, FETCHES AND READS the pages it finds, ranks them, and writes a
|
|
grounded answer with inline markdown citations. Use it for anything that needs
|
|
evidence, comparison or current fact — "what changed in X", "compare A and B",
|
|
"is this claim true". For a plain list of links, use search_web instead; for
|
|
one page you already have the URL of, use read_page.
|
|
|
|
`mode` buys depth: `search` is a single fast pass, `news` biases to recency,
|
|
`research` plans and iterates, `deep` surveys widest. `sources` narrows the
|
|
evidence to `web`, `news`, `academic`, `github`, `reddit` or `x` — each becomes
|
|
a site-scoped search, which is how this reaches X/Twitter posts.
|
|
|
|
EVERY CITATION IS A PAGE THIS CALL FETCHED. That is a property of the text and
|
|
not an instruction to the model: each source is fenced with a per-request nonce
|
|
so a crawled page cannot print itself a source number, and every markdown link
|
|
in the answer is checked against the gathered set before it is returned. So a
|
|
link in `answer` always appears in `sources`, and a page that was not read
|
|
cannot be cited.
|
|
|
|
It is BOUNDED and it degrades rather than failing: a mode's rounds, wall clock
|
|
and token ceiling all cap it, and a search that finds little or a page that
|
|
will not load yields a thinner answer, never an error. A validated principal is
|
|
required, and the answer is billed once to that principal's org.
|
|
|
|
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
|
|
@return AskAPIResearchWebRequest
|
|
*/
|
|
func (a *AskAPIService) ResearchWeb(ctx context.Context) AskAPIResearchWebRequest {
|
|
return AskAPIResearchWebRequest{
|
|
ApiService: a,
|
|
ctx: ctx,
|
|
}
|
|
}
|
|
|
|
// Execute executes the request
|
|
//
|
|
// @return AskReport
|
|
func (a *AskAPIService) ResearchWebExecute(r AskAPIResearchWebRequest) (*AskReport, *http.Response, error) {
|
|
var (
|
|
localVarHTTPMethod = http.MethodPost
|
|
localVarPostBody interface{}
|
|
formFiles []formFile
|
|
localVarReturnValue *AskReport
|
|
)
|
|
|
|
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "AskAPIService.ResearchWeb")
|
|
if err != nil {
|
|
return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
|
|
}
|
|
|
|
localVarPath := localBasePath + "/v1/ask/web"
|
|
|
|
localVarHeaderParams := make(map[string]string)
|
|
localVarQueryParams := url.Values{}
|
|
localVarFormParams := url.Values{}
|
|
if r.askWebQuestion == nil {
|
|
return localVarReturnValue, nil, reportError("askWebQuestion is required and must be specified")
|
|
}
|
|
|
|
// to determine the Content-Type header
|
|
localVarHTTPContentTypes := []string{"application/json"}
|
|
|
|
// set Content-Type header
|
|
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
|
|
if localVarHTTPContentType != "" {
|
|
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
|
|
}
|
|
|
|
// to determine the Accept header
|
|
localVarHTTPHeaderAccepts := []string{"application/json", "application/problem+json"}
|
|
|
|
// set Accept header
|
|
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
|
|
if localVarHTTPHeaderAccept != "" {
|
|
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
|
|
}
|
|
// body params
|
|
localVarPostBody = r.askWebQuestion
|
|
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
|
|
if err != nil {
|
|
return localVarReturnValue, nil, err
|
|
}
|
|
|
|
localVarHTTPResponse, err := a.client.callAPI(req)
|
|
if err != nil || localVarHTTPResponse == nil {
|
|
return localVarReturnValue, localVarHTTPResponse, err
|
|
}
|
|
|
|
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
|
|
localVarHTTPResponse.Body.Close()
|
|
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
|
|
if err != nil {
|
|
return localVarReturnValue, localVarHTTPResponse, err
|
|
}
|
|
|
|
if localVarHTTPResponse.StatusCode >= 300 {
|
|
newErr := &GenericOpenAPIError{
|
|
body: localVarBody,
|
|
error: localVarHTTPResponse.Status,
|
|
}
|
|
var v ProblemDetails
|
|
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
|
|
if err != nil {
|
|
newErr.error = err.Error()
|
|
return localVarReturnValue, localVarHTTPResponse, newErr
|
|
}
|
|
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
|
|
newErr.model = v
|
|
return localVarReturnValue, localVarHTTPResponse, newErr
|
|
}
|
|
|
|
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
|
|
if err != nil {
|
|
newErr := &GenericOpenAPIError{
|
|
body: localVarBody,
|
|
error: err.Error(),
|
|
}
|
|
return localVarReturnValue, localVarHTTPResponse, newErr
|
|
}
|
|
|
|
return localVarReturnValue, localVarHTTPResponse, nil
|
|
}
|