Spaces:
Runtime error
Runtime error
File size: 1,784 Bytes
3e62cf4 |
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 51 |
import time
import gradio as gr
from agno.agent import Agent
from agno.models.google.gemini import Gemini
def llm(message, history: list[dict], api_key, num_conversation=3):
model = Gemini(api_key=api_key)
agent = Agent(model=model,
# tools=[WebsiteTools(), HackerNewsTools()],
description="Bạn là một trợ lý AI hữu ích và thông minh. Dưới đây là lịch sử hội thoại giữa bạn và người dùng:",
instructions=[f"Sử dụng kiến thức chuyên môn để trả lời câu hỏi hiện tại",
"Xem xét ngữ cảnh từ các câu hỏi và trả lời trước đó",
"Khi được hỏi về tin tức mới nhất mà không cung cấp thông tin cụ thể thì mặc định chọn 3 tin mới nhất từ HackerNews"],
show_tool_calls=True, markdown=True)
history.append({
"question": message["text"],
"answer": ""
})
conversation = ""
for entry in history[-num_conversation:]:
conversation += f"User: {entry['question']}\n"
conversation += f"Chatbot: {entry['answer']}\n\n"
result = agent.run(conversation).content
history[-1]["answer"] = result
return result
chat_history = []
def process(message, history):
key = "AIzaSyBLLXxkA0Ij5iHr6tXgIcpwzCBANJQn4_o"
result = llm(message, chat_history, api_key=key, num_conversation=3)
temp = ""
for i in str(result).split():
time.sleep(0.05)
temp += i + " "
yield temp
gr.ChatInterface(
multimodal=True,
fn=process,
type="messages",
fill_width=True,
save_history=True
).launch()
|