Lhumpal commited on
Commit
f417ee0
·
verified ·
1 Parent(s): c107fb9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -23
app.py CHANGED
@@ -18,14 +18,30 @@ class ChatRequest(BaseModel):
18
  emphasizes deep scouting, strategic access, and minimalist setups. Through The Hunting Beast, you teach hunters how to kill big bucks
19
  using terrain, wind, and thermals. You speak from firsthand experience, keeping your advice practical and to the point. Provide detailed
20
  yet concise responses, with a maximum of 150 words"""
21
- max_tokens: int = 512
22
  temperature: float = 0.7
23
- top_p: float = 0.95
24
- model_choice: str = "HF"
25
 
26
  @app.post("/chat")
27
  async def chat(request: ChatRequest):
28
  try:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  if request.model_choice == "HF":
30
  if hf_token:
31
  client = InferenceClient("meta-llama/Llama-3.2-3B-Instruct", token=hf_token)
@@ -45,26 +61,6 @@ async def chat(request: ChatRequest):
45
  )
46
 
47
  return {"response": response.choices[0].message.content}
48
-
49
- if request.model_choice == "google":
50
- client = genai.Client(api_key=google_api_key)
51
-
52
- messages = [
53
- {"role": "user", "parts": [{"text": request.message}]},
54
- # {"role": "model", "parts": [{"text": "Great! Dogs are fun pets."}]},
55
- # {"role": "user", "parts": [{"text": "How many dogs do I have?"}]},
56
- ]
57
-
58
- response = client.models.generate_content(
59
- model="gemini-2.0-flash",
60
- contents=messages,
61
- config=GenerateContentConfig(
62
- system_instruction=[
63
- "Respond like you are a pirate.",
64
- ]
65
- ),
66
- )
67
- return {"response": response.text}
68
 
69
  except Exception as e:
70
  raise HTTPException(status_code=500, detail=str(e))
 
18
  emphasizes deep scouting, strategic access, and minimalist setups. Through The Hunting Beast, you teach hunters how to kill big bucks
19
  using terrain, wind, and thermals. You speak from firsthand experience, keeping your advice practical and to the point. Provide detailed
20
  yet concise responses, with a maximum of 150 words"""
 
21
  temperature: float = 0.7
22
+ model_choice: str = "google"
 
23
 
24
  @app.post("/chat")
25
  async def chat(request: ChatRequest):
26
  try:
27
+ if request.model_choice == "google":
28
+ client = genai.Client(api_key=google_api_key)
29
+
30
+ messages = [
31
+ {"role": "user", "parts": [{"text": request.message}]},
32
+ # {"role": "model", "parts": [{"text": "Great! Dogs are fun pets."}]},
33
+ # {"role": "user", "parts": [{"text": "How many dogs do I have?"}]},
34
+ ]
35
+
36
+ response = client.models.generate_content(
37
+ model="gemini-2.0-flash",
38
+ contents=messages,
39
+ config=GenerateContentConfig(
40
+ system_instruction=[system_message]
41
+ ),
42
+ )
43
+ return {"response": response.text}
44
+
45
  if request.model_choice == "HF":
46
  if hf_token:
47
  client = InferenceClient("meta-llama/Llama-3.2-3B-Instruct", token=hf_token)
 
61
  )
62
 
63
  return {"response": response.choices[0].message.content}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
 
65
  except Exception as e:
66
  raise HTTPException(status_code=500, detail=str(e))