eivind-n commited on
Commit
aff3908
·
1 Parent(s): 27917f8

Initial files

Browse files
app.py ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ import openai
4
+ import chromadb
5
+ from chromadb.config import Settings
6
+ from langchain.embeddings import OpenAIEmbeddings
7
+
8
+
9
+ css="""
10
+ #col-container {max-width: 700px; margin-left: auto; margin-right: auto;}
11
+ """
12
+
13
+ title = """
14
+ <div style="text-align: center;max-width: 700px;">
15
+ <h1>Ask P360 Help • OpenAI</h1>
16
+ <p style="text-align: center;">Ask questions about the P360 documentation.
17
+ </div>
18
+ """
19
+
20
+ def init():
21
+ '''
22
+ Setup.
23
+ '''
24
+ chroma_client = chromadb.Client(
25
+ Settings(
26
+ chroma_db_impl='duckdb+parquet',
27
+ persist_directory='./vectorstore/',
28
+ )
29
+ )
30
+
31
+ global db
32
+ db = chroma_client.get_collection(
33
+ name='help-360',
34
+ )
35
+
36
+ global embeddings_generator
37
+ embeddings_generator = OpenAIEmbeddings(
38
+ openai_api_key=os.getenv('AZURE_OPENAI_KEY'),
39
+ openai_api_base=os.getenv('AZURE_OPENAI_ENDPOINT'),
40
+ openai_api_type='azure',
41
+ openai_api_version='2023-05-15',
42
+ deployment='embedding-test'
43
+ )
44
+
45
+
46
+ def respond(query):
47
+ '''
48
+ OpenAI GPT response.
49
+ '''
50
+ query_embedding = embeddings_generator.embed_query(query)
51
+ results = db.query(
52
+ query_embeddings=query_embedding,
53
+ n_results=1,
54
+ )
55
+ relevant_help = results['documents'][0][0]
56
+
57
+ openai.api_type = 'azure'
58
+ openai.api_base = os.getenv('AZURE_OPENAI_ENDPOINT')
59
+ openai.api_key = os.getenv('AZURE_OPENAI_KEY')
60
+ openai.api_version = '2023-05-15'
61
+
62
+ response = openai.ChatCompletion.create(
63
+ engine='entest-gpt-35-turbo',
64
+ messages=[
65
+ {"role": "system", "content": "You are a helpful assistant in the P360 document archiving system."},
66
+ {"role": "user", "content": "What do you know about P360?"},
67
+ {"role": "assistant", "content": relevant_help},
68
+ {"role": "user", "content": query},
69
+ ]
70
+ )
71
+ return response['choices'][0]['message']['content']
72
+
73
+
74
+ with gr.Blocks(css=css) as demo:
75
+ with gr.Column(elem_id="col-container"):
76
+ gr.HTML(title)
77
+ question = gr.Textbox(label='Question', placeholder='Type your question and hit Enter ')
78
+ answer = gr.Textbox(label='Answer').style(height=350)
79
+ question.submit(respond, [question], [answer])
80
+
81
+
82
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ openai
2
+ tiktoken
3
+ chromadb
4
+ langchain
vectorstore/chroma-collections.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:179e58ec52786d9363e09234fc15cd6dc29ba2a3156b2659d57792135ab023cb
3
+ size 552
vectorstore/chroma-embeddings.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ac1624236a20e796e52dfd638eae6a3904a5fc397f7796f10c713eadad72d592
3
+ size 7056150
vectorstore/index/id_to_uuid_621498b8-3f11-4417-a09e-a7c5d047d1f8.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8f60098fd8252f9978771f4e39f6668c0d061c0080bb89c3a360697c6f892609
3
+ size 24146
vectorstore/index/index_621498b8-3f11-4417-a09e-a7c5d047d1f8.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e7432088529e4845be24e8993447fc6c26cbe384e675ff9cc12bc534aba4183c
3
+ size 4719632
vectorstore/index/index_metadata_621498b8-3f11-4417-a09e-a7c5d047d1f8.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6ef5746b6394c4342c9f7fd3756414fcb4903090c7aa7f61300c291a6a8deeb4
3
+ size 105
vectorstore/index/uuid_to_id_621498b8-3f11-4417-a09e-a7c5d047d1f8.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7ff9e3f04d4afc3458a4dda36ae8d6b8dbfc86635bd012f3e95b964081b4ffdf
3
+ size 28261