Skip to main content

Chat GPT Integration

We have an integration to Chat-GPT in our platform, which is implemented for search purpose.

Demo

For complete step-by-step instruction see Quick Start Demo

Create config

  1. Go to Quasiris Search Cloud
  2. Enter 'Config' in the top left search input
  3. Click on 'Config'
  4. Create a config with name 'chat-gpt-integration-config'
  5. In tab 'Config' post a json
    {
    "type": "searchResultRefinement",
    "searchResultRefinement": {
    "requestTemplate": "Title is '${(searchResults['chat-gpt-quick-start-demo'].documents[0].document.title)!\"\"}'",
    "appendToSearchContextKey": "biking",
    "contextString": "This is a chat for the application, where I would enter a query, and you would answer the question from this query. Possible answers are only yes, no, unknown. Don't add any comments or symbols. ONLY 'yes', 'no', 'unknown'. \nWe are at biking shop, I want to know if the title user enter somehow connected to biking topic."
    }
    }
  6. Replace 'chat-gpt-quick-start-demo' with the name of your search config, where you want to use it
  7. Click 'Save'

Json structure

{
"type": "searchResultRefinement",
"searchResultRefinement": {
"requestTemplate": "Title is '${(searchResults['chat-gpt-quick-start-demo'].documents[0].document.title)!\"\"}'",
"appendToSearchContextKey": "biking",
"contextString": "This is a chat for the application, where I would enter a query, and you would answer the question from this query. Possible answers are only yes, no, unknown. Don't add any comments or symbols. ONLY 'yes', 'no', 'unknown'. \nWe are at biking shop, I want to know if the title user enter somehow connected to biking topic."
}
}
  • type - must be searchResultRefinement to use it with ChatGPT filter
  • searchResultRefinement.requestTemplate - freemarker template, which would be used to send requests to ChatGPT
  • searchResultRefinement.appendToSearchContextKey - an alphanumeric value to determine json key where we put a ChatGPT answer in search response
  • searchResultRefinement.contextString - a context for ChatGPT. A string where you would enter the instructions for chat GPT and preconfigure what it needs to do.
  1. Go to your search config
  2. Go to 'Pipeline' tab
  3. Choose 'Custom' pipeline type
  4. Post yaml
!!com.quasiris.qsf.pipeline.Pipeline
id: search-pipeline
timeout: 4000
filterList:
- !!com.quasiris.qsf.pipeline.filter.DebugFilter
active: true
id: search-pipeline.DebugFilter
- !!com.quasiris.qsc.search.service.query.QscSearchQueryFilter
active: true
id: search-pipeline.QscSearchQueryFilter
- !!com.quasiris.qsc.search.service.rules.QueryRuleFilter
active: true
baseUrl: {{ searchIndexBaseUrl }}
env: {{ env }}
id: queryRuleFilter
- !!com.quasiris.qsf.pipeline.filter.elastic.ElasticFilter
active: true
baseUrl: {{searchIndexBaseUrl}}
id: searchElasticFilter
resultSetId: {{searchCode}}
queryTransformer: !!com.quasiris.qsc.search.service.QscSearchQueryTransformer
profile: {{profile}}
searchResultTransformer: !!com.quasiris.qsc.search.service.QscResultTransformer
elasticSearchClient: !!com.quasiris.qsf.commons.elasticsearch.client.ElasticSearchClient
useApacheClient: false
- !!com.quasiris.qsf.pipeline.filter.ConditionFilter
active: true
condition: !!com.quasiris.qsf.pipeline.filter.conditions.EmptyResultCondition
resultSetId: {{searchCode}}
id: conditional.isSpellcheck
pipeline:
filterList:
- !!com.quasiris.qsf.pipeline.filter.TokenizerFilter
active: true
id: qsc-spellcheck.TokenizerFilter
- !!com.quasiris.qsf.pipeline.filter.elastic.SpellCheckElasticFilter
active: true
baseUrl: {{searchIndexBaseUrl}}-spellcheck
id: qsc-spellcheck.SpellCheckElasticFilter
maxTokenLenght: 10
minTokenLenght: 4
minTokenWeight: 1
sentenceScoringEnabled: false
restartPipelineId: search-pipeline
id: qsc-spellcheck
timeout: 1000
- !!com.quasiris.qsf.pipeline.filter.QSFQLResponseRefinementFilter
active: true
id: search-pipeline.QSFQLResponseRefinementFilter
resultId: {{searchCode}}
- !!com.quasiris.qsc.chatgpt.filter.ChatGPTFilter
active: true
apiKey: "chat-gpt-integration-config"
modelId: "gpt-3.5-turbo"
chatGptConfigCode: "chat-gpt-config"
resultSetId: {{searchCode}}
maxTokens: 10
timeoutMills: 8000
temperature: 0
- !!com.quasiris.qsf.pipeline.filter.elastic.ElasticTrackingFilter
active: true
baseUrl: {{trackingIndexBaseUrl}}
customParameter:
app: search
searchCode: {{searchCode}}
tenantCode: {{tenant}}
env: {{env}}
id: search-pipeline.ElasticTrackingFilter
idFieldName: id
resultSetId: {{searchCode}}
rotation: none
trackingId: null
  1. Click 'Save'

Yaml structure

- !!com.quasiris.qsc.chatgpt.filter.ChatGPTFilter
active: true
apiKey: "chat-gpt-api-key"
modelId: "gpt-3.5-turbo"
chatGptConfigCode: "chat-gpt-config"
resultSetId: {{searchCode}}
maxTokens: 10
timeoutMills: 8000
temperature: 0
  • active - specify if filter must be executed
  • apiKey - api key for ChatGPT
  • modelId - model id of ChatGPT
  • chatGptConfigCode - the config code, which you created in previous steps
  • resultSetId - result set id, where you want to put chat gpt response
  • maxTokens - maxTokens configurations for ChatGPT
  • timeoutMills - timeout for the operation
  • temperature - temperature for ChatGPT requests (0 - the most precise, 1 - the most unpredictable)

Now you can make search with the search config and find chat gpt response in context fields. For example if you have search config with code 'demo', the json path to retrieve the context would be $.result.demo.context