File size: 2,575 Bytes
95d599c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//                           _       _
// __      _____  __ ___   ___  __ _| |_ ___
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
//  \ V  V /  __/ (_| |\ V /| | (_| | ||  __/
//   \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
//
//  Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
//
//  CONTACT: hello@weaviate.io
//

package modulecapabilities

import (
	"context"

	"github.com/tailor-inc/graphql"
	"github.com/tailor-inc/graphql/language/ast"
	"github.com/weaviate/weaviate/entities/moduletools"
)

// GraphQLFieldFn generates graphql input fields
type GraphQLInputFieldFn = func(classname string) *graphql.InputObjectFieldConfig

// ExtractRequestParamsFn extracts specific generative API parameters from graphql queries
type ExtractRequestParamsFn = func(field *ast.ObjectField) interface{}

// GenerateDebugInformation exposes debug information
type GenerateDebugInformation struct {
	Prompt string
}

// GenerateResponse defines generative response. Params files hold module specific
// response parameters
type GenerateResponse struct {
	Result *string
	Params map[string]interface{}
	Debug  *GenerateDebugInformation
}

// GenerateProperties defines the properties to be supplied as part of the generative request.
// They must be differentiated at this point due to the different ways third-parties handle them.
type GenerateProperties struct {
	Text map[string]string
	Blob map[string]*string
}

// GenerativeClient defines generative client
type GenerativeClient interface {
	GenerateSingleResult(ctx context.Context,
		properties *GenerateProperties, prompt string, requestParams interface{}, debug bool, cfg moduletools.ClassConfig,
	) (*GenerateResponse, error)
	GenerateAllResults(ctx context.Context,
		properties []*GenerateProperties, task string, requestParams interface{}, debug bool, cfg moduletools.ClassConfig,
	) (*GenerateResponse, error)
}

// GenerativeProperty defines all needed additional request / response parameters
// only client setting is manadatory as we can have generative modules
// that don't expose any additional request / response params.
type GenerativeProperty struct {
	Client                       GenerativeClient
	RequestParamsFunction        GraphQLInputFieldFn
	ResponseParamsFunction       GraphQLFieldFn
	ExtractRequestParamsFunction ExtractRequestParamsFn
}

// AdditionalGenerativeProperties groups whole interface methods needed
// for adding the capability of additional generative properties
type AdditionalGenerativeProperties interface {
	AdditionalGenerativeProperties() map[string]GenerativeProperty
}