Mbonea commited on
Commit
a1192cf
·
1 Parent(s): 56e498e

["candidates"][0]["content"]['parts'][0]['text']

Browse files
App/Chat/utils/RAG.py CHANGED
@@ -47,7 +47,7 @@ class GenerativeAIAssistant:
47
  latest_message = messages[-1]['content']
48
  latest_message={"content":self.generate_template(latest_message,task_id)}
49
  messages[-1]=latest_message
50
- url = f'https://generativelanguage.googleapis.com/v1beta/models/{self.model}:generateMessage?key={self.api_key}'
51
  data = {
52
  "prompt": {
53
  "context": self.context,
@@ -64,7 +64,7 @@ class GenerativeAIAssistant:
64
  async with session.post(url, json=data, headers={'Content-Type': 'application/json'}) as response:
65
  try:
66
  temp= await response.json()
67
- return temp['candidates']
68
  except Exception as e:
69
  return f"Error ⚠️ {e}"
70
 
 
47
  latest_message = messages[-1]['content']
48
  latest_message={"content":self.generate_template(latest_message,task_id)}
49
  messages[-1]=latest_message
50
+ url = f'https://generativelanguage.googleapis.com/v1beta/models/{self.model}:generateContent?key={self.api_key}'
51
  data = {
52
  "prompt": {
53
  "context": self.context,
 
64
  async with session.post(url, json=data, headers={'Content-Type': 'application/json'}) as response:
65
  try:
66
  temp= await response.json()
67
+ return temp["candidates"][0]["content"]['parts'][0]['text']
68
  except Exception as e:
69
  return f"Error ⚠️ {e}"
70
 
App/Chat/utils/Summarize.py CHANGED
@@ -52,33 +52,55 @@ async def PalmTextModel(text, candidates=1):
52
  "Content-Type": "application/json",
53
  }
54
 
55
- data = {
56
- "prompt": {"text": text},
57
- "temperature": 0.95,
58
- "top_k": 100,
59
- "top_p": 0.95,
60
- "candidate_count": candidates,
61
- "max_output_tokens": 1024,
62
- "stop_sequences": ["</output>"],
63
- "safety_settings": [
64
- {"category": "HARM_CATEGORY_DEROGATORY", "threshold": 4},
65
- {"category": "HARM_CATEGORY_TOXICITY", "threshold": 4},
66
- {"category": "HARM_CATEGORY_VIOLENCE", "threshold": 4},
67
- {"category": "HARM_CATEGORY_SEXUAL", "threshold": 4},
68
- {"category": "HARM_CATEGORY_MEDICAL", "threshold": 4},
69
- {"category": "HARM_CATEGORY_DANGEROUS", "threshold": 4},
70
  ],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  }
72
 
 
 
73
  async with aiohttp.ClientSession() as session:
74
  async with session.post(url, json=data, headers=headers) as response:
75
  if response.status == 200:
76
  result = await response.json()
77
  # print(result)
78
  if candidates > 1:
79
- temp = [candidate["output"] for candidate in result["candidates"]]
80
  return temp
81
- temp = result["candidates"][0]["output"]
82
  return temp
83
  else:
84
  print(f"Error: {response.status}\n{await response.text()}")
 
52
  "Content-Type": "application/json",
53
  }
54
 
55
+ payload = {
56
+ "contents": [
57
+ {
58
+ "role": "user",
59
+ "parts": [
60
+ {
61
+ "text": text
62
+ }
63
+ ]
64
+ }
 
 
 
 
 
65
  ],
66
+ "generationConfig": {
67
+ "temperature": 0.9,
68
+ "topK": 1,
69
+ "topP": 1,
70
+ "maxOutputTokens": 2048,
71
+ "stopSequences": []
72
+ },
73
+ "safetySettings": [
74
+ {
75
+ "category": "HARM_CATEGORY_HARASSMENT",
76
+ "threshold": "BLOCK_ONLY_HIGH"
77
+ },
78
+ {
79
+ "category": "HARM_CATEGORY_HATE_SPEECH",
80
+ "threshold": "BLOCK_ONLY_HIGH"
81
+ },
82
+ {
83
+ "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
84
+ "threshold": "BLOCK_ONLY_HIGH"
85
+ },
86
+ {
87
+ "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
88
+ "threshold": "BLOCK_ONLY_HIGH"
89
+ }
90
+ ]
91
  }
92
 
93
+
94
+
95
  async with aiohttp.ClientSession() as session:
96
  async with session.post(url, json=data, headers=headers) as response:
97
  if response.status == 200:
98
  result = await response.json()
99
  # print(result)
100
  if candidates > 1:
101
+ temp = [candidate["content"]['parts'][0]['text'] for candidate in result["candidates"]]
102
  return temp
103
+ temp = result["candidates"][0]["content"]['parts'][0]['text']
104
  return temp
105
  else:
106
  print(f"Error: {response.status}\n{await response.text()}")