Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
from openai import OpenAI
|
|
|
3 |
import os
|
4 |
|
5 |
ACCESS_TOKEN = os.getenv("HF_TOKEN")
|
@@ -11,9 +12,12 @@ client = OpenAI(
|
|
11 |
)
|
12 |
print("OpenAI client initialized.")
|
13 |
|
|
|
|
|
|
|
14 |
# Define a comprehensive system prompt
|
15 |
SYSTEM_PROMPT = """
|
16 |
-
You are a highly knowledgeable and reliable Crypto Trading Advisor and Analyzer
|
17 |
|
18 |
### 1. Communication Style
|
19 |
- Be professional, approachable, and clear.
|
@@ -104,6 +108,17 @@ def respond(
|
|
104 |
# Append the latest user message
|
105 |
messages.append({"role": "user", "content": message})
|
106 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
# Start response generation
|
108 |
response = ""
|
109 |
print("Sending request to OpenAI API.")
|
@@ -177,4 +192,4 @@ demo = gr.ChatInterface(
|
|
177 |
)
|
178 |
|
179 |
if __name__ == "__main__":
|
180 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from openai import OpenAI
|
3 |
+
from langchain_community.tools.tavily_search import TavilySearchResults
|
4 |
import os
|
5 |
|
6 |
ACCESS_TOKEN = os.getenv("HF_TOKEN")
|
|
|
12 |
)
|
13 |
print("OpenAI client initialized.")
|
14 |
|
15 |
+
# Tavily Search Tool'u başlat
|
16 |
+
search_tool = TavilySearchResults()
|
17 |
+
|
18 |
# Define a comprehensive system prompt
|
19 |
SYSTEM_PROMPT = """
|
20 |
+
You are a highly knowledgeable and reliable Crypto Trading Advisor and Analyzer. Your primary goal is to assist users in understanding, analyzing, and making informed decisions about cryptocurrency trading. You provide accurate, concise, and actionable advice based on real-time data, historical trends, and established best practices. Below are your core responsibilities and interaction guidelines:
|
21 |
|
22 |
### 1. Communication Style
|
23 |
- Be professional, approachable, and clear.
|
|
|
108 |
# Append the latest user message
|
109 |
messages.append({"role": "user", "content": message})
|
110 |
|
111 |
+
# Tavily arama aracıyla ilgili bilgi al
|
112 |
+
print("Searching for relevant information...")
|
113 |
+
search_results = search_tool.run(message)
|
114 |
+
print(f"Search results: {search_results}")
|
115 |
+
|
116 |
+
# Arama sonuçlarını sisteme ekle
|
117 |
+
if search_results:
|
118 |
+
search_summary = " ".join(search_results)
|
119 |
+
messages.append({"role": "system", "content": f"Relevant information found online: {search_summary}"})
|
120 |
+
print("Search results added to context.")
|
121 |
+
|
122 |
# Start response generation
|
123 |
response = ""
|
124 |
print("Sending request to OpenAI API.")
|
|
|
192 |
)
|
193 |
|
194 |
if __name__ == "__main__":
|
195 |
+
demo.launch()
|