tanveeshsingh commited on
Commit
bf97766
·
1 Parent(s): 56dc4f7
Files changed (1) hide show
  1. app.py +20 -18
app.py CHANGED
@@ -5,23 +5,7 @@ import json
5
  from openai import AsyncOpenAI
6
  from jinja2 import Template
7
  collinear = Collinear(access_token=os.getenv('COLLINEAR_API_KEY'))
8
-
9
- def update_inputs(input_style):
10
- if input_style == "Conv":
11
- return gr.update(visible=True), gr.update(visible=True), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
12
- elif input_style == "NLI":
13
- return gr.update(visible=True), gr.update(visible=False), gr.update(visible=True), gr.update(visible=False), gr.update(visible=False)
14
- elif input_style == "QA format":
15
- return gr.update(visible=True), gr.update(visible=False), gr.update(visible=False), gr.update(visible=True), gr.update(visible=True)
16
-
17
-
18
- async def lynx(input_style_dropdown,document_input,question_input,answer_input):
19
- if input_style_dropdown=='QA format':
20
- client = AsyncOpenAI(
21
- base_url="https://s6mipt5j797e6fql.us-east-1.aws.endpoints.huggingface.cloud/v1/",
22
- api_key=os.getenv("HF_TOKEN")
23
- )
24
- prompt = Template("""Given the following QUESTION, DOCUMENT and ANSWER you must analyze the provided answer and determine whether it is faithful to the contents of the DOCUMENT. The ANSWER must not offer new information beyond the context provided in the DOCUMENT. The ANSWER also must not contradict information provided in the DOCUMENT. Output your final verdict by strictly following this format: "PASS" if the answer is faithful to the DOCUMENT and "FAIL" if the answer is not faithful to the DOCUMENT. Show your reasoning.
25
  --
26
  QUESTION (THIS DOES NOT COUNT AS BACKGROUND INFORMATION):
27
  {question}
@@ -38,12 +22,30 @@ ANSWER:
38
 
39
  Your output should be in JSON FORMAT with the keys "REASONING" and "SCORE":
40
  {{"REASONING": <your reasoning as bullet points>, "SCORE": <your final score>}}""")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  chat_completion = await client.chat.completions.create(
42
  model="tgi",
43
  messages=[
44
  {
45
  "role": "user",
46
- "content": prompt.render(question=question_input,context=document_input,answer=answer_input)
47
  }
48
  ],
49
  top_p=None,
 
5
  from openai import AsyncOpenAI
6
  from jinja2 import Template
7
  collinear = Collinear(access_token=os.getenv('COLLINEAR_API_KEY'))
8
+ prompt = Template("""Given the following QUESTION, DOCUMENT and ANSWER you must analyze the provided answer and determine whether it is faithful to the contents of the DOCUMENT. The ANSWER must not offer new information beyond the context provided in the DOCUMENT. The ANSWER also must not contradict information provided in the DOCUMENT. Output your final verdict by strictly following this format: "PASS" if the answer is faithful to the DOCUMENT and "FAIL" if the answer is not faithful to the DOCUMENT. Show your reasoning.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  --
10
  QUESTION (THIS DOES NOT COUNT AS BACKGROUND INFORMATION):
11
  {question}
 
22
 
23
  Your output should be in JSON FORMAT with the keys "REASONING" and "SCORE":
24
  {{"REASONING": <your reasoning as bullet points>, "SCORE": <your final score>}}""")
25
+
26
+ def update_inputs(input_style):
27
+ if input_style == "Conv":
28
+ return gr.update(visible=True), gr.update(visible=True), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
29
+ elif input_style == "NLI":
30
+ return gr.update(visible=True), gr.update(visible=False), gr.update(visible=True), gr.update(visible=False), gr.update(visible=False)
31
+ elif input_style == "QA format":
32
+ return gr.update(visible=True), gr.update(visible=False), gr.update(visible=False), gr.update(visible=True), gr.update(visible=True)
33
+
34
+
35
+ async def lynx(input_style_dropdown,document_input,question_input,answer_input):
36
+ if input_style_dropdown=='QA format':
37
+ client = AsyncOpenAI(
38
+ base_url="https://s6mipt5j797e6fql.us-east-1.aws.endpoints.huggingface.cloud/v1/",
39
+ api_key=os.getenv("HF_TOKEN")
40
+ )
41
+ rendered_prompt = prompt.render(question=question_input,context=document_input,answer=answer_input)
42
+ print(prompt.render(question=question_input,context=document_input,answer=answer_input))
43
  chat_completion = await client.chat.completions.create(
44
  model="tgi",
45
  messages=[
46
  {
47
  "role": "user",
48
+ "content": "hey"
49
  }
50
  ],
51
  top_p=None,