Kackle commited on
Commit
69e68db
·
verified ·
1 Parent(s): 90a5b5c

Update nova_agent.py

Browse files
Files changed (1) hide show
  1. nova_agent.py +37 -5
nova_agent.py CHANGED
@@ -34,19 +34,26 @@ class NovaLiteAgent:
34
  print(f"NovaLiteAgent received question (first 50 chars): {question[:50]}...")
35
 
36
  try:
 
 
 
 
 
 
 
37
  # Prepare the request payload for Nova Lite
38
  payload = {
39
  "messages": [
40
  {
41
  "role": "user",
42
  "content": [{
43
- "text": question
44
  }]
45
  }
46
  ],
47
  "inferenceConfig": {
48
- "max_new_tokens": 1000,
49
- "temperature": 0.1
50
  }
51
  }
52
 
@@ -62,8 +69,33 @@ class NovaLiteAgent:
62
  response_body = json.loads(response['body'].read())
63
  answer = response_body['output']['message']['content'][0]['text']
64
 
65
- return answer.strip()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
 
67
  except Exception as e:
68
  print(f"Error calling Nova Lite: {e}")
69
- return f"I apologize, but I'm currently experiencing technical difficulties: {e}"
 
34
  print(f"NovaLiteAgent received question (first 50 chars): {question[:50]}...")
35
 
36
  try:
37
+ # Create a more focused prompt for concise answers
38
+ prompt = f"""Answer this question directly and concisely. Provide only the essential information requested, not explanations or step-by-step reasoning unless specifically asked.
39
+
40
+ Question: {question}
41
+
42
+ Answer:"""
43
+
44
  # Prepare the request payload for Nova Lite
45
  payload = {
46
  "messages": [
47
  {
48
  "role": "user",
49
  "content": [{
50
+ "text": prompt
51
  }]
52
  }
53
  ],
54
  "inferenceConfig": {
55
+ "max_new_tokens": 150,
56
+ "temperature": 0.0
57
  }
58
  }
59
 
 
69
  response_body = json.loads(response['body'].read())
70
  answer = response_body['output']['message']['content'][0]['text']
71
 
72
+ # Clean up the answer - remove verbose patterns
73
+ answer = answer.strip()
74
+
75
+ # Remove common verbose beginnings
76
+ verbose_starts = [
77
+ "To answer this question",
78
+ "Based on the information",
79
+ "According to",
80
+ "The answer is",
81
+ "Looking at"
82
+ ]
83
+
84
+ for start in verbose_starts:
85
+ if answer.lower().startswith(start.lower()):
86
+ sentences = answer.split('. ')
87
+ for sentence in sentences[1:]:
88
+ if len(sentence.strip()) > 10:
89
+ answer = sentence.strip()
90
+ break
91
+
92
+ # Limit length
93
+ if len(answer) > 200:
94
+ sentences = answer.split('. ')
95
+ answer = sentences[0] + '.'
96
+
97
+ return answer
98
 
99
  except Exception as e:
100
  print(f"Error calling Nova Lite: {e}")
101
+ return "Unable to process request."