File size: 1,528 Bytes
ec16604
 
 
 
 
 
 
f1d619d
b7e76a9
f1d619d
b7e76a9
4463689
f1d619d
 
 
 
 
 
 
ec16604
 
 
 
 
 
 
 
 
 
f1d619d
b7e76a9
ec16604
b7e76a9
f1d619d
ec16604
 
 
 
 
 
 
f1d619d
ec16604
 
 
 
 
 
 
f1d619d
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
42
43
44
45
46
47
48
49
50
from openai import OpenAI
import crawl_the_site
import create_database
import streamlit as st

api_key = "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"

config = st.text_area("Enter the start URL and the limit of crawling (in this format : URL,limit):")
config_btn = st.button("Start crawling!")

if config and config_btn:
    global collection
    start = config.split(",")[0]
    limit = int(config.split(",")[1])
    
    print("")
    txt = crawl_the_site.crawl(start,limit)
    collection = create_database.create_database(txt)
    st.write("Crawling is done.")

openai_client = OpenAI(base_url="https://openrouter.ai/api/v1",api_key=api_key)

prompt_template = """Answer the question only according to the information provided below. Answer only the user's question, dont give additional information.
## Information : 
{}

## Question : 
# {}"""

prompt = st.text_area("Enter a prompt (after the crawling is done):")
prompt_btn = st.button("Enter")

if prompt and prompt_btn:
    results = collection.query(query_texts=[prompt],n_results=5)
    infos = results["documents"][0]

    info_text = ""
    for info in infos:
        info_text += info + "\n---\n"
    info_text = info_text.strip()

    prompt = prompt_template.format(info_text,prompt)

    completion = openai_client.chat.completions.create(
    extra_headers={},
    extra_body={},
    model="deepseek/deepseek-r1:free",
    messages=[{"role":"user","content":prompt}])

    st.write((completion.choices[0].message.content)[7:-1])