regraded01 commited on
Commit
ce61e92
·
1 Parent(s): 123ba7e

feat: create end-to-end run using fake data/llm

Browse files
Files changed (2) hide show
  1. app_langchain.py +28 -14
  2. config/model_config.yml +2 -2
app_langchain.py CHANGED
@@ -1,23 +1,37 @@
1
- import streamlit as st
2
- import os
3
-
4
- from langchain_core.prompts import PromptTemplate
5
 
6
  from src.utils import load_config_values
7
  from src.dev_llm import FakeLLM
8
 
9
- # Get HuggingFace API key
10
- api_key_name = "HUGGINGFACE_HUB_TOKEN"
11
- api_key = os.getenv(api_key_name)
12
- if api_key is None:
13
- st.error(f"Failed to read `{api_key_name}`. Ensure the token is correctly located")
14
 
15
  # Load in model and pipeline configuration values
16
- system_message, model_id, template = load_config_values()
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
- prompt = PromptTemplate(
19
- template=template,
20
- input_variables=["system_message", "user_message"]
 
 
 
 
 
21
  )
22
 
23
- llm = FakeLLM()
 
1
+ from langchain_core.prompts import ChatPromptTemplate
2
+ from langchain_core.runnables import RunnablePassthrough
 
 
3
 
4
  from src.utils import load_config_values
5
  from src.dev_llm import FakeLLM
6
 
7
+ # TODO: Change this to reflect prod model rather than dev models
8
+ # Initalise fake values and a fake LLM to test out the full pipeline
9
+ tmp_llm = FakeLLM()
10
+ tmp_pdf_text = "This patient is due for an appointment on 1st June 2024" # replace with Runner to a file uploader
 
11
 
12
  # Load in model and pipeline configuration values
13
+ system_message, context_message, model_id = load_config_values(
14
+ config_keys=[
15
+ "system_message",
16
+ "context_message",
17
+ "model_id",
18
+ ]
19
+ )
20
+
21
+
22
+ prompt = ChatPromptTemplate.from_template(
23
+ template=context_message,
24
+ )
25
+
26
 
27
+ chain = (
28
+ {
29
+ "system_message": lambda x: system_message,
30
+ "pdf_text": lambda x: tmp_pdf_text,
31
+ "data_to_extract": RunnablePassthrough()
32
+ }
33
+ |prompt
34
+ |tmp_llm
35
  )
36
 
37
+ print(chain.invoke("{\"appointment_date\"}"))
config/model_config.yml CHANGED
@@ -1,3 +1,3 @@
1
- system_message: "Your role is to take PDF documents and extract their raw text into a JSON format that can be uploaded into a database. Return the JSON only. For example if you need to extract information about a report written on 2nd February 2011 with an author called Jane Mary then return this only: {'report_written_date': '02/02/2011', 'author_name': 'Jane Mary'} Another example would be a clinical exam passed by a student on the 3rd of July 2022 would return this only: {'result' : 'pass', 'date_of_exam' : '03/07/2022'}"
2
- template: "System: {system_message}\nUser: {user_message}"
3
  model_id: "meta-llama/Llama-2-70b-chat-hf"
 
1
+ system_message: "Your role is to take PDF documents and extract their raw text into a JSON format that can be uploaded into a database. Return the JSON only. \nFor example if you need to extract information about a report written on 2nd February 2011 with an author called Jane Mary then return this only: {'report_written_date': '02/02/2011', 'author_name': 'Jane Mary'}\nAnother example would be a clinical exam passed by a student on the 3rd of July 2022 would return this only: {'result' : 'pass', 'date_of_exam' : '03/07/2022'}"
2
+ context_message: "{system_message}\n\nUse the text provided and denoted by 3 backticks ```{pdf_text}```. \nExtract the following values in JSON format.\n{data_to_extract}"
3
  model_id: "meta-llama/Llama-2-70b-chat-hf"