Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -1,41 +1,45 @@
|
|
1 |
-
from openai import OpenAI
|
2 |
-
import crawl_the_site
|
3 |
-
import create_database
|
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 |
print((completion.choices[0].message.content)[7:-1])
|
|
|
1 |
+
from openai import OpenAI
|
2 |
+
import crawl_the_site
|
3 |
+
import create_database
|
4 |
+
import streamlit as st
|
5 |
+
|
6 |
+
api_key = "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"
|
7 |
+
|
8 |
+
config = st.text_area("enter the start URL and the limit of crawling :")
|
9 |
+
|
10 |
+
start = "asdf"
|
11 |
+
limit = 100
|
12 |
+
|
13 |
+
print("")
|
14 |
+
txt = crawl_the_site.crawl(start,limit)
|
15 |
+
collection = create_database.create_database(txt)
|
16 |
+
|
17 |
+
openai_client = OpenAI(base_url="https://openrouter.ai/api/v1",api_key=api_key)
|
18 |
+
|
19 |
+
prompt_template = """Answer the question only according to the information provided below. Answer only the user's question, dont give additional information.
|
20 |
+
## Information :
|
21 |
+
{}
|
22 |
+
|
23 |
+
## Question :
|
24 |
+
# {}"""
|
25 |
+
|
26 |
+
while True:
|
27 |
+
q = input("prompt : ")
|
28 |
+
|
29 |
+
results = collection.query(query_texts=[q],n_results=5)
|
30 |
+
infos = results["documents"][0]
|
31 |
+
|
32 |
+
info_text = ""
|
33 |
+
for info in infos:
|
34 |
+
info_text += info + "\n---\n"
|
35 |
+
info_text = info_text.strip()
|
36 |
+
|
37 |
+
prompt = prompt_template.format(info_text,q)
|
38 |
+
|
39 |
+
completion = openai_client.chat.completions.create(
|
40 |
+
extra_headers={},
|
41 |
+
extra_body={},
|
42 |
+
model="deepseek/deepseek-r1:free",
|
43 |
+
messages=[{"role":"user","content":prompt}])
|
44 |
+
|
45 |
print((completion.choices[0].message.content)[7:-1])
|