cancel
Showing results for 
Search instead for 
Did you mean: 
Generative AI
Explore discussions on generative artificial intelligence techniques and applications within the Databricks Community. Share ideas, challenges, and breakthroughs in this cutting-edge field.
cancel
Showing results for 
Search instead for 
Did you mean: 

GenAI Cookbook - how to add source documents to output and open pdf file on a page

karavyu1
New Contributor II

Hello,

I am implementing RAG solution as per Databricks cookbook. Review App is working, references are provided as text chunks.

I need to build functionality to open pdf file on a specific page as a reference. Is there a way to change ReviewApp to open pdf file instead of opening text?
Or do I need to build chainlit app with PdfViewer elements to provide this functionality?
How can I call serving point to return source documents?
I am using this code atm and sources are not returned:

 

 

import os
import requests
import numpy as np
import pandas as pd
import json

def create_tf_serving_json(data):
    return {'inputs': {name: data[name] for name in data.keys()} if isinstance(data, dict) else data}

def score_model(dataset):
    url = 'https://XXX/invocations'
    headers = {'Authorization': f'Bearer {DATABRICKS_TOKEN}', 'Content-Type': 'application/json'}
    ds_dict = {'dataframe_split': dataset.to_dict(orient='split')} if isinstance(dataset, pd.DataFrame) else create_tf_serving_json(dataset)
    data_json = json.dumps(ds_dict, allow_nan=True)
    print(data_json)
    response = requests.request(method='POST', headers=headers, url=url, data=data_json})
    if response.status_code != 200:
        raise Exception(f'Request failed with status {response.status_code}, {response.text}')
    return response.json()

response = score_model({
  "messages": [
    {
      "role": "user",
      "content": "What is LLM?"
    }
  ]
})
for item in response.items():
    print(item)

 

 

 
0 REPLIES 0

Join Us as a Local Community Builder!

Passionate about hosting events and connecting people? Help us grow a vibrant local community—sign up today to get started!

Sign Up Now