You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/* Prepare the JSON string with relevant results to be sent to LLM for evaluation */
48
-
declare @s nvarchar(max) = (
49
-
select
50
-
[id], [name], [description], [notes], [details],
51
-
cast((1-distance_score)*100asint) as similiarity_score
52
-
from #s
53
-
where distance_score <0.85
54
-
order by distance_score for jsonpath
55
-
)
56
-
--select @s
19
+
selecttop(1) @cached_response = response from #c where d <0.3
20
+
if (@cached_response isnotnull) set @response = @cached_response
57
21
58
-
/* Create the prompt for the LLM */
59
-
declare @p nvarchar(max) =
60
-
json_object(
61
-
'messages': json_array(
62
-
json_object(
63
-
'role':'system',
64
-
'content':'
65
-
You as a system assistant who helps users find code samples the user can use to learn the topic they are interested in.
66
-
Samples are provided in an assitant message using a JSON Array with the following format: [{id, name, description, note, details, similiarity_score}].
67
-
Put in sample_summary output property a markdown short summary of the sample using the provided description, notes, and details.
68
-
Use only the provided samples to help you answer the user''s question.
69
-
Make sure to use details, notes, and description that are provided in each sample are used only with that sample.
70
-
If there are related links or repos in the details of a sample that is included in the answer, include them in the short summary. Include links only if they are related to the sample and if they are available in the note or details of that sample.
71
-
If the question cannot be answered by the provided samples, you must say that you don''t know.
72
-
If asked question is about topics you don''t know, answer that you don''t know.
73
-
'
74
-
),
75
-
json_object(
76
-
'role':'assistant',
77
-
'content': 'The available samples are the following:'
78
-
),
79
-
json_object(
80
-
'role':'assistant',
81
-
'content': coalesce(@s, 'No samples found for the requested search text.')
82
-
),
83
-
json_object(
84
-
'role':'user',
85
-
'content': + @text
86
-
)
87
-
),
88
-
'temperature': 0.2,
89
-
'frequency_penalty': 0,
90
-
'presence_penalty': 0,
91
-
'stop': null
92
-
);
22
+
/* If no cached response is available then generate a fresh answer */
select'Generator'as [error], -1as [error_code], 'Query not provided'as [error_message]
10
+
return-1
11
+
end
12
+
13
+
if (@source isnull) begin
14
+
select'Generator'as [error], -1as [error_code], 'Sample list not provided'as [error_message]
15
+
return-1
16
+
end
17
+
18
+
19
+
/* Create the prompt for the LLM */
20
+
declare @p nvarchar(max) =
21
+
json_object(
22
+
'messages': json_array(
23
+
json_object(
24
+
'role':'system',
25
+
'content':'
26
+
You as a system assistant who helps users find code samples the user can use to learn the topic they are interested in.
27
+
Samples are provided in an assitant message using a JSON Array with the following format: [{id, name, description, note, details, similiarity_score}].
28
+
Put in sample_summary output property a markdown short summary of the sample using the provided description, notes, and details.
29
+
Use only the provided samples to help you answer the question.
30
+
Use only the informations available in the provided JSON to answer the question.
31
+
Make sure to use details, notes, and description that are provided in each sample are used only with that sample.
32
+
If there are related links or repos in the details of a sample that is included in the answer, include them in the short summary. Include links only if they are related to the sample and if they are available in the note or details of that sample.
33
+
If the question cannot be answered by the provided samples, you must say that you don''t know.
34
+
If asked question is about topics you don''t know, answer that you don''t know.
35
+
If no samples are provided, say that you canno''t answer as no samples have been found.
36
+
'
37
+
),
38
+
json_object(
39
+
'role':'assistant',
40
+
'content': 'The available samples are the following:'
41
+
),
42
+
json_object(
43
+
'role':'assistant',
44
+
'content': coalesce(@source, '')
45
+
),
46
+
json_object(
47
+
'role':'user',
48
+
'content': + @query_text
49
+
)
50
+
),
51
+
'temperature': 0.2,
52
+
'frequency_penalty': 0,
53
+
'presence_penalty': 0,
54
+
'stop': null
55
+
);
56
+
57
+
declare @js nvarchar(max) = N'{
58
+
"type": "json_schema",
59
+
"json_schema": {
60
+
"name": "samples",
61
+
"strict": true,
62
+
"schema": {
63
+
"type": "object",
64
+
"properties": {
65
+
"samples": {
66
+
"type": "array",
67
+
"items": {
68
+
"type": "object",
69
+
"properties": {
70
+
"result_position": {
71
+
"type": "number"
72
+
},
73
+
"id": {
74
+
"type": "number"
75
+
},
76
+
"sample_summary": {
77
+
"type": "string"
78
+
},
79
+
"thoughts": {
80
+
"type": "string"
81
+
}
82
+
},
83
+
"required": [
84
+
"id",
85
+
"sample_summary",
86
+
"thoughts",
87
+
"result_position"
88
+
],
89
+
"additionalProperties": false
90
+
}
91
+
}
92
+
},
93
+
"required": ["samples"],
94
+
"additionalProperties": false
95
+
}
96
+
}
97
+
}'
98
+
99
+
set @p = json_modify(@p, '$.response_format', json_query(@js))
0 commit comments