File size: 1,511 Bytes
46927b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from openai import OpenAI
import os

OPENAPI_ORG = os.getenv('OpenAPIOrganization')
OPENAPI_PROJ = os.getenv('OpenAPIProject')
client = OpenAI(organization=OPENAPI_ORG, project=OPENAPI_PROJ)

class QuestionAnserBot:
    PROMPT = """\
You are a helpful assistant that can answer questions.
Rules:
-	Reply with answer only and nothing but the answer
-	Say 'I don't know' if you don't know the answer
-	Use the provided context
"""
    def answer_question(self, question: str) -> str:
        completion = client.chat.completions.create(
            model='gpt-3.5-turbo',
            messages=[
                {'role': 'system', 'content': QuestionAnserBot.PROMPT},
                {'role': 'user', 'content': f'Context:Кафдера систем штучного інтелекту. Місія кафедри: підготувати спеціаліста, який зможе вирішувати алгоритмічно складні задачі, аналізувати дані великих обсягів, розробляти алгоритми обробки відео, зображень або текстів, програмувати та керувати роботами\nQuestion:{question}'}
            ]
        )

        return completion.choices[0].message.content

def answer_question(query):
    bot = QuestionAnserBot()
    return bot.answer_question(query)

demo = gr.Interface(
    fn=answer_question,
    inputs=["text"],
    outputs=["text"],
)

demo.launch()