DevsDoCode commited on
Commit
1094e6e
1 Parent(s): 82617a1

Upload 4 files

Browse files
Files changed (4) hide show
  1. api_call.py +7 -2
  2. api_info.py +3 -2
  3. app.py +5 -1
  4. bingChat.py +5 -2
api_call.py CHANGED
@@ -5,13 +5,17 @@ class BingChatAPI:
5
  def __init__(self, base_url="https://devsdocode-bing.hf.space"):
6
  self.base_url = base_url
7
 
8
- def generate(self, conversation_history, realtime=False, md_format=True):
9
  """
10
  Generate a response using the Bing Chat API.
11
 
12
  Args:
13
  conversation_history (list or str): A list of message objects or a string query.
14
  realtime (bool): Whether to stream the response in real-time.
 
 
 
 
15
  md_format (bool): Whether to format the response in Markdown.
16
 
17
  Returns:
@@ -25,7 +29,8 @@ class BingChatAPI:
25
  params = {
26
  "conversation_history": json.dumps(conversation_history),
27
  "realtime": str(realtime).lower(),
28
- "md_format": str(md_format).lower()
 
29
  }
30
 
31
  response = requests.get(endpoint, params=params)
 
5
  def __init__(self, base_url="https://devsdocode-bing.hf.space"):
6
  self.base_url = base_url
7
 
8
+ def generate(self, conversation_history, realtime=False, md_format=True, convo_tone="Balanced"):
9
  """
10
  Generate a response using the Bing Chat API.
11
 
12
  Args:
13
  conversation_history (list or str): A list of message objects or a string query.
14
  realtime (bool): Whether to stream the response in real-time.
15
+ convo_tone (str): The desired conversational style or tone.
16
+ - Balanced
17
+ - Creative
18
+ - Precise
19
  md_format (bool): Whether to format the response in Markdown.
20
 
21
  Returns:
 
29
  params = {
30
  "conversation_history": json.dumps(conversation_history),
31
  "realtime": str(realtime).lower(),
32
+ "md_format": str(md_format).lower(),
33
+ "convo_tone": convo_tone
34
  }
35
 
36
  response = requests.get(endpoint, params=params)
api_info.py CHANGED
@@ -20,9 +20,10 @@ endpoint = {
20
  },
21
  'optional_params': {
22
  "realtime": "[true/false]",
23
- "md_format": "[true/false]"
 
24
  },
25
- 'url_demo': '/generate?conversation_history=[{"role": "user", "content": "Who is Devs Do Code"}]&realtime=false&md_format=true'
26
  }
27
 
28
  available_models = {
 
20
  },
21
  'optional_params': {
22
  "realtime": "[true/false]",
23
+ "md_format": "[true/false]",
24
+ "convo_tone": "[Creative/Balanced/Precise]"
25
  },
26
+ 'url_demo': '/generate?conversation_history=[{"role": "user", "content": "Who is Devs Do Code"}]&realtime=false&md_format=true&convo_tone=Balanced'
27
  }
28
 
29
  available_models = {
app.py CHANGED
@@ -29,10 +29,13 @@ def generate():
29
  conversation_history = data.get('conversation_history')
30
  realtime = data.get('realtime', False)
31
  md_format = data.get('md_format', True)
 
 
32
  else: # GET request
33
  conversation_history = request.args.get('conversation_history')
34
  realtime = request.args.get('realtime', 'false').lower() == 'true'
35
  md_format = request.args.get('md_format', 'true').lower() == 'true'
 
36
 
37
  if conversation_history:
38
  # Parse the conversation_history as JSON if it's a string
@@ -45,7 +48,8 @@ def generate():
45
  response = bingChat.ddc_bing_converse(
46
  conv_history=conversation_history,
47
  realtime=realtime,
48
- md_format=md_format
 
49
  )
50
  return jsonify(response), 200
51
  else:
 
29
  conversation_history = data.get('conversation_history')
30
  realtime = data.get('realtime', False)
31
  md_format = data.get('md_format', True)
32
+ convo_tone = data.get('convo_tone', 'Balanced')
33
+
34
  else: # GET request
35
  conversation_history = request.args.get('conversation_history')
36
  realtime = request.args.get('realtime', 'false').lower() == 'true'
37
  md_format = request.args.get('md_format', 'true').lower() == 'true'
38
+ convo_tone = request.args.get('convo_tone', 'Balanced')
39
 
40
  if conversation_history:
41
  # Parse the conversation_history as JSON if it's a string
 
48
  response = bingChat.ddc_bing_converse(
49
  conv_history=conversation_history,
50
  realtime=realtime,
51
+ md_format=md_format,
52
+ convo_tone=convo_tone
53
  )
54
  return jsonify(response), 200
55
  else:
bingChat.py CHANGED
@@ -17,13 +17,16 @@ from dotenv import load_dotenv; load_dotenv()
17
  ddc_api_endpoint = os.environ.get("api_url")
18
 
19
 
20
- def ddc_bing_converse(conv_history=[], convo_tone="", md_format=False, realtime=True):
21
  """
22
  Initiates a conversation with the Bing Chat API and retrieves the response.
23
 
24
  Args:
25
  conv_history (list): A sequence of message objects forming the conversation.
26
  convo_tone (str): The desired conversational style or tone.
 
 
 
27
  md_format (bool): Flag to enable Markdown formatting in the response.
28
  realtime (bool): Indicator for streaming the API response in real-time.
29
 
@@ -142,7 +145,7 @@ def ddc_handle_error_response(response):
142
  if __name__ == "__main__":
143
  # DevsDoCode: Example usage demonstration
144
  sample_query = [{"role": "user", "content": "Describe India in 10 lines"}]
145
- api_result = ddc_bing_converse(conv_history=sample_query, realtime=False, md_format=True)
146
 
147
  if api_result["api_error"]:
148
  print("API Error Encountered:", api_result["api_error"])
 
17
  ddc_api_endpoint = os.environ.get("api_url")
18
 
19
 
20
+ def ddc_bing_converse(conv_history=[], convo_tone="Balanced", md_format=False, realtime=True):
21
  """
22
  Initiates a conversation with the Bing Chat API and retrieves the response.
23
 
24
  Args:
25
  conv_history (list): A sequence of message objects forming the conversation.
26
  convo_tone (str): The desired conversational style or tone.
27
+ - Balanced
28
+ - Creative
29
+ - Precise
30
  md_format (bool): Flag to enable Markdown formatting in the response.
31
  realtime (bool): Indicator for streaming the API response in real-time.
32
 
 
145
  if __name__ == "__main__":
146
  # DevsDoCode: Example usage demonstration
147
  sample_query = [{"role": "user", "content": "Describe India in 10 lines"}]
148
+ api_result = ddc_bing_converse(conv_history=sample_query, realtime=False, md_format=True, convo_tone="Creative")
149
 
150
  if api_result["api_error"]:
151
  print("API Error Encountered:", api_result["api_error"])