Update app.py
Browse files
app.py
CHANGED
@@ -46,7 +46,7 @@ class ChatRequest(BaseModel):
|
|
46 |
You focus on buck bedding, terrain reading, and aggressive yet calculated mobile tactics. Your blue-collar, no-nonsense approach
|
47 |
emphasizes deep scouting, strategic access, and minimalist setups. Through The Hunting Beast, you teach hunters how to kill big bucks
|
48 |
using terrain, wind, and thermals. You speak from firsthand experience, keeping your advice practical and to the point. Provide detailed
|
49 |
-
yet concise responses, with a maximum of 150 words.
|
50 |
"""
|
51 |
temperature: float = 0.7
|
52 |
chat_history: List[Dict[str, Any]] = []
|
@@ -62,25 +62,12 @@ chunks = chunk_text(concise_text_string, chunk_size=450)
|
|
62 |
# Build the vectorsore
|
63 |
vectorstore = build_faiss_vectorstore(chunks)
|
64 |
|
65 |
-
one_shot_example = textwrap.dedent(""" Here is an example of the style and tone of a response:
|
66 |
-
Query: How do big bucks use clear cuts for bedding?
|
67 |
-
Response: Yeah, a lot of guys think big bucks just bed right in the middle of a clear cut because it’s thick, but that’s not really how they use it. The
|
68 |
-
thick regrowth is great for food and cover, but those bucks still want an advantage. Most of the time, they’re bedding on the edges, right where the cut
|
69 |
-
meets older timber. They’ll set up with the wind at their back so they can smell anything sneaking up behind them, and they’re looking out into the open
|
70 |
-
woods, watching for danger""")
|
71 |
-
|
72 |
@app.post("/chat")
|
73 |
async def chat(request: ChatRequest):
|
74 |
try:
|
75 |
if request.model_choice == "google":
|
76 |
client = genai.Client(api_key=google_api_key)
|
77 |
|
78 |
-
# insert one shot example at beginning of chat
|
79 |
-
request.chat_history.insert(0, {
|
80 |
-
"role": "user",
|
81 |
-
"parts": [{"text": one_shot_example}]
|
82 |
-
})
|
83 |
-
|
84 |
# summarize chat history
|
85 |
summary_thresh = 10
|
86 |
if len(request.chat_history) > summary_thresh:
|
@@ -103,13 +90,24 @@ async def chat(request: ChatRequest):
|
|
103 |
results = retrieve(request.message, vectorstore, top_k=5)
|
104 |
formatted_results = "\n\n".join(results)
|
105 |
|
106 |
-
rag_prompt = f"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
|
108 |
{formatted_results}
|
109 |
|
110 |
Using the information above, answer the user's query as accurately as possible:
|
111 |
|
112 |
-
|
113 |
"""
|
114 |
|
115 |
# remove the unfformatted user message
|
|
|
46 |
You focus on buck bedding, terrain reading, and aggressive yet calculated mobile tactics. Your blue-collar, no-nonsense approach
|
47 |
emphasizes deep scouting, strategic access, and minimalist setups. Through The Hunting Beast, you teach hunters how to kill big bucks
|
48 |
using terrain, wind, and thermals. You speak from firsthand experience, keeping your advice practical and to the point. Provide detailed
|
49 |
+
yet concise responses, with a maximum of 150 words.
|
50 |
"""
|
51 |
temperature: float = 0.7
|
52 |
chat_history: List[Dict[str, Any]] = []
|
|
|
62 |
# Build the vectorsore
|
63 |
vectorstore = build_faiss_vectorstore(chunks)
|
64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
@app.post("/chat")
|
66 |
async def chat(request: ChatRequest):
|
67 |
try:
|
68 |
if request.model_choice == "google":
|
69 |
client = genai.Client(api_key=google_api_key)
|
70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
# summarize chat history
|
72 |
summary_thresh = 10
|
73 |
if len(request.chat_history) > summary_thresh:
|
|
|
90 |
results = retrieve(request.message, vectorstore, top_k=5)
|
91 |
formatted_results = "\n\n".join(results)
|
92 |
|
93 |
+
rag_prompt = f"""Use the following information to answer the user's query. You do not have to use all the information, just the pieces that directly
|
94 |
+
help answer the query most accurately. Start directly with information, NOT with a rhetorical question. Respond in a conversational manner.
|
95 |
+
|
96 |
+
Here is an example of the style and tone of a response:
|
97 |
+
|
98 |
+
Query: How do big bucks use clear cuts for bedding?
|
99 |
+
Response: Yeah, a lot of guys think big bucks just bed right in the middle of a clear cut because it’s thick, but that’s not really how they use it. The
|
100 |
+
thick regrowth is great for food and cover, but those bucks still want an advantage. Most of the time, they’re bedding on the edges, right where the cut
|
101 |
+
meets older timber. They’ll set up with the wind at their back so they can smell anything sneaking up behind them, and they’re looking out into the open
|
102 |
+
woods, watching for danger.
|
103 |
+
|
104 |
+
You have access to the following relevant information retrieved based on the user's query:
|
105 |
|
106 |
{formatted_results}
|
107 |
|
108 |
Using the information above, answer the user's query as accurately as possible:
|
109 |
|
110 |
+
Query: {request.message}
|
111 |
"""
|
112 |
|
113 |
# remove the unfformatted user message
|