Skip to content

Commit 2fa8c17

Browse files
authored
Merge pull request #81 from AddSearch/sc-11492/conversational-search-to-be-named-as-ai-answers
[sc-11492] refactor: "conversational search" to become "ai answers"
2 parents 51aa9c3 + 487806b commit 2fa8c17

File tree

5 files changed

+48
-16
lines changed

5 files changed

+48
-16
lines changed

README.md

+32
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,38 @@ function callback(configurationObject) {
500500
client.setApiRequestInterceptor(callback, option);
501501
```
502502

503+
## AI Answers API
504+
505+
#### Fetch AI answers
506+
507+
```js
508+
// Get AI generated answer with a question
509+
client.aiAnswers('A question to get AI generated answers', callback);
510+
```
511+
512+
Example of callback function and how the response looks like:
513+
```js
514+
callbackFn = function (response) {
515+
516+
console.log(response);
517+
518+
// response object contains the answer
519+
// {
520+
// "answer": "The answer to the question",
521+
// "conversation_id": "31f33b53-1fe1-4734-884f-fefa470f1389",
522+
// "ids": <array of ids belonging to source documents>, for example ['073010f023db7c6d558123f73a9b4f82', '821f7bea12daf0eda17ba2755979f7a5'],
523+
// "source_documents": <documents that provide context for AI generated answers, the object of this field looks similarly to the response of regular SearchApi result>
524+
// }
525+
};
526+
````
527+
528+
#### Send Sentiment Analysis
529+
530+
```js
531+
// possible sentiment_value: positive, negative
532+
client.putSentimentClick('conversation_id', 'sentiment_value');
533+
```
534+
503535
## Indexing API
504536

505537
With the Indexing API, you can fetch, create, update, and delete single documents or batches of

src/conversational-search-interactions-api.ts renamed to src/ai-answers-interactions-api.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
import 'es6-promise/auto';
4-
import { RESPONSE_SERVER_ERROR, conversationalSearchInteractionsInstance } from './api';
4+
import { RESPONSE_SERVER_ERROR, aiAnswersInteractionsInstance } from './api';
55

66
const putSentimentClick = (
77
apiHostname: string,
@@ -10,7 +10,7 @@ const putSentimentClick = (
1010
sentimentValue: 'positive' | 'negative' | 'neutral'
1111
): Promise<boolean> => {
1212
return new Promise((resolve, reject) => {
13-
conversationalSearchInteractionsInstance
13+
aiAnswersInteractionsInstance
1414
.put(`https://${apiHostname}/v2/indices/${sitekey}/conversations/${conversationId}/rating`, {
1515
value: sentimentValue === 'positive' ? 1 : sentimentValue === 'negative' ? -1 : 0
1616
})

src/api.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import axios, { AxiosInstance, InternalAxiosRequestConfig } from 'axios';
22

33
const apiInstance: AxiosInstance = axios.create();
44
const statsInstance: AxiosInstance = axios.create();
5-
const conversationalSearchInteractionsInstance: AxiosInstance = axios.create();
5+
const aiAnswersInteractionsInstance: AxiosInstance = axios.create();
66

77
const RESPONSE_BAD_REQUEST = 400;
88
const RESPONSE_SERVER_ERROR = 500;
@@ -38,7 +38,7 @@ const setRequestInterceptor = (
3838
export {
3939
apiInstance,
4040
statsInstance,
41-
conversationalSearchInteractionsInstance,
41+
aiAnswersInteractionsInstance,
4242
setRequestInterceptor,
4343
RESPONSE_BAD_REQUEST,
4444
RESPONSE_SERVER_ERROR

src/apifetch.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ const executeApiFetch: ExecuteApiFetch = function (
108108
// Validate query type
109109
if (
110110
type !== 'search' &&
111-
type !== 'conversational-search' &&
111+
type !== 'ai-answers' &&
112112
type !== 'suggest' &&
113113
type !== 'autocomplete' &&
114114
type !== 'recommend'
@@ -259,8 +259,8 @@ const executeApiFetch: ExecuteApiFetch = function (
259259
queryParamsString;
260260
}
261261

262-
// Conversational Search
263-
else if (type === 'conversational-search') {
262+
// Ai Answers
263+
else if (type === 'ai-answers') {
264264
// TODO use apiHostname instead of hardcoded URL
265265
apiInstance
266266
.post(`https://api.addsearch.com/v2/indices/${sitekey}/conversations`, {
@@ -273,7 +273,7 @@ const executeApiFetch: ExecuteApiFetch = function (
273273
cb({
274274
error: {
275275
response: RESPONSE_SERVER_ERROR,
276-
message: 'Could not get conversational search response in the expected data format'
276+
message: 'Could not get ai-answers response in the expected data format'
277277
}
278278
});
279279
}
@@ -347,7 +347,7 @@ const executeApiFetch: ExecuteApiFetch = function (
347347
apiEndpoint = 'https://' + apiHostname + '/v1/' + apiPath;
348348
}
349349

350-
if (type !== 'conversational-search') {
350+
if (type !== 'ai-answers') {
351351
apiInstance
352352
.get(apiEndpoint as string)
353353
.then(function (response: AxiosResponse<GenericApiResponse>) {

src/index.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
deleteDocument
1212
} from './indexingapi';
1313
import sendStats from './stats';
14-
import { putSentimentClick } from './conversational-search-interactions-api';
14+
import { putSentimentClick } from './ai-answers-interactions-api';
1515
import SettingsManager, {
1616
Settings,
1717
PersonalizationEvent,
@@ -66,7 +66,7 @@ class AddSearchClient {
6666
private userTokenInPersonalization: string;
6767
private useStatsSessionId = false;
6868
private throttledSearchFetch?: ExecuteApiFetch;
69-
private throttledConversationalSearchFetch?: ExecuteApiFetch;
69+
private throttledAiAnswersFetch?: ExecuteApiFetch;
7070
private throttledSuggestionsFetch?: ExecuteApiFetch;
7171
private throttledRecommendationFetch?: ExecuteApiFetch;
7272
private throttledAutocompleteFetch?: ExecuteApiFetch;
@@ -123,21 +123,21 @@ class AddSearchClient {
123123
);
124124
}
125125

126-
conversationalSearch(keyword: string, callback: ApiFetchCallback): void {
126+
aiAnswers(keyword: string, callback: ApiFetchCallback): void {
127127
this.settings.setCallback(() => callback);
128128
this.settings.setKeyword(keyword);
129129

130-
if (!this.throttledConversationalSearchFetch) {
131-
this.throttledConversationalSearchFetch = throttle(
130+
if (!this.throttledAiAnswersFetch) {
131+
this.throttledAiAnswersFetch = throttle(
132132
this.settings.getSettings().throttleTimeMs,
133133
executeApiFetch
134134
);
135135
}
136136

137-
this.throttledConversationalSearchFetch(
137+
this.throttledAiAnswersFetch(
138138
this.apiHostname,
139139
this.sitekey,
140-
'conversational-search',
140+
'ai-answers',
141141
this.settings.getSettings(),
142142
callback
143143
);

0 commit comments

Comments
 (0)