File size: 1,300 Bytes
b91b29d
ee8c5b2
 
 
 
 
cecfec2
ee8c5b2
 
60df988
ee8c5b2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b91b29d
 
ee8c5b2
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
import gradio as gr
from langchain.vectorstores import FAISS
from langchain.embeddings import HuggingFaceEmbeddings
from groq import Groq

# Load FAISS index
vector_store = FAISS.load_local("robohome_faiss", HuggingFaceEmbeddings())

# Inisialisasi API Groq
client = Groq(api_key="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")

def retrieve_and_generate(query):
    # Retrieve top 3 documents
    docs = vector_store.similarity_search(query, k=3)
    context = "\n\n".join([doc.page_content for doc in docs])

    # Generate response with LLM
    response = client.chat.completions.create(
        model="mixtral-8x7b-32768",
        messages=[
            {"role": "system", "content": "Anda adalah asisten AI yang menjawab pertanyaan tentang RoboHome berdasarkan dokumen ini."},
            {"role": "user", "content": f"{context}\n\nPertanyaan: {query}"}
        ],
        temperature=0.7,
        max_tokens=200
    )

    return response.choices[0].message.content

# UI dengan Gradio
iface = gr.Interface(
    fn=retrieve_and_generate,
    inputs=gr.Textbox(label="Ajukan pertanyaan tentang RoboHome"),
    outputs=gr.Textbox(label="Jawaban"),
    title="RoboHome RAG Chatbot",
    description="Chatbot ini menjawab pertanyaan berdasarkan dokumentasi RoboHome.",
)

iface.launch()