Code0ut commited on
Commit
dc862b9
·
verified ·
1 Parent(s): e09296f

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. server/response_generator.py +12 -4
server/response_generator.py CHANGED
@@ -44,8 +44,11 @@ Respond like a real patient in 1-2 sentences.You are not allowed to mention your
44
 
45
 
46
 
47
- OPENROUTER_API_KEY = os.getenv("OPENROUTER_API_KEY")
 
 
48
 
 
49
  OPENROUTER_URL = "https://openrouter.ai/api/v1/chat/completions"
50
 
51
 
@@ -56,7 +59,7 @@ def call_llm(prompt: str) -> str:
56
  }
57
 
58
  payload = {
59
- "model": "nvidia/nemotron-3-nano-30b-a3b:free", # you can change model here
60
  "messages": [
61
  {"role": "system", "content": "You are a mental health patient."},
62
  {"role": "user", "content": prompt}
@@ -75,7 +78,12 @@ def call_llm(prompt: str) -> str:
75
 
76
  result = response.json()
77
 
78
- return result["choices"][0]["message"]["content"].strip()
 
 
 
 
 
79
 
80
  except Exception as e:
81
  print("LLM Error:", e)
@@ -94,4 +102,4 @@ def generate_response(action_type: str, message: str, state, ) -> str:
94
 
95
  response = call_llm(prompt)
96
 
97
- return response
 
44
 
45
 
46
 
47
+ import requests
48
+ import os
49
+
50
 
51
+ OPENROUTER_API_KEY = os.getenv("OPENROUTER_API_KEY")
52
  OPENROUTER_URL = "https://openrouter.ai/api/v1/chat/completions"
53
 
54
 
 
59
  }
60
 
61
  payload = {
62
+ "model": "nvidia/nemotron-3-nano-30b-a3b:free",
63
  "messages": [
64
  {"role": "system", "content": "You are a mental health patient."},
65
  {"role": "user", "content": prompt}
 
78
 
79
  result = response.json()
80
 
81
+ content = result.get("choices", [{}])[0].get("message", {}).get("content")
82
+
83
+ if not content:
84
+ return "I don't really know how to explain it..."
85
+
86
+ return content.strip()
87
 
88
  except Exception as e:
89
  print("LLM Error:", e)
 
102
 
103
  response = call_llm(prompt)
104
 
105
+ return response