Mohammed Albrayh commited on
Commit
873ced5
1 Parent(s): a8dc960
Files changed (2) hide show
  1. .env +0 -7
  2. app.py +46 -8
.env DELETED
@@ -1,7 +0,0 @@
1
- RUNPOD_KEY = 80SUW0PDAG3SDFSS2JA0E5QFCIMECU7SCXUTNH3A
2
- RUNPOD_URL = https://api.runpod.ai/v2/vllm-s4x8uw9y3qv296/openai/v1
3
- # QDRANT_URL = https://2fee3feb-59b4-43ca-adef-ffaaacd4e0c6.europe-west3-0.gcp.cloud.qdrant.io
4
- QDRANT_URL = https://7fcf6c04-2f9f-40f3-b26b-c19885487d64.europe-west3-0.gcp.cloud.qdrant.io
5
- # QDRANT_KEY = X2zkjP-ruS0uvdDEWbj2ZxeMVtmDbG1WXH6lQdGUnOYjT_-ODzqWZQ
6
- QDRANT_KEY = c-p0ej858dskulydMoLpokCLK2Q2phWXTUHjrKBYYRz3y-g7YSKZ4A
7
- OPENAI_API_KEY = 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
 
 
 
 
 
 
 
 
app.py CHANGED
@@ -7,6 +7,9 @@ from qdrant_client import QdrantClient
7
  from qdrant_client.http.models import Distance, VectorParams
8
  from langchain_qdrant import QdrantVectorStore
9
  from langchain_openai import OpenAIEmbeddings
 
 
 
10
 
11
  load_dotenv()
12
 
@@ -17,14 +20,11 @@ model = OpenAI(api_key=RUNPOD_KEY, base_url= RUNPOD_URL)
17
  QDRANT_URL = os.getenv("QDRANT_URL")
18
  QDRANT_KEY = os.getenv("QDRANT_KEY")
19
 
20
- print(QDRANT_URL)
21
- print(QDRANT_KEY)
22
-
23
  OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
24
- print(OPENAI_API_KEY)
25
 
26
  client = QdrantClient(QDRANT_URL, api_key=QDRANT_KEY)
27
- collection_name = "search_engine"
 
28
 
29
  embeddings = OpenAIEmbeddings(
30
  model="text-embedding-3-small",
@@ -59,7 +59,7 @@ prompt = PromptTemplate(
59
 
60
  def prompt_template(query):
61
 
62
- results = qdrant.similarity_search( query=query, k=3 )
63
 
64
  _ctx = ''
65
 
@@ -70,6 +70,38 @@ def prompt_template(query):
70
 
71
  return _prompt
72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  def generate_response(prompt):
74
 
75
  response = model.chat.completions.create(
@@ -83,13 +115,19 @@ def generate_response(prompt):
83
  return response.choices[0].message
84
 
85
  def main(query, history):
86
- prompt = prompt_template(query)
 
87
  resault = generate_response(prompt)
88
 
 
89
 
90
  return resault.content
91
 
92
- demo = gr.ChatInterface(fn=main, title = "News GPT")
 
 
 
 
93
 
94
 
95
  if __name__ == "__main__":
 
7
  from qdrant_client.http.models import Distance, VectorParams
8
  from langchain_qdrant import QdrantVectorStore
9
  from langchain_openai import OpenAIEmbeddings
10
+ import openai
11
+
12
+ openai.api_key = os.getenv("OPENAI_API_KEY")
13
 
14
  load_dotenv()
15
 
 
20
  QDRANT_URL = os.getenv("QDRANT_URL")
21
  QDRANT_KEY = os.getenv("QDRANT_KEY")
22
 
 
 
 
23
  OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
 
24
 
25
  client = QdrantClient(QDRANT_URL, api_key=QDRANT_KEY)
26
+ # collection_name = "search_engine"
27
+ collection_name = "week_4_assesment_embeddings"
28
 
29
  embeddings = OpenAIEmbeddings(
30
  model="text-embedding-3-small",
 
59
 
60
  def prompt_template(query):
61
 
62
+ results = qdrant.similarity_search( query=query, k= 6)
63
 
64
  _ctx = ''
65
 
 
70
 
71
  return _prompt
72
 
73
+ def prompt_top6(text):
74
+ # query_embedding = openai.Embedding.create(
75
+ # input=text,
76
+ # model="text-embedding-3-small"
77
+ # )['data'][0]['embedding']
78
+
79
+ query_embedding = embeddings.embed_query(text)
80
+
81
+ search_results = client.search(
82
+ collection_name="week_4_assesment_embeddings",
83
+ query_vector=query_embedding,
84
+ limit=6
85
+ )
86
+
87
+ # search_results = qdrant.similarity_search( query=text, k= 6)
88
+
89
+ print(search_results)
90
+
91
+
92
+ chunks = ''
93
+ for result in search_results:
94
+ # print(f"Question: {text}")
95
+ # print(f"Answer: {result.payload['answer']}")
96
+ chunks += f"Chunk: {result.payload['context']}\n"
97
+ chunks += '-----\n'
98
+
99
+ _prompt = prompt.format(instruction=text, input=chunks)
100
+
101
+ return _prompt
102
+
103
+
104
+
105
  def generate_response(prompt):
106
 
107
  response = model.chat.completions.create(
 
115
  return response.choices[0].message
116
 
117
  def main(query, history):
118
+ # prompt = prompt_template(query)
119
+ prompt = prompt_top6(query)
120
  resault = generate_response(prompt)
121
 
122
+
123
 
124
  return resault.content
125
 
126
+ examples = [
127
+ "What is the Berry Export Summary 2028 and what is its purpose?",
128
+ ]
129
+
130
+ demo = gr.ChatInterface(fn=main, title = "Assignment 4 GPT", examples=examples)
131
 
132
 
133
  if __name__ == "__main__":