File size: 1,207 Bytes
d195d4f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import gradio as gr
import openai
import json
from factool import Factool
import os

def chat_with_gpt(api_key, model, message):
    openai.api_key = api_key
    response = openai.ChatCompletion.create(
      model=model,
      messages=[
            {"role": "system", "content": "You are a helpful assistant."},
            {"role": "user", "content": message},
        ]
    )
    return response.choices[0].message['content']

def fact_check(api_key, model, message, response):
    os.environ['OPENAI_API_KEY'] = api_key
    factool_instance = Factool("model")
    inputs = [
            {
                "prompt": message,
                "response": response,
                "category": "kbqa",
                "search_type": "online",
            },
    ]
    response_list = factool_instance.run(inputs)
    return response_list

def process_input(api_key, model, message):
    response = chat_with_gpt(api_key, model, message)
    return fact_check(api_key, model, message, response)

iface = gr.Interface(fn=process_input, 
                     inputs=["text", gr.inputs.Radio(["gpt-3.5-turbo", "gpt-4"], label="Model"), "text"], 
                     outputs=gr.outputs.JSON())
iface.launch()