feat(qa): add web search provider port (#60)
This commit is contained in:
@ -9,14 +9,15 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
ErrNotFound = errors.New("qa_not_found")
|
||||
ErrInvalid = errors.New("qa_invalid_request")
|
||||
ErrConflict = errors.New("qa_idempotency_conflict")
|
||||
ErrBusy = errors.New("qa_question_in_progress")
|
||||
ErrLimit = errors.New("qa_context_limit")
|
||||
ErrModel = errors.New("qa_model_unavailable")
|
||||
ErrProvider = errors.New("qa_provider_failed")
|
||||
ErrRateLimited = errors.New("qa_rate_limited")
|
||||
ErrWebSearchUnsupported = errors.New("web_search_unsupported")
|
||||
ErrNotFound = errors.New("qa_not_found")
|
||||
ErrInvalid = errors.New("qa_invalid_request")
|
||||
ErrConflict = errors.New("qa_idempotency_conflict")
|
||||
ErrBusy = errors.New("qa_question_in_progress")
|
||||
ErrLimit = errors.New("qa_context_limit")
|
||||
ErrModel = errors.New("qa_model_unavailable")
|
||||
ErrProvider = errors.New("qa_provider_failed")
|
||||
ErrRateLimited = errors.New("qa_rate_limited")
|
||||
)
|
||||
|
||||
const CallsPerMinute = 10
|
||||
@ -38,22 +39,27 @@ const MaxContextBytes = 128000
|
||||
const PendingLifetime = 2 * time.Minute
|
||||
|
||||
type Question struct {
|
||||
RequestID string `json:"request_id"`
|
||||
Passage string `json:"passage"`
|
||||
Question string `json:"question"`
|
||||
UseWebSearch bool `json:"use_web_search"`
|
||||
RequestID string `json:"request_id"`
|
||||
Passage string `json:"passage"`
|
||||
Question string `json:"question"`
|
||||
}
|
||||
type Turn struct {
|
||||
ID string `json:"id"`
|
||||
RequestID string `json:"request_id"`
|
||||
Passage string `json:"passage"`
|
||||
Question string `json:"question"`
|
||||
Answer string `json:"answer"`
|
||||
Status string `json:"status"`
|
||||
FailureCode string `json:"failure_code,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
Replayed bool `json:"replayed"`
|
||||
UseWebSearch bool `json:"use_web_search"`
|
||||
WebSearchPerformed bool `json:"web_search_performed"`
|
||||
Citations []Citation `json:"citations"`
|
||||
ID string `json:"id"`
|
||||
RequestID string `json:"request_id"`
|
||||
Passage string `json:"passage"`
|
||||
Question string `json:"question"`
|
||||
Answer string `json:"answer"`
|
||||
Status string `json:"status"`
|
||||
FailureCode string `json:"failure_code,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
Replayed bool `json:"replayed"`
|
||||
}
|
||||
type Conversation struct {
|
||||
WebSearchSupported bool `json:"web_search_supported"`
|
||||
ID string `json:"id"`
|
||||
SummaryID string `json:"summary_id"`
|
||||
Mode string `json:"mode"`
|
||||
@ -72,20 +78,22 @@ type Exchange struct {
|
||||
|
||||
// StatelessRequest deliberately has no article/source field.
|
||||
type StatelessRequest struct {
|
||||
Summary string `json:"summary"`
|
||||
Language string `json:"language"`
|
||||
History []Exchange `json:"history"`
|
||||
Passage string `json:"passage"`
|
||||
Question string `json:"question"`
|
||||
UseWebSearch bool `json:"use_web_search,omitempty"`
|
||||
Summary string `json:"summary"`
|
||||
Language string `json:"language"`
|
||||
History []Exchange `json:"history"`
|
||||
Passage string `json:"passage"`
|
||||
Question string `json:"question"`
|
||||
}
|
||||
type Capabilities struct {
|
||||
Create bool `json:"create"`
|
||||
Continue bool `json:"continue"`
|
||||
Purge bool `json:"purge"`
|
||||
WebSearch bool `json:"web_search"`
|
||||
Create bool `json:"create"`
|
||||
Continue bool `json:"continue"`
|
||||
Purge bool `json:"purge"`
|
||||
}
|
||||
type Provider interface {
|
||||
Capabilities() Capabilities
|
||||
Answer(context.Context, StatelessRequest) (string, error)
|
||||
Answer(context.Context, StatelessRequest) (AnswerResult, error)
|
||||
}
|
||||
|
||||
// A future session adapter must implement all three lifecycle operations before
|
||||
@ -111,7 +119,7 @@ type Repository interface {
|
||||
CancelQAQuestion(context.Context, string, string, string) error
|
||||
GetQAConversation(context.Context, string, string, time.Time) (Conversation, error)
|
||||
BeginQAQuestion(context.Context, string, string, Question, time.Time) (Work, error)
|
||||
FinishQAQuestion(context.Context, string, string, string, string, string, time.Time) (Turn, error)
|
||||
FinishQAQuestion(context.Context, string, string, string, AnswerResult, string, time.Time) (Turn, error)
|
||||
DeleteQAConversation(context.Context, string, string) error
|
||||
PurgeExpiredQASources(context.Context, time.Time) error
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user